Enable smart punctuation

Closes #740
This commit is contained in:
Vincent Prouillet 2020-11-27 11:11:19 +01:00
parent 5d2c25b8c5
commit 59d3d8a3da
5 changed files with 23 additions and 0 deletions

View file

@ -13,6 +13,8 @@
- Add a `[markdown]` section to `config.toml` to configure rendering - Add a `[markdown]` section to `config.toml` to configure rendering
- Add `highlight_code` and `highlight_theme` to a `[markdown]` section in `config.toml` - 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 `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) ## 0.12.2 (2020-09-28)

View file

@ -19,6 +19,8 @@ pub struct Markdown {
pub external_links_no_follow: bool, pub external_links_no_follow: bool,
/// Whether to set rel="noreferrer" for all external links /// Whether to set rel="noreferrer" for all external links
pub external_links_no_referrer: bool, 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 { impl Markdown {
@ -63,6 +65,7 @@ impl Default for Markdown {
external_links_target_blank: false, external_links_target_blank: false,
external_links_no_follow: false, external_links_no_follow: false,
external_links_no_referrer: false, external_links_no_referrer: false,
smart_punctuation: false,
} }
} }
} }

View file

@ -186,6 +186,10 @@ pub fn markdown_to_html(content: &str, context: &RenderContext) -> Result<Render
opts.insert(Options::ENABLE_STRIKETHROUGH); opts.insert(Options::ENABLE_STRIKETHROUGH);
opts.insert(Options::ENABLE_TASKLISTS); opts.insert(Options::ENABLE_TASKLISTS);
if context.config.markdown.smart_punctuation {
opts.insert(Options::ENABLE_SMART_PUNCTUATION);
}
{ {
let mut events = Parser::new_ext(content, opts) let mut events = Parser::new_ext(content, opts)
.map(|event| { .map(|event| {

View file

@ -1116,3 +1116,13 @@ fn can_set_all_options_for_external_link() {
let res = render_content("<https://google.com>", &context).unwrap(); let res = render_content("<https://google.com>", &context).unwrap();
assert_eq!(res.body, "<p><a rel=\"noopener nofollow noreferrer\" target=\"_blank\" href=\"https://google.com\">https://google.com</a></p>\n"); assert_eq!(res.body, "<p><a rel=\"noopener nofollow noreferrer\" target=\"_blank\" href=\"https://google.com\">https://google.com</a></p>\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, "<p>This is “it”…</p>\n");
}

View file

@ -118,6 +118,10 @@ external_links_no_follow = false
# Whether to set rel="noreferrer" for all external links # Whether to set rel="noreferrer" for all external links
external_links_no_referrer = false 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. # Configuration of the link checker.
[link_checker] [link_checker]
# Skip link checking for external URLs that start with these prefixes # Skip link checking for external URLs that start with these prefixes