Skip to content

Commit 4262636

Browse files
committed
Auto merge of #11646 - Enyium:patch-1, r=weihanglo
Ensure em dashes are recognizable in markup An em dash (—) isn't well-recognizable in a monospace font. There were already a couple of locations where a hyphen was used instead. These were also corrected to `—`. `—` should reduce the probability of a hyphen being used for new entries.
2 parents f0a4ee0 + b1754b2 commit 4262636

File tree

173 files changed

+1326
-1280
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+1326
-1280
lines changed

.github/workflows/contrib.yml

Lines changed: 1 addition & 1 deletion
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: |

crates/mdman/Cargo.lock

Lines changed: 8 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/mdman/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description = "Creates a man page page from markdown."
88
[dependencies]
99
anyhow = "1.0.31"
1010
handlebars = { version = "3.2.1", features = ["dir_source"] }
11-
pulldown-cmark = { version = "0.7.2", default-features = false }
11+
pulldown-cmark = { version = "0.9.2", default-features = false }
1212
same-file = "1.0.6"
1313
serde_json = "1.0.56"
1414
url = "2.2.2"

crates/mdman/src/format/man.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::util::{header_text, parse_name_and_section};
44
use crate::EventIter;
55
use anyhow::{bail, Error};
6-
use pulldown_cmark::{Alignment, Event, LinkType, Tag};
6+
use pulldown_cmark::{Alignment, Event, HeadingLevel, LinkType, Tag};
77
use std::fmt::Write;
88
use url::Url;
99

@@ -122,10 +122,10 @@ impl<'e> ManRenderer<'e> {
122122
self.output.push_str(".sp\n");
123123
}
124124
}
125-
Tag::Heading(n) => {
126-
if n == 1 {
125+
Tag::Heading(level, ..) => {
126+
if level == HeadingLevel::H1 {
127127
self.push_top_header()?;
128-
} else if n == 2 {
128+
} else if level == HeadingLevel::H2 {
129129
// Section header
130130
let text = header_text(&mut self.parser)?;
131131
self.flush();
@@ -255,7 +255,7 @@ impl<'e> ManRenderer<'e> {
255255
Event::End(tag) => {
256256
match &tag {
257257
Tag::Paragraph => self.flush(),
258-
Tag::Heading(_n) => {}
258+
Tag::Heading(..) => {}
259259
Tag::BlockQuote => {
260260
self.flush();
261261
// restore left margin, restore line length
@@ -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| {

crates/mdman/src/format/text.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::util::{header_text, unwrap};
44
use crate::EventIter;
55
use anyhow::{bail, Error};
6-
use pulldown_cmark::{Alignment, Event, LinkType, Tag};
6+
use pulldown_cmark::{Alignment, Event, HeadingLevel, LinkType, Tag};
77
use std::fmt::Write;
88
use std::mem;
99
use url::Url;
@@ -116,24 +116,24 @@ impl<'e> TextRenderer<'e> {
116116
self.flush();
117117
}
118118
}
119-
Tag::Heading(n) => {
119+
Tag::Heading(level, ..) => {
120120
self.flush();
121-
if n == 1 {
121+
if level == HeadingLevel::H1 {
122122
let text = header_text(&mut self.parser)?;
123123
self.push_to_line(&text.to_uppercase());
124124
self.hard_break();
125125
self.hard_break();
126-
} else if n == 2 {
126+
} else if level == HeadingLevel::H2 {
127127
let text = header_text(&mut self.parser)?;
128128
self.push_to_line(&text.to_uppercase());
129129
self.flush();
130130
self.indent = 7;
131131
} else {
132132
let text = header_text(&mut self.parser)?;
133-
self.push_indent((n as usize - 2) * 3);
133+
self.push_indent((level as usize - 2) * 3);
134134
self.push_to_line(&text);
135135
self.flush();
136-
self.indent = (n as usize - 1) * 3 + 1;
136+
self.indent = (level as usize - 1) * 3 + 1;
137137
}
138138
}
139139
Tag::BlockQuote => {
@@ -223,7 +223,7 @@ impl<'e> TextRenderer<'e> {
223223
self.flush();
224224
self.hard_break();
225225
}
226-
Tag::Heading(_n) => {}
226+
Tag::Heading(..) => {}
227227
Tag::BlockQuote => {
228228
self.indent -= 3;
229229
}

crates/mdman/src/lib.rs

Lines changed: 1 addition & 0 deletions
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.

crates/mdman/src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub fn header_text<'e>(parser: &mut EventIter<'e>) -> Result<CowStr<'e>, Error>
3131
e => bail!("expected plain text in man header, got {:?}", e),
3232
};
3333
match parser.next() {
34-
Some((Event::End(Tag::Heading(_)), _range)) => {
34+
Some((Event::End(Tag::Heading(..)), _range)) => {
3535
return Ok(text);
3636
}
3737
e => bail!("expected plain text in man header, got {:?}", e),

crates/mdman/tests/compare/expected/formatting.1

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,8 @@ With a second paragraph inside it
6666
.sp
6767
.RS 4
6868
\h'-04'\(bu\h'+02'Milk
69-
.sp
70-
.RS 4
71-
\h'-04' 5.\h'+01'Don't start at one.
72-
.RE
73-
.sp
74-
.RS 4
75-
\h'-04' 6.\h'+01'tamarind
76-
.RE
69+
5. Don\[cq]t start at one.
70+
6. tamarind
7771
.RE
7872
.RE
7973
.sp

crates/mdman/tests/compare/expected/formatting.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,7 @@ LISTS
4343

4444
o Eggs
4545

46-
o Milk
47-
48-
5. Don't start at one.
49-
50-
6. tamarind
46+
o Milk 5. Don’t start at one. 6. tamarind
5147

5248
2. Second element
5349

crates/mdman/tests/compare/expected/options.1

Lines changed: 2 additions & 2 deletions
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

0 commit comments

Comments
 (0)