diff options
author | Eric Huss <eric@huss.org> | 2024-02-25 13:42:44 -0800 |
---|---|---|
committer | Eric Huss <eric@huss.org> | 2024-02-25 13:42:44 -0800 |
commit | d28cf53009ae7e86f3883ae050c43756482f1a5d (patch) | |
tree | aff097dd6a563162e9725ff0efa8318cd06b6189 /src/config.rs | |
parent | 504900d7bdfacd3a65991fb22b02b786a1001cb8 (diff) |
Rename curly-quotes to smart-punctuation.
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/src/config.rs b/src/config.rs index 67b1a700..4840c030 100644 --- a/src/config.rs +++ b/src/config.rs @@ -526,7 +526,9 @@ pub struct HtmlConfig { /// The theme to use if the browser requests the dark version of the site. /// Defaults to 'navy'. pub preferred_dark_theme: Option<String>, - /// Use "smart quotes" instead of the usual `"` character. + /// Supports smart quotes, apostrophes, ellipsis, en-dash, and em-dash. + pub smart_punctuation: bool, + /// Deprecated alias for `smart_punctuation`. pub curly_quotes: bool, /// Should mathjax be enabled? pub mathjax_support: bool, @@ -590,6 +592,7 @@ impl Default for HtmlConfig { theme: None, default_theme: None, preferred_dark_theme: None, + smart_punctuation: false, curly_quotes: false, mathjax_support: false, copy_fonts: true, @@ -623,6 +626,11 @@ impl HtmlConfig { None => root.join("theme"), } } + + /// Returns `true` if smart punctuation is enabled. + pub fn smart_punctuation(&self) -> bool { + self.smart_punctuation || self.curly_quotes + } } /// Configuration for how to render the print icon, print.html, and print.css. @@ -798,7 +806,7 @@ mod tests { [output.html] theme = "./themedir" default-theme = "rust" - curly-quotes = true + smart-punctuation = true google-analytics = "123456" additional-css = ["./foo/bar/baz.css"] git-repository-url = "https://foo.com/" @@ -845,7 +853,7 @@ mod tests { runnable: true, }; let html_should_be = HtmlConfig { - curly_quotes: true, + smart_punctuation: true, google_analytics: Some(String::from("123456")), additional_css: vec![PathBuf::from("./foo/bar/baz.css")], theme: Some(PathBuf::from("./themedir")), @@ -1025,7 +1033,7 @@ mod tests { [output.html] destination = "my-book" # the output files will be generated in `root/my-book` instead of `root/book` theme = "my-theme" - curly-quotes = true + smart-punctuation = true google-analytics = "123456" additional-css = ["custom.css", "custom2.css"] additional-js = ["custom.js"] @@ -1050,7 +1058,7 @@ mod tests { let html_should_be = HtmlConfig { theme: Some(PathBuf::from("my-theme")), - curly_quotes: true, + smart_punctuation: true, google_analytics: Some(String::from("123456")), additional_css: vec![PathBuf::from("custom.css"), PathBuf::from("custom2.css")], additional_js: vec![PathBuf::from("custom.js")], @@ -1320,4 +1328,37 @@ mod tests { assert!(html_config.print.enable); assert!(!html_config.print.page_break); } + + #[test] + fn curly_quotes_or_smart_punctuation() { + let src = r#" + [book] + title = "mdBook Documentation" + + [output.html] + smart-punctuation = true + "#; + let config = Config::from_str(src).unwrap(); + assert_eq!(config.html_config().unwrap().smart_punctuation(), true); + + let src = r#" + [book] + title = "mdBook Documentation" + + [output.html] + curly-quotes = true + "#; + let config = Config::from_str(src).unwrap(); + assert_eq!(config.html_config().unwrap().smart_punctuation(), true); + + let src = r#" + [book] + title = "mdBook Documentation" + "#; + let config = Config::from_str(src).unwrap(); + assert_eq!( + config.html_config().unwrap_or_default().smart_punctuation(), + false + ); + } } |