Enable smart-punctuation by default

This enables the smart-punctuation setting by default. The long term
plan is to continue to enable more markdown extensions by default across
semver breaking releases.
This commit is contained in:
Eric Huss 2025-08-22 16:52:08 -07:00
parent 6be8e526d6
commit b8ad85c16f
8 changed files with 70 additions and 42 deletions

View file

@ -417,7 +417,7 @@ pub enum RustEdition {
}
/// Configuration for the HTML renderer.
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(default, rename_all = "kebab-case", deny_unknown_fields)]
#[non_exhaustive]
pub struct HtmlConfig {
@ -485,6 +485,35 @@ pub struct HtmlConfig {
pub hash_files: bool,
}
impl Default for HtmlConfig {
fn default() -> HtmlConfig {
HtmlConfig {
theme: None,
default_theme: None,
preferred_dark_theme: None,
smart_punctuation: true,
mathjax_support: false,
additional_css: Vec::new(),
additional_js: Vec::new(),
fold: Fold::default(),
playground: Playground::default(),
code: Code::default(),
print: Print::default(),
no_section_label: false,
search: None,
git_repository_url: None,
git_repository_icon: None,
input_404: None,
site_url: None,
cname: None,
edit_url_template: None,
live_reload_endpoint: None,
redirect: HashMap::new(),
hash_files: false,
}
}
}
impl HtmlConfig {
/// Returns the directory of theme from the provided root directory. If the
/// directory is not present it will append the default directory of "theme"

View file

@ -23,16 +23,25 @@ pub use pulldown_cmark;
mod tests;
/// Options for parsing markdown.
#[derive(Default)]
#[non_exhaustive]
pub struct MarkdownOptions {
/// Enables smart punctuation.
///
/// Converts quotes to curly quotes, `...` to `…`, `--` to en-dash, and
/// `---` to em-dash.
///
/// This is `true` by default.
pub smart_punctuation: bool,
}
impl Default for MarkdownOptions {
fn default() -> MarkdownOptions {
MarkdownOptions {
smart_punctuation: true,
}
}
}
/// Options for converting markdown to HTML.
#[non_exhaustive]
pub struct HtmlRenderOptions<'a> {

View file

@ -61,7 +61,8 @@ fn it_can_wrap_tables() {
#[test]
fn it_can_keep_quotes_straight() {
let options = HtmlRenderOptions::new(&Path::new(""));
let mut options = HtmlRenderOptions::new(&Path::new(""));
options.markdown_options.smart_punctuation = false;
assert_eq!(render_markdown("'one'", &options), "<p>'one'</p>\n");
}
@ -78,8 +79,7 @@ fn it_can_make_quotes_curly_except_when_they_are_in_code() {
</code></pre>
<p><code>'three'</code> four</p>
"#;
let mut options = HtmlRenderOptions::new(&Path::new(""));
options.markdown_options.smart_punctuation = true;
let options = HtmlRenderOptions::new(&Path::new(""));
assert_eq!(render_markdown(input, &options), expected);
}
@ -102,9 +102,7 @@ more text with spaces
</code></pre>
<p>more text with spaces</p>
"#;
let mut options = HtmlRenderOptions::new(&Path::new(""));
assert_eq!(render_markdown(input, &options), expected);
options.markdown_options.smart_punctuation = true;
let options = HtmlRenderOptions::new(&Path::new(""));
assert_eq!(render_markdown(input, &options), expected);
}
@ -117,9 +115,7 @@ fn rust_code_block_properties_are_passed_as_space_delimited_class() {
let expected = r#"<pre><code class="language-rust,no_run,should_panic,property_3"></code></pre>
"#;
let mut options = HtmlRenderOptions::new(&Path::new(""));
assert_eq!(render_markdown(input, &options), expected);
options.markdown_options.smart_punctuation = true;
let options = HtmlRenderOptions::new(&Path::new(""));
assert_eq!(render_markdown(input, &options), expected);
}
@ -132,9 +128,7 @@ fn rust_code_block_properties_with_whitespace_are_passed_as_space_delimited_clas
let expected = r#"<pre><code class="language-rust,,,,,no_run,,,should_panic,,,,property_3"></code></pre>
"#;
let mut options = HtmlRenderOptions::new(&Path::new(""));
assert_eq!(render_markdown(input, &options), expected);
options.markdown_options.smart_punctuation = true;
let options = HtmlRenderOptions::new(&Path::new(""));
assert_eq!(render_markdown(input, &options), expected);
}
@ -147,17 +141,13 @@ fn rust_code_block_without_properties_has_proper_html_class() {
let expected = r#"<pre><code class="language-rust"></code></pre>
"#;
let mut options = HtmlRenderOptions::new(&Path::new(""));
assert_eq!(render_markdown(input, &options), expected);
options.markdown_options.smart_punctuation = true;
let options = HtmlRenderOptions::new(&Path::new(""));
assert_eq!(render_markdown(input, &options), expected);
let input = r#"
```rust
```
"#;
let mut options = HtmlRenderOptions::new(&Path::new(""));
assert_eq!(render_markdown(input, &options), expected);
options.markdown_options.smart_punctuation = true;
let options = HtmlRenderOptions::new(&Path::new(""));
assert_eq!(render_markdown(input, &options), expected);
}

View file

@ -123,7 +123,7 @@ The following configuration options are available:
CSS media query. Defaults to `navy`.
- **smart-punctuation:** Converts quotes to curly quotes, `...` to `…`, `--` to en-dash, and `---` to em-dash.
See [Smart Punctuation](../markdown.md#smart-punctuation).
Defaults to `false`.
Defaults to `true`.
- **mathjax-support:** Adds support for [MathJax](../mathjax.md). Defaults to
`false`.
- **additional-css:** If you need to slightly change the appearance of your book

View file

@ -220,8 +220,8 @@ characters:
So, no need to manually enter those Unicode characters!
This feature is disabled by default.
To enable it, see the [`output.html.smart-punctuation`] config option.
This feature is enabled by default.
To disable it, see the [`output.html.smart-punctuation`] config option.
[strikethrough]: https://github.github.com/gfm/#strikethrough-extension-
[tables]: https://github.github.com/gfm/#tables-extension-

View file

@ -90,23 +90,7 @@ Carrots</li>
#[test]
fn smart_punctuation() {
BookTest::from_dir("markdown/smart_punctuation")
// Default is off.
.check_main_file(
"book/smart_punctuation.html",
str![[r##"
<h1 id="smart-punctuation"><a class="header" href="#smart-punctuation">Smart Punctuation</a></h1>
<ul>
<li>En dash: --</li>
<li>Em dash: ---</li>
<li>Ellipsis: ...</li>
<li>Double quote: "quote"</li>
<li>Single quote: 'quote'</li>
</ul>
"##]],
)
.run("build", |cmd| {
cmd.env("MDBOOK_OUTPUT__HTML__SMART_PUNCTUATION", "true");
})
// Default is on.
.check_main_file(
"book/smart_punctuation.html",
str![[r##"
@ -118,6 +102,22 @@ fn smart_punctuation() {
<li>Double quote: quote</li>
<li>Single quote: quote</li>
</ul>
"##]],
)
.run("build", |cmd| {
cmd.env("MDBOOK_OUTPUT__HTML__SMART_PUNCTUATION", "false");
})
.check_main_file(
"book/smart_punctuation.html",
str![[r##"
<h1 id="smart-punctuation"><a class="header" href="#smart-punctuation">Smart Punctuation</a></h1>
<ul>
<li>En dash: --</li>
<li>Em dash: ---</li>
<li>Ellipsis: ...</li>
<li>Double quote: "quote"</li>
<li>Single quote: 'quote'</li>
</ul>
"##]],
);
}

View file

@ -63,7 +63,7 @@ fn reasonable_search_index() {
// html.
assert_eq!(
docs[&sneaky]["body"],
"I put &lt;HTML&gt; in here! Sneaky inline event alert(\"inline\");. But regular inline is indexed."
"I put &lt;HTML&gt; in here! Sneaky inline event alert(“inline”);. But regular inline is indexed."
);
assert_eq!(
docs[&no_headers]["breadcrumbs"],

File diff suppressed because one or more lines are too long