From 59d3d8a3da71693133511c6f43baa0d82d1ef4d2 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Fri, 27 Nov 2020 11:11:19 +0100 Subject: [PATCH] Enable smart punctuation Closes #740 --- CHANGELOG.md | 2 ++ components/config/src/config/markup.rs | 3 +++ components/rendering/src/markdown.rs | 4 ++++ components/rendering/tests/markdown.rs | 10 ++++++++++ .../documentation/getting-started/configuration.md | 4 ++++ 5 files changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cb35b8d..adafd3dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ - Add a `[markdown]` section to `config.toml` to configure rendering - Add `highlight_code` and `highlight_theme` to a `[markdown]` section in `config.toml` - Add `external_links_target_blank`, `external_links_no_follow` and `external_links_no_referrer` +- Add a `smart_punctuation` option in the `[markdown]` section in `config.toml` to turn elements like dots and dashes +into their typographic forms ## 0.12.2 (2020-09-28) diff --git a/components/config/src/config/markup.rs b/components/config/src/config/markup.rs index d918ef70..035aad7d 100644 --- a/components/config/src/config/markup.rs +++ b/components/config/src/config/markup.rs @@ -19,6 +19,8 @@ pub struct Markdown { pub external_links_no_follow: bool, /// Whether to set rel="noreferrer" for all external links pub external_links_no_referrer: bool, + /// Whether smart punctuation is enabled (changing quotes, dashes, dots etc in their typographic form) + pub smart_punctuation: bool, } impl Markdown { @@ -63,6 +65,7 @@ impl Default for Markdown { external_links_target_blank: false, external_links_no_follow: false, external_links_no_referrer: false, + smart_punctuation: false, } } } diff --git a/components/rendering/src/markdown.rs b/components/rendering/src/markdown.rs index 68104fac..d7975cbc 100644 --- a/components/rendering/src/markdown.rs +++ b/components/rendering/src/markdown.rs @@ -186,6 +186,10 @@ pub fn markdown_to_html(content: &str, context: &RenderContext) -> Result", &context).unwrap(); assert_eq!(res.body, "

https://google.com

\n"); } + +#[test] +fn can_use_smart_punctuation() { + let permalinks_ctx = HashMap::new(); + let mut config = Config::default(); + config.markdown.smart_punctuation = true; + let context = RenderContext::new(&ZOLA_TERA, &config, "", &permalinks_ctx, InsertAnchor::None); + let res = render_content(r#"This -- is "it"..."#, &context).unwrap(); + assert_eq!(res.body, "

This – is “it”…

\n"); +} \ No newline at end of file diff --git a/docs/content/documentation/getting-started/configuration.md b/docs/content/documentation/getting-started/configuration.md index 0d7e4a7a..b97fd5b6 100644 --- a/docs/content/documentation/getting-started/configuration.md +++ b/docs/content/documentation/getting-started/configuration.md @@ -118,6 +118,10 @@ external_links_no_follow = false # Whether to set rel="noreferrer" for all external links external_links_no_referrer = false +# Whether smart punctuation is enabled (changing quotes, dashes, dots in their typographic form) +# For example, `...` into `…`, `"quote"` into `“curly”` etc +smart_punctuation = false + # Configuration of the link checker. [link_checker] # Skip link checking for external URLs that start with these prefixes