Skip to content

Commit

Permalink
Enable smart punctuation in mdBook.
Browse files Browse the repository at this point in the history
  • Loading branch information
Enyium committed Feb 14, 2023
1 parent 2a4ec9f commit 0263ef4
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/contrib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install mdbook
run: |
mkdir mdbook
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
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
echo `pwd`/mdbook >> $GITHUB_PATH
- name: Deploy docs
run: |
Expand Down
2 changes: 2 additions & 0 deletions crates/mdman/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions crates/mdman/src/format/man.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,21 +400,27 @@ impl<'e> ManRenderer<'e> {
}

fn escape(s: &str) -> Result<String, Error> {
// Note: Possible source on output escape sequences: https://man7.org/linux/man-pages/man7/groff_char.7.html.
// Otherwise, use generic escaping in the form `\[u1EE7]` or `\[u1F994]`.

let mut replaced = s
.replace('\\', "\\(rs")
.replace('-', "\\-")
.replace('\u{00A0}', "\\ ") // non-breaking space (non-stretchable)
.replace('–', "\\[en]") // \u{2013} en-dash
.replace('—', "\\[em]") // \u{2014} em-dash
.replace('‘', "\\[oq]") // \u{2018} left single quote
.replace('’', "\\[cq]") // \u{2019} right single quote or apostrophe
.replace('“', "\\[lq]") // \u{201C} left double quote
.replace('”', "\\[rq]") // \u{201D} right double quote
.replace('…', "\\[u2026]") // \u{2026} ellipsis
.replace('│', "|") // \u{2502} box drawing light vertical (could use \[br])
.replace('├', "|") // \u{251C} box drawings light vertical and right
.replace('└', "`") // \u{2514} box drawings light up and right
.replace('─', "\\-") // \u{2500} box drawing light horizontal
;
if replaced.starts_with('.') {
replaced = format!("\\&.{}", &replaced[1..]);
} else if replaced.starts_with('\'') {
replaced = format!("\\(aq{}", &replaced[1..]);
}

if let Some(ch) = replaced.chars().find(|ch| {
Expand Down
1 change: 1 addition & 0 deletions crates/mdman/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pub(crate) fn md_parser(input: &str, url: Option<Url>) -> EventIter {
options.insert(Options::ENABLE_TABLES);
options.insert(Options::ENABLE_FOOTNOTES);
options.insert(Options::ENABLE_STRIKETHROUGH);
options.insert(Options::ENABLE_SMART_PUNCTUATION);
let parser = Parser::new_ext(input, options);
let parser = parser.into_offset_iter();
// Translate all links to include the base url.
Expand Down
2 changes: 1 addition & 1 deletion crates/mdman/tests/compare/expected/formatting.1
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ With a second paragraph inside it
.sp
.RS 4
\h'-04'\(bu\h'+02'Milk
5. Don't start at one.
5. Don\[cq]t start at one.
6. tamarind
.RE
.RE
Expand Down
2 changes: 1 addition & 1 deletion crates/mdman/tests/compare/expected/formatting.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ LISTS

o Eggs

o Milk 5. Don't start at one. 6. tamarind
o Milk 5. Dont start at one. 6. tamarind

2. Second element

Expand Down
4 changes: 2 additions & 2 deletions crates/mdman/tests/compare/expected/options.1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ my\-command \- A brief description
.br
\fBmy\-command\fR (\fB\-m\fR | \fB\-M\fR) [\fIoldbranch\fR] \fInewbranch\fR
.br
\fBmy\-command\fR (\fB\-d\fR | \fB\-D\fR) [\fB\-r\fR] \fIbranchname\fR\&...
\fBmy\-command\fR (\fB\-d\fR | \fB\-D\fR) [\fB\-r\fR] \fIbranchname\fR\[u2026]
.SH "DESCRIPTION"
A description of the command.
.sp
Expand Down Expand Up @@ -49,7 +49,7 @@ Demo \fIemphasis\fR, \fBstrong\fR, ~~strike~~
This has multiple flags.
.RE
.sp
\fInamed\-arg...\fR
\fInamed\-arg\[u2026]\fR
.RS 4
A named argument.
.RE
Expand Down
2 changes: 1 addition & 1 deletion crates/mdman/tests/compare/expected/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ A description of the command.
<dd class="option-desc">This has multiple flags.</dd>


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


Expand Down
4 changes: 2 additions & 2 deletions crates/mdman/tests/compare/expected/options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SYNOPSIS
my-command [--abc | --xyz] name
my-command [-f file]
my-command (-m | -M) [oldbranch] newbranch
my-command (-d | -D) [-r] branchname...
my-command (-d | -D) [-r] branchname

DESCRIPTION
A description of the command.
Expand All @@ -29,7 +29,7 @@ OPTIONS
-p spec, --package spec
This has multiple flags.

named-arg...
named-arg
A named argument.

Common Options
Expand Down
1 change: 1 addition & 0 deletions src/doc/book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ title = "The Cargo Book"
author = "Alex Crichton, Steve Klabnik and Carol Nichols, with contributions from the Rust community"

[output.html]
curly-quotes = true # Enable smart-punctuation feature for more than quotes.
git-repository-url = "https://github.com/rust-lang/cargo/tree/master/src/doc/src"
edit-url-template = "https://github.com/rust-lang/cargo/edit/master/src/doc/{path}"
1 change: 1 addition & 0 deletions src/doc/contrib/book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title = "Cargo Contributor Guide"
authors = ["Eric Huss"]

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

[output.html.redirect]
Expand Down

0 comments on commit 0263ef4

Please sign in to comment.