From dcd6f7648d42d57aabe8a6776404c128fcca6ae2 Mon Sep 17 00:00:00 2001 From: Martin Donath Date: Tue, 11 Nov 2025 19:07:17 +0100 Subject: [PATCH] zensical:docs - add comment on title handling Signed-off-by: Martin Donath --- crates/zensical/src/structure/nav.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/zensical/src/structure/nav.rs b/crates/zensical/src/structure/nav.rs index 6870621..5b177ef 100644 --- a/crates/zensical/src/structure/nav.rs +++ b/crates/zensical/src/structure/nav.rs @@ -410,6 +410,8 @@ pub(crate) fn to_title(component: &str) -> String { let title = component.trim_end_matches(".md").replace(['-', '_'], " "); let first = title.chars().next().unwrap_or_default(); + // Only uppercase first character if it's an ASCII character, and keep + // other languages like Chinese as-is if title.to_lowercase() == title && first.is_ascii_alphabetic() { first.to_uppercase().to_string() + &title[1..] } else { @@ -417,6 +419,10 @@ pub(crate) fn to_title(component: &str) -> String { } } +// ---------------------------------------------------------------------------- +// Tests +// ---------------------------------------------------------------------------- + #[cfg(test)] mod tests { use super::*; @@ -424,8 +430,7 @@ mod tests { /// https://github.com/zensical/zensical/issues/66 #[test] fn test_to_title() { - assert_eq!(to_title("编译器笔记"), "编译器笔记"); assert_eq!(to_title("hello-world"), "Hello world"); - assert_eq!(to_title("hello_world"), "Hello world"); + assert_eq!(to_title("编译器笔记"), "编译器笔记"); } }