Skip to content

Commit 0263ef4

Browse files
committed
Enable smart punctuation in mdBook.
1 parent 2a4ec9f commit 0263ef4

File tree

11 files changed

+21
-10
lines changed

11 files changed

+21
-10
lines changed

Diff for: .github/workflows/contrib.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Install mdbook
2020
run: |
2121
mkdir mdbook
22-
curl -Lf https://github.com/rust-lang/mdBook/releases/download/v0.4.9/mdbook-v0.4.9-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook
22+
curl -Lf https://github.com/rust-lang/mdBook/releases/download/v0.4.26/mdbook-v0.4.26-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook
2323
echo `pwd`/mdbook >> $GITHUB_PATH
2424
- name: Deploy docs
2525
run: |

Diff for: crates/mdman/Cargo.lock

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: crates/mdman/src/format/man.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -400,21 +400,27 @@ impl<'e> ManRenderer<'e> {
400400
}
401401

402402
fn escape(s: &str) -> Result<String, Error> {
403+
// Note: Possible source on output escape sequences: https://man7.org/linux/man-pages/man7/groff_char.7.html.
404+
// Otherwise, use generic escaping in the form `\[u1EE7]` or `\[u1F994]`.
405+
403406
let mut replaced = s
404407
.replace('\\', "\\(rs")
405408
.replace('-', "\\-")
406409
.replace('\u{00A0}', "\\ ") // non-breaking space (non-stretchable)
407410
.replace('–', "\\[en]") // \u{2013} en-dash
408411
.replace('—', "\\[em]") // \u{2014} em-dash
412+
.replace('‘', "\\[oq]") // \u{2018} left single quote
413+
.replace('’', "\\[cq]") // \u{2019} right single quote or apostrophe
414+
.replace('“', "\\[lq]") // \u{201C} left double quote
415+
.replace('”', "\\[rq]") // \u{201D} right double quote
416+
.replace('…', "\\[u2026]") // \u{2026} ellipsis
409417
.replace('│', "|") // \u{2502} box drawing light vertical (could use \[br])
410418
.replace('├', "|") // \u{251C} box drawings light vertical and right
411419
.replace('└', "`") // \u{2514} box drawings light up and right
412420
.replace('─', "\\-") // \u{2500} box drawing light horizontal
413421
;
414422
if replaced.starts_with('.') {
415423
replaced = format!("\\&.{}", &replaced[1..]);
416-
} else if replaced.starts_with('\'') {
417-
replaced = format!("\\(aq{}", &replaced[1..]);
418424
}
419425

420426
if let Some(ch) = replaced.chars().find(|ch| {

Diff for: crates/mdman/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ pub(crate) fn md_parser(input: &str, url: Option<Url>) -> EventIter {
6969
options.insert(Options::ENABLE_TABLES);
7070
options.insert(Options::ENABLE_FOOTNOTES);
7171
options.insert(Options::ENABLE_STRIKETHROUGH);
72+
options.insert(Options::ENABLE_SMART_PUNCTUATION);
7273
let parser = Parser::new_ext(input, options);
7374
let parser = parser.into_offset_iter();
7475
// Translate all links to include the base url.

Diff for: crates/mdman/tests/compare/expected/formatting.1

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ With a second paragraph inside it
6666
.sp
6767
.RS 4
6868
\h'-04'\(bu\h'+02'Milk
69-
5. Don't start at one.
69+
5. Don\[cq]t start at one.
7070
6. tamarind
7171
.RE
7272
.RE

Diff for: crates/mdman/tests/compare/expected/formatting.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ LISTS
4343

4444
o Eggs
4545

46-
o Milk 5. Don't start at one. 6. tamarind
46+
o Milk 5. Dont start at one. 6. tamarind
4747

4848
2. Second element
4949

Diff for: crates/mdman/tests/compare/expected/options.1

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ my\-command \- A brief description
1212
.br
1313
\fBmy\-command\fR (\fB\-m\fR | \fB\-M\fR) [\fIoldbranch\fR] \fInewbranch\fR
1414
.br
15-
\fBmy\-command\fR (\fB\-d\fR | \fB\-D\fR) [\fB\-r\fR] \fIbranchname\fR\&...
15+
\fBmy\-command\fR (\fB\-d\fR | \fB\-D\fR) [\fB\-r\fR] \fIbranchname\fR\[u2026]
1616
.SH "DESCRIPTION"
1717
A description of the command.
1818
.sp
@@ -49,7 +49,7 @@ Demo \fIemphasis\fR, \fBstrong\fR, ~~strike~~
4949
This has multiple flags.
5050
.RE
5151
.sp
52-
\fInamed\-arg...\fR
52+
\fInamed\-arg\[u2026]\fR
5353
.RS 4
5454
A named argument.
5555
.RE

Diff for: crates/mdman/tests/compare/expected/options.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ A description of the command.
3737
<dd class="option-desc">This has multiple flags.</dd>
3838

3939

40-
<dt class="option-term" id="option-options-named-arg..."><a class="option-anchor" href="#option-options-named-arg..."></a><em>named-arg...</em></dt>
40+
<dt class="option-term" id="option-options-named-arg"><a class="option-anchor" href="#option-options-named-arg"></a><em>named-arg</em></dt>
4141
<dd class="option-desc">A named argument.</dd>
4242

4343

Diff for: crates/mdman/tests/compare/expected/options.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ SYNOPSIS
77
my-command [--abc | --xyz] name
88
my-command [-f file]
99
my-command (-m | -M) [oldbranch] newbranch
10-
my-command (-d | -D) [-r] branchname...
10+
my-command (-d | -D) [-r] branchname
1111

1212
DESCRIPTION
1313
A description of the command.
@@ -29,7 +29,7 @@ OPTIONS
2929
-p spec, --package spec
3030
This has multiple flags.
3131

32-
named-arg...
32+
named-arg
3333
A named argument.
3434

3535
Common Options

Diff for: src/doc/book.toml

+1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ title = "The Cargo Book"
33
author = "Alex Crichton, Steve Klabnik and Carol Nichols, with contributions from the Rust community"
44

55
[output.html]
6+
curly-quotes = true # Enable smart-punctuation feature for more than quotes.
67
git-repository-url = "https://github.com/rust-lang/cargo/tree/master/src/doc/src"
78
edit-url-template = "https://github.com/rust-lang/cargo/edit/master/src/doc/{path}"

Diff for: src/doc/contrib/book.toml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ title = "Cargo Contributor Guide"
33
authors = ["Eric Huss"]
44

55
[output.html]
6+
curly-quotes = true # Enable smart-punctuation feature for more than quotes.
67
git-repository-url = "https://github.com/rust-lang/cargo/tree/master/src/doc/contrib/src"
78

89
[output.html.redirect]

0 commit comments

Comments
 (0)