Skip to content

Commit ec436ad

Browse files
authored
Merge pull request #2810 from ehuss/smart-punctuation-default
Enable smart-punctuation by default
2 parents 6be8e52 + b8ad85c commit ec436ad

File tree

8 files changed

+65
-37
lines changed

8 files changed

+65
-37
lines changed

crates/mdbook-core/src/config.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ pub enum RustEdition {
417417
}
418418

419419
/// Configuration for the HTML renderer.
420-
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
420+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
421421
#[serde(default, rename_all = "kebab-case", deny_unknown_fields)]
422422
#[non_exhaustive]
423423
pub struct HtmlConfig {
@@ -485,6 +485,35 @@ pub struct HtmlConfig {
485485
pub hash_files: bool,
486486
}
487487

488+
impl Default for HtmlConfig {
489+
fn default() -> HtmlConfig {
490+
HtmlConfig {
491+
theme: None,
492+
default_theme: None,
493+
preferred_dark_theme: None,
494+
smart_punctuation: true,
495+
mathjax_support: false,
496+
additional_css: Vec::new(),
497+
additional_js: Vec::new(),
498+
fold: Fold::default(),
499+
playground: Playground::default(),
500+
code: Code::default(),
501+
print: Print::default(),
502+
no_section_label: false,
503+
search: None,
504+
git_repository_url: None,
505+
git_repository_icon: None,
506+
input_404: None,
507+
site_url: None,
508+
cname: None,
509+
edit_url_template: None,
510+
live_reload_endpoint: None,
511+
redirect: HashMap::new(),
512+
hash_files: false,
513+
}
514+
}
515+
}
516+
488517
impl HtmlConfig {
489518
/// Returns the directory of theme from the provided root directory. If the
490519
/// directory is not present it will append the default directory of "theme"

crates/mdbook-markdown/src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,25 @@ pub use pulldown_cmark;
2323
mod tests;
2424

2525
/// Options for parsing markdown.
26-
#[derive(Default)]
2726
#[non_exhaustive]
2827
pub struct MarkdownOptions {
2928
/// Enables smart punctuation.
3029
///
3130
/// Converts quotes to curly quotes, `...` to `…`, `--` to en-dash, and
3231
/// `---` to em-dash.
32+
///
33+
/// This is `true` by default.
3334
pub smart_punctuation: bool,
3435
}
3536

37+
impl Default for MarkdownOptions {
38+
fn default() -> MarkdownOptions {
39+
MarkdownOptions {
40+
smart_punctuation: true,
41+
}
42+
}
43+
}
44+
3645
/// Options for converting markdown to HTML.
3746
#[non_exhaustive]
3847
pub struct HtmlRenderOptions<'a> {

crates/mdbook-markdown/src/tests.rs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ fn it_can_wrap_tables() {
6161

6262
#[test]
6363
fn it_can_keep_quotes_straight() {
64-
let options = HtmlRenderOptions::new(&Path::new(""));
64+
let mut options = HtmlRenderOptions::new(&Path::new(""));
65+
options.markdown_options.smart_punctuation = false;
6566
assert_eq!(render_markdown("'one'", &options), "<p>'one'</p>\n");
6667
}
6768

@@ -78,8 +79,7 @@ fn it_can_make_quotes_curly_except_when_they_are_in_code() {
7879
</code></pre>
7980
<p><code>'three'</code> ‘four’</p>
8081
"#;
81-
let mut options = HtmlRenderOptions::new(&Path::new(""));
82-
options.markdown_options.smart_punctuation = true;
82+
let options = HtmlRenderOptions::new(&Path::new(""));
8383
assert_eq!(render_markdown(input, &options), expected);
8484
}
8585

@@ -102,9 +102,7 @@ more text with spaces
102102
</code></pre>
103103
<p>more text with spaces</p>
104104
"#;
105-
let mut options = HtmlRenderOptions::new(&Path::new(""));
106-
assert_eq!(render_markdown(input, &options), expected);
107-
options.markdown_options.smart_punctuation = true;
105+
let options = HtmlRenderOptions::new(&Path::new(""));
108106
assert_eq!(render_markdown(input, &options), expected);
109107
}
110108

@@ -117,9 +115,7 @@ fn rust_code_block_properties_are_passed_as_space_delimited_class() {
117115

118116
let expected = r#"<pre><code class="language-rust,no_run,should_panic,property_3"></code></pre>
119117
"#;
120-
let mut options = HtmlRenderOptions::new(&Path::new(""));
121-
assert_eq!(render_markdown(input, &options), expected);
122-
options.markdown_options.smart_punctuation = true;
118+
let options = HtmlRenderOptions::new(&Path::new(""));
123119
assert_eq!(render_markdown(input, &options), expected);
124120
}
125121

@@ -132,9 +128,7 @@ fn rust_code_block_properties_with_whitespace_are_passed_as_space_delimited_clas
132128

133129
let expected = r#"<pre><code class="language-rust,,,,,no_run,,,should_panic,,,,property_3"></code></pre>
134130
"#;
135-
let mut options = HtmlRenderOptions::new(&Path::new(""));
136-
assert_eq!(render_markdown(input, &options), expected);
137-
options.markdown_options.smart_punctuation = true;
131+
let options = HtmlRenderOptions::new(&Path::new(""));
138132
assert_eq!(render_markdown(input, &options), expected);
139133
}
140134

@@ -147,17 +141,13 @@ fn rust_code_block_without_properties_has_proper_html_class() {
147141

148142
let expected = r#"<pre><code class="language-rust"></code></pre>
149143
"#;
150-
let mut options = HtmlRenderOptions::new(&Path::new(""));
151-
assert_eq!(render_markdown(input, &options), expected);
152-
options.markdown_options.smart_punctuation = true;
144+
let options = HtmlRenderOptions::new(&Path::new(""));
153145
assert_eq!(render_markdown(input, &options), expected);
154146

155147
let input = r#"
156148
```rust
157149
```
158150
"#;
159-
let mut options = HtmlRenderOptions::new(&Path::new(""));
160-
assert_eq!(render_markdown(input, &options), expected);
161-
options.markdown_options.smart_punctuation = true;
151+
let options = HtmlRenderOptions::new(&Path::new(""));
162152
assert_eq!(render_markdown(input, &options), expected);
163153
}

guide/src/format/configuration/renderers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ The following configuration options are available:
123123
CSS media query. Defaults to `navy`.
124124
- **smart-punctuation:** Converts quotes to curly quotes, `...` to ``, `--` to en-dash, and `---` to em-dash.
125125
See [Smart Punctuation](../markdown.md#smart-punctuation).
126-
Defaults to `false`.
126+
Defaults to `true`.
127127
- **mathjax-support:** Adds support for [MathJax](../mathjax.md). Defaults to
128128
`false`.
129129
- **additional-css:** If you need to slightly change the appearance of your book

guide/src/format/markdown.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ characters:
220220

221221
So, no need to manually enter those Unicode characters!
222222

223-
This feature is disabled by default.
224-
To enable it, see the [`output.html.smart-punctuation`] config option.
223+
This feature is enabled by default.
224+
To disable it, see the [`output.html.smart-punctuation`] config option.
225225

226226
[strikethrough]: https://github.github.com/gfm/#strikethrough-extension-
227227
[tables]: https://github.github.com/gfm/#tables-extension-

tests/testsuite/markdown.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,33 +90,33 @@ Carrots</li>
9090
#[test]
9191
fn smart_punctuation() {
9292
BookTest::from_dir("markdown/smart_punctuation")
93-
// Default is off.
93+
// Default is on.
9494
.check_main_file(
9595
"book/smart_punctuation.html",
9696
str![[r##"
9797
<h1 id="smart-punctuation"><a class="header" href="#smart-punctuation">Smart Punctuation</a></h1>
9898
<ul>
99-
<li>En dash: --</li>
100-
<li>Em dash: ---</li>
101-
<li>Ellipsis: ...</li>
102-
<li>Double quote: "quote"</li>
103-
<li>Single quote: 'quote'</li>
99+
<li>En dash: </li>
100+
<li>Em dash: </li>
101+
<li>Ellipsis: </li>
102+
<li>Double quote: quote</li>
103+
<li>Single quote: quote</li>
104104
</ul>
105105
"##]],
106106
)
107107
.run("build", |cmd| {
108-
cmd.env("MDBOOK_OUTPUT__HTML__SMART_PUNCTUATION", "true");
108+
cmd.env("MDBOOK_OUTPUT__HTML__SMART_PUNCTUATION", "false");
109109
})
110110
.check_main_file(
111111
"book/smart_punctuation.html",
112112
str![[r##"
113113
<h1 id="smart-punctuation"><a class="header" href="#smart-punctuation">Smart Punctuation</a></h1>
114114
<ul>
115-
<li>En dash: </li>
116-
<li>Em dash: </li>
117-
<li>Ellipsis: </li>
118-
<li>Double quote: quote</li>
119-
<li>Single quote: quote</li>
115+
<li>En dash: --</li>
116+
<li>Em dash: ---</li>
117+
<li>Ellipsis: ...</li>
118+
<li>Double quote: "quote"</li>
119+
<li>Single quote: 'quote'</li>
120120
</ul>
121121
"##]],
122122
);

tests/testsuite/search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn reasonable_search_index() {
6363
// html.
6464
assert_eq!(
6565
docs[&sneaky]["body"],
66-
"I put &lt;HTML&gt; in here! Sneaky inline event alert(\"inline\");. But regular inline is indexed."
66+
"I put &lt;HTML&gt; in here! Sneaky inline event alert(inline);. But regular inline is indexed."
6767
);
6868
assert_eq!(
6969
docs[&no_headers]["breadcrumbs"],

tests/testsuite/search/reasonable_search_index/expected_index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)