@@ -526,7 +526,9 @@ pub struct HtmlConfig {
526526 /// The theme to use if the browser requests the dark version of the site.
527527 /// Defaults to 'navy'.
528528 pub preferred_dark_theme : Option < String > ,
529- /// Use "smart quotes" instead of the usual `"` character.
529+ /// Supports smart quotes, apostrophes, ellipsis, en-dash, and em-dash.
530+ pub smart_punctuation : bool ,
531+ /// Deprecated alias for `smart_punctuation`.
530532 pub curly_quotes : bool ,
531533 /// Should mathjax be enabled?
532534 pub mathjax_support : bool ,
@@ -590,6 +592,7 @@ impl Default for HtmlConfig {
590592 theme : None ,
591593 default_theme : None ,
592594 preferred_dark_theme : None ,
595+ smart_punctuation : false ,
593596 curly_quotes : false ,
594597 mathjax_support : false ,
595598 copy_fonts : true ,
@@ -623,6 +626,11 @@ impl HtmlConfig {
623626 None => root. join ( "theme" ) ,
624627 }
625628 }
629+
630+ /// Returns `true` if smart punctuation is enabled.
631+ pub fn smart_punctuation ( & self ) -> bool {
632+ self . smart_punctuation || self . curly_quotes
633+ }
626634}
627635
628636/// Configuration for how to render the print icon, print.html, and print.css.
@@ -798,7 +806,7 @@ mod tests {
798806 [output.html]
799807 theme = "./themedir"
800808 default-theme = "rust"
801- curly-quotes = true
809+ smart-punctuation = true
802810 google-analytics = "123456"
803811 additional-css = ["./foo/bar/baz.css"]
804812 git-repository-url = "https://foo.com/"
@@ -845,7 +853,7 @@ mod tests {
845853 runnable : true ,
846854 } ;
847855 let html_should_be = HtmlConfig {
848- curly_quotes : true ,
856+ smart_punctuation : true ,
849857 google_analytics : Some ( String :: from ( "123456" ) ) ,
850858 additional_css : vec ! [ PathBuf :: from( "./foo/bar/baz.css" ) ] ,
851859 theme : Some ( PathBuf :: from ( "./themedir" ) ) ,
@@ -1025,7 +1033,7 @@ mod tests {
10251033 [output.html]
10261034 destination = "my-book" # the output files will be generated in `root/my-book` instead of `root/book`
10271035 theme = "my-theme"
1028- curly-quotes = true
1036+ smart-punctuation = true
10291037 google-analytics = "123456"
10301038 additional-css = ["custom.css", "custom2.css"]
10311039 additional-js = ["custom.js"]
@@ -1050,7 +1058,7 @@ mod tests {
10501058
10511059 let html_should_be = HtmlConfig {
10521060 theme : Some ( PathBuf :: from ( "my-theme" ) ) ,
1053- curly_quotes : true ,
1061+ smart_punctuation : true ,
10541062 google_analytics : Some ( String :: from ( "123456" ) ) ,
10551063 additional_css : vec ! [ PathBuf :: from( "custom.css" ) , PathBuf :: from( "custom2.css" ) ] ,
10561064 additional_js : vec ! [ PathBuf :: from( "custom.js" ) ] ,
@@ -1320,4 +1328,37 @@ mod tests {
13201328 assert ! ( html_config. print. enable) ;
13211329 assert ! ( !html_config. print. page_break) ;
13221330 }
1331+
1332+ #[ test]
1333+ fn curly_quotes_or_smart_punctuation ( ) {
1334+ let src = r#"
1335+ [book]
1336+ title = "mdBook Documentation"
1337+
1338+ [output.html]
1339+ smart-punctuation = true
1340+ "# ;
1341+ let config = Config :: from_str ( src) . unwrap ( ) ;
1342+ assert_eq ! ( config. html_config( ) . unwrap( ) . smart_punctuation( ) , true ) ;
1343+
1344+ let src = r#"
1345+ [book]
1346+ title = "mdBook Documentation"
1347+
1348+ [output.html]
1349+ curly-quotes = true
1350+ "# ;
1351+ let config = Config :: from_str ( src) . unwrap ( ) ;
1352+ assert_eq ! ( config. html_config( ) . unwrap( ) . smart_punctuation( ) , true ) ;
1353+
1354+ let src = r#"
1355+ [book]
1356+ title = "mdBook Documentation"
1357+ "# ;
1358+ let config = Config :: from_str ( src) . unwrap ( ) ;
1359+ assert_eq ! (
1360+ config. html_config( ) . unwrap_or_default( ) . smart_punctuation( ) ,
1361+ false
1362+ ) ;
1363+ }
13231364}
0 commit comments