style: format Rust theme modules with cargo fmt
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -93,10 +93,7 @@ fn find_available_stem(dir: &Path, base: &str, ext: &str) -> String {
|
||||
fn vault_theme_note_content(name: &str, vars: &[(&str, &str)]) -> String {
|
||||
let mut fm = format!("---\nIs A: Theme\nDescription: {name} theme\n");
|
||||
for (key, value) in vars {
|
||||
if value.contains('#')
|
||||
|| value.contains('\'')
|
||||
|| value.contains(',')
|
||||
|| value.contains('(')
|
||||
if value.contains('#') || value.contains('\'') || value.contains(',') || value.contains('(')
|
||||
{
|
||||
fm.push_str(&format!("{key}: \"{value}\"\n"));
|
||||
} else {
|
||||
@@ -240,23 +237,65 @@ mod tests {
|
||||
}
|
||||
|
||||
// Spot-check editor properties from theme.json that were previously missing
|
||||
assert!(content.contains("editor-font-family:"), "missing editor-font-family");
|
||||
assert!(content.contains("editor-padding-horizontal:"), "missing editor-padding-horizontal");
|
||||
assert!(content.contains("headings-h1-font-size:"), "missing headings-h1-font-size");
|
||||
assert!(content.contains("lists-bullet-size:"), "missing lists-bullet-size");
|
||||
assert!(content.contains("lists-bullet-color:"), "missing lists-bullet-color");
|
||||
assert!(content.contains("checkboxes-size:"), "missing checkboxes-size");
|
||||
assert!(content.contains("inline-styles-bold-font-weight:"), "missing inline-styles-bold-font-weight");
|
||||
assert!(content.contains("code-blocks-font-family:"), "missing code-blocks-font-family");
|
||||
assert!(content.contains("blockquote-border-left-width:"), "missing blockquote-border-left-width");
|
||||
assert!(content.contains("table-border-color:"), "missing table-border-color");
|
||||
assert!(content.contains("horizontal-rule-thickness:"), "missing horizontal-rule-thickness");
|
||||
assert!(
|
||||
content.contains("editor-font-family:"),
|
||||
"missing editor-font-family"
|
||||
);
|
||||
assert!(
|
||||
content.contains("editor-padding-horizontal:"),
|
||||
"missing editor-padding-horizontal"
|
||||
);
|
||||
assert!(
|
||||
content.contains("headings-h1-font-size:"),
|
||||
"missing headings-h1-font-size"
|
||||
);
|
||||
assert!(
|
||||
content.contains("lists-bullet-size:"),
|
||||
"missing lists-bullet-size"
|
||||
);
|
||||
assert!(
|
||||
content.contains("lists-bullet-color:"),
|
||||
"missing lists-bullet-color"
|
||||
);
|
||||
assert!(
|
||||
content.contains("checkboxes-size:"),
|
||||
"missing checkboxes-size"
|
||||
);
|
||||
assert!(
|
||||
content.contains("inline-styles-bold-font-weight:"),
|
||||
"missing inline-styles-bold-font-weight"
|
||||
);
|
||||
assert!(
|
||||
content.contains("code-blocks-font-family:"),
|
||||
"missing code-blocks-font-family"
|
||||
);
|
||||
assert!(
|
||||
content.contains("blockquote-border-left-width:"),
|
||||
"missing blockquote-border-left-width"
|
||||
);
|
||||
assert!(
|
||||
content.contains("table-border-color:"),
|
||||
"missing table-border-color"
|
||||
);
|
||||
assert!(
|
||||
content.contains("horizontal-rule-thickness:"),
|
||||
"missing horizontal-rule-thickness"
|
||||
);
|
||||
assert!(content.contains("colors-text:"), "missing colors-text");
|
||||
assert!(content.contains("colors-cursor:"), "missing colors-cursor");
|
||||
|
||||
// Numeric values that need CSS units must have px suffix
|
||||
assert!(content.contains("editor-font-size: 15px"), "editor-font-size should have px unit");
|
||||
assert!(content.contains("editor-max-width: 720px"), "editor-max-width should have px unit");
|
||||
assert!(content.contains("editor-padding-horizontal: 40px"), "editor-padding-horizontal should have px unit");
|
||||
assert!(
|
||||
content.contains("editor-font-size: 15px"),
|
||||
"editor-font-size should have px unit"
|
||||
);
|
||||
assert!(
|
||||
content.contains("editor-max-width: 720px"),
|
||||
"editor-max-width should have px unit"
|
||||
);
|
||||
assert!(
|
||||
content.contains("editor-padding-horizontal: 40px"),
|
||||
"editor-padding-horizontal should have px unit"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,7 +239,10 @@ pub const DEFAULT_VAULT_THEME_VARS: [(&str, &str); 140] = [
|
||||
"'SF Mono', 'Fira Code', monospace",
|
||||
),
|
||||
("inline-styles-code-font-size", "14px"),
|
||||
("inline-styles-code-background-color", "var(--bg-hover-subtle)"),
|
||||
(
|
||||
"inline-styles-code-background-color",
|
||||
"var(--bg-hover-subtle)",
|
||||
),
|
||||
("inline-styles-code-padding-horizontal", "4px"),
|
||||
("inline-styles-code-padding-vertical", "2px"),
|
||||
("inline-styles-code-border-radius", "3px"),
|
||||
@@ -377,10 +380,7 @@ const MINIMAL_OVERRIDES: &[(&str, &str)] = &[
|
||||
("accent-purple-light", "#66009914"),
|
||||
("accent-red-light", "#CC000014"),
|
||||
("accent-yellow-light", "#99660014"),
|
||||
(
|
||||
"font-family",
|
||||
"'SF Mono', 'Menlo', monospace",
|
||||
),
|
||||
("font-family", "'SF Mono', 'Menlo', monospace"),
|
||||
("font-size-base", "13px"),
|
||||
("editor-font-size", "15px"),
|
||||
("editor-line-height", "1.6"),
|
||||
@@ -391,17 +391,10 @@ const MINIMAL_OVERRIDES: &[(&str, &str)] = &[
|
||||
/// Build a vault theme note string from a set of CSS variable pairs.
|
||||
///
|
||||
/// Values containing `#`, `'`, `,`, or `(` are YAML-quoted to avoid parse errors.
|
||||
fn build_vault_theme_note(
|
||||
name: &str,
|
||||
description: &str,
|
||||
vars: &[(&str, &str)],
|
||||
) -> String {
|
||||
fn build_vault_theme_note(name: &str, description: &str, vars: &[(&str, &str)]) -> String {
|
||||
let mut fm = format!("---\ntype: Theme\nDescription: {description}\n");
|
||||
for (key, value) in vars {
|
||||
if value.contains('#')
|
||||
|| value.contains('\'')
|
||||
|| value.contains(',')
|
||||
|| value.contains('(')
|
||||
if value.contains('#') || value.contains('\'') || value.contains(',') || value.contains('(')
|
||||
{
|
||||
fm.push_str(&format!("{key}: \"{value}\"\n"));
|
||||
} else {
|
||||
@@ -414,7 +407,9 @@ fn build_vault_theme_note(
|
||||
}
|
||||
|
||||
/// Apply overrides on top of DEFAULT_VAULT_THEME_VARS, returning a new Vec.
|
||||
fn apply_overrides(overrides: &[(&'static str, &'static str)]) -> Vec<(&'static str, &'static str)> {
|
||||
fn apply_overrides(
|
||||
overrides: &[(&'static str, &'static str)],
|
||||
) -> Vec<(&'static str, &'static str)> {
|
||||
let mut vars: Vec<(&'static str, &'static str)> = DEFAULT_VAULT_THEME_VARS.to_vec();
|
||||
for &(key, value) in overrides {
|
||||
if let Some(entry) = vars.iter_mut().find(|e| e.0 == key) {
|
||||
|
||||
@@ -35,8 +35,7 @@ pub fn seed_default_themes(vault_path: &str) {
|
||||
fn write_if_missing(path: &Path, content: &str) -> Result<bool, String> {
|
||||
let needs_write = !path.exists() || fs::metadata(path).map_or(true, |m| m.len() == 0);
|
||||
if needs_write {
|
||||
fs::write(path, content)
|
||||
.map_err(|e| format!("Failed to write {}: {e}", path.display()))?;
|
||||
fs::write(path, content).map_err(|e| format!("Failed to write {}: {e}", path.display()))?;
|
||||
}
|
||||
Ok(needs_write)
|
||||
}
|
||||
@@ -352,15 +351,42 @@ mod tests {
|
||||
let content = fs::read_to_string(vault.join("theme").join("default.md")).unwrap();
|
||||
|
||||
// Must contain all editor properties from theme.json
|
||||
assert!(content.contains("editor-font-family:"), "missing editor-font-family");
|
||||
assert!(content.contains("headings-h1-font-size:"), "missing headings-h1-font-size");
|
||||
assert!(content.contains("lists-bullet-size:"), "missing lists-bullet-size");
|
||||
assert!(content.contains("checkboxes-size:"), "missing checkboxes-size");
|
||||
assert!(content.contains("inline-styles-bold-font-weight:"), "missing inline-styles-bold");
|
||||
assert!(content.contains("code-blocks-font-family:"), "missing code-blocks-font-family");
|
||||
assert!(content.contains("blockquote-border-left-width:"), "missing blockquote");
|
||||
assert!(content.contains("table-border-color:"), "missing table-border-color");
|
||||
assert!(content.contains("horizontal-rule-thickness:"), "missing horizontal-rule");
|
||||
assert!(
|
||||
content.contains("editor-font-family:"),
|
||||
"missing editor-font-family"
|
||||
);
|
||||
assert!(
|
||||
content.contains("headings-h1-font-size:"),
|
||||
"missing headings-h1-font-size"
|
||||
);
|
||||
assert!(
|
||||
content.contains("lists-bullet-size:"),
|
||||
"missing lists-bullet-size"
|
||||
);
|
||||
assert!(
|
||||
content.contains("checkboxes-size:"),
|
||||
"missing checkboxes-size"
|
||||
);
|
||||
assert!(
|
||||
content.contains("inline-styles-bold-font-weight:"),
|
||||
"missing inline-styles-bold"
|
||||
);
|
||||
assert!(
|
||||
content.contains("code-blocks-font-family:"),
|
||||
"missing code-blocks-font-family"
|
||||
);
|
||||
assert!(
|
||||
content.contains("blockquote-border-left-width:"),
|
||||
"missing blockquote"
|
||||
);
|
||||
assert!(
|
||||
content.contains("table-border-color:"),
|
||||
"missing table-border-color"
|
||||
);
|
||||
assert!(
|
||||
content.contains("horizontal-rule-thickness:"),
|
||||
"missing horizontal-rule"
|
||||
);
|
||||
assert!(content.contains("colors-text:"), "missing colors-text");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user