Skip to content

Commit 8ba82fc

Browse files
committed
Auto merge of #13517 - bryangarza:chore-pulldown-cmark-0.10.0, r=weihanglo
chore: update pulldown-cmark to 0.10.0 ### What does this PR try to resolve? Update a dependency and address its breaking changes. `pulldown-cmark: 0.9.3 -> 0.10.0` Fixes: #13509 ### How should we test and review this PR? The `.md` and `.1` docs are updated as part of this commit, you can see there that nothing changes except for removal of some trailing whitespace.
2 parents 9e6288e + 604d2e4 commit 8ba82fc

34 files changed

+192
-158
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pathdiff = "0.2"
7474
percent-encoding = "2.3"
7575
pkg-config = "0.3.30"
7676
proptest = "1.4.0"
77-
pulldown-cmark = { version = "0.9.3", default-features = false }
77+
pulldown-cmark = { version = "0.10.0", default-features = false, features = ["html"] }
7878
rand = "0.8.5"
7979
regex = "1.10.3"
8080
rusqlite = { version = "0.31.0", features = ["bundled"] }

crates/mdman/src/format/man.rs

Lines changed: 45 additions & 35 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, HeadingLevel, LinkType, Tag};
6+
use pulldown_cmark::{Alignment, Event, HeadingLevel, LinkType, Tag, TagEnd};
77
use std::fmt::Write;
88
use url::Url;
99

@@ -110,6 +110,7 @@ impl<'e> ManRenderer<'e> {
110110
let mut suppress_paragraph = false;
111111
let mut table_cell_index = 0;
112112

113+
let mut last_seen_link_data = None;
113114
while let Some((event, range)) = self.parser.next() {
114115
let this_suppress_paragraph = suppress_paragraph;
115116
suppress_paragraph = false;
@@ -122,7 +123,7 @@ impl<'e> ManRenderer<'e> {
122123
self.output.push_str(".sp\n");
123124
}
124125
}
125-
Tag::Heading(level, ..) => {
126+
Tag::Heading { level, .. } => {
126127
if level == HeadingLevel::H1 {
127128
self.push_top_header()?;
128129
} else if level == HeadingLevel::H2 {
@@ -212,7 +213,12 @@ impl<'e> ManRenderer<'e> {
212213
Tag::Strong => self.push_font(Font::Bold),
213214
// Strikethrough isn't usually supported for TTY.
214215
Tag::Strikethrough => self.output.push_str("~~"),
215-
Tag::Link(link_type, dest_url, _title) => {
216+
Tag::Link {
217+
link_type,
218+
dest_url,
219+
..
220+
} => {
221+
last_seen_link_data = Some((link_type.clone(), dest_url.to_owned()));
216222
if dest_url.starts_with('#') {
217223
// In a man page, page-relative anchors don't
218224
// have much meaning.
@@ -247,68 +253,71 @@ impl<'e> ManRenderer<'e> {
247253
}
248254
}
249255
}
250-
Tag::Image(_link_type, _dest_url, _title) => {
256+
Tag::Image { .. } => {
251257
bail!("images are not currently supported")
252258
}
259+
Tag::HtmlBlock { .. } | Tag::MetadataBlock { .. } => {}
253260
}
254261
}
255-
Event::End(tag) => {
256-
match &tag {
257-
Tag::Paragraph => self.flush(),
258-
Tag::Heading(..) => {}
259-
Tag::BlockQuote => {
262+
Event::End(tag_end) => {
263+
match &tag_end {
264+
TagEnd::Paragraph => self.flush(),
265+
TagEnd::Heading(..) => {}
266+
TagEnd::BlockQuote => {
260267
self.flush();
261268
// restore left margin, restore line length
262269
self.output.push_str(".br\n.RE\n.ll\n");
263270
}
264-
Tag::CodeBlock(_kind) => {
271+
TagEnd::CodeBlock => {
265272
self.flush();
266273
// Restore fill mode, move margin back one level.
267274
self.output.push_str(".fi\n.RE\n");
268275
}
269-
Tag::List(_) => {
276+
TagEnd::List(_) => {
270277
list.pop();
271278
}
272-
Tag::Item => {
279+
TagEnd::Item => {
273280
self.flush();
274281
// Move margin back one level.
275282
self.output.push_str(".RE\n");
276283
}
277-
Tag::FootnoteDefinition(_label) => {}
278-
Tag::Table(_) => {
284+
TagEnd::FootnoteDefinition => {}
285+
TagEnd::Table => {
279286
// Table end
280287
// I don't know why, but the .sp is needed to provide
281288
// space with the following content.
282289
self.output.push_str("\n.TE\n.sp\n");
283290
}
284-
Tag::TableHead => {}
285-
Tag::TableRow => {}
286-
Tag::TableCell => {
291+
TagEnd::TableHead => {}
292+
TagEnd::TableRow => {}
293+
TagEnd::TableCell => {
287294
// End text block.
288295
self.output.push_str("\nT}");
289296
}
290-
Tag::Emphasis | Tag::Strong => self.pop_font(),
291-
Tag::Strikethrough => self.output.push_str("~~"),
292-
Tag::Link(link_type, dest_url, _title) => {
293-
if dest_url.starts_with('#') {
294-
continue;
295-
}
296-
match link_type {
297-
LinkType::Autolink | LinkType::Email => {}
298-
LinkType::Inline
299-
| LinkType::Reference
300-
| LinkType::Collapsed
301-
| LinkType::Shortcut => {
302-
self.pop_font();
303-
self.output.push(' ');
297+
TagEnd::Emphasis | TagEnd::Strong => self.pop_font(),
298+
TagEnd::Strikethrough => self.output.push_str("~~"),
299+
TagEnd::Link => {
300+
if let Some((link_type, ref dest_url)) = last_seen_link_data {
301+
if dest_url.starts_with('#') {
302+
continue;
304303
}
305-
_ => {
306-
panic!("unexpected tag {:?}", tag);
304+
match link_type {
305+
LinkType::Autolink | LinkType::Email => {}
306+
LinkType::Inline
307+
| LinkType::Reference
308+
| LinkType::Collapsed
309+
| LinkType::Shortcut => {
310+
self.pop_font();
311+
self.output.push(' ');
312+
}
313+
_ => {
314+
panic!("unexpected tag {:?}", tag_end);
315+
}
307316
}
317+
write!(self.output, "<{}>", escape(&dest_url)?)?;
308318
}
309-
write!(self.output, "<{}>", escape(&dest_url)?)?;
310319
}
311-
Tag::Image(_link_type, _dest_url, _title) => {}
320+
TagEnd::Image | TagEnd::HtmlBlock | TagEnd::MetadataBlock(..) => {}
312321
}
313322
}
314323
Event::Text(t) => {
@@ -346,6 +355,7 @@ impl<'e> ManRenderer<'e> {
346355
self.output.push_str("\\l'\\n(.lu'\n");
347356
}
348357
Event::TaskListMarker(_b) => unimplemented!(),
358+
Event::InlineHtml(..) => unimplemented!(),
349359
}
350360
}
351361
Ok(())

crates/mdman/src/format/text.rs

Lines changed: 50 additions & 40 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, HeadingLevel, LinkType, Tag};
6+
use pulldown_cmark::{Alignment, Event, HeadingLevel, LinkType, Tag, TagEnd};
77
use std::fmt::Write;
88
use std::mem;
99
use url::Url;
@@ -102,6 +102,7 @@ impl<'e> TextRenderer<'e> {
102102
// Whether or not word-wrapping is enabled.
103103
let mut wrap_text = true;
104104

105+
let mut last_seen_link_data = None;
105106
while let Some((event, range)) = self.parser.next() {
106107
let this_suppress_paragraph = suppress_paragraph;
107108
// Always reset suppression, even if the next event isn't a
@@ -116,7 +117,7 @@ impl<'e> TextRenderer<'e> {
116117
self.flush();
117118
}
118119
}
119-
Tag::Heading(level, ..) => {
120+
Tag::Heading { level, .. } => {
120121
self.flush();
121122
if level == HeadingLevel::H1 {
122123
let text = header_text(&mut self.parser)?;
@@ -180,7 +181,12 @@ impl<'e> TextRenderer<'e> {
180181
Tag::Strong => {}
181182
// Strikethrough isn't usually supported for TTY.
182183
Tag::Strikethrough => self.word.push_str("~~"),
183-
Tag::Link(link_type, dest_url, _title) => {
184+
Tag::Link {
185+
link_type,
186+
dest_url,
187+
..
188+
} => {
189+
last_seen_link_data = Some((link_type.clone(), dest_url.to_owned()));
184190
if dest_url.starts_with('#') {
185191
// In a man page, page-relative anchors don't
186192
// have much meaning.
@@ -213,59 +219,62 @@ impl<'e> TextRenderer<'e> {
213219
}
214220
}
215221
}
216-
Tag::Image(_link_type, _dest_url, _title) => {
222+
Tag::Image { .. } => {
217223
bail!("images are not currently supported")
218224
}
225+
Tag::HtmlBlock { .. } | Tag::MetadataBlock { .. } => {}
219226
}
220227
}
221-
Event::End(tag) => match &tag {
222-
Tag::Paragraph => {
228+
Event::End(tag_end) => match &tag_end {
229+
TagEnd::Paragraph => {
223230
self.flush();
224231
self.hard_break();
225232
}
226-
Tag::Heading(..) => {}
227-
Tag::BlockQuote => {
233+
TagEnd::Heading(..) => {}
234+
TagEnd::BlockQuote => {
228235
self.indent -= 3;
229236
}
230-
Tag::CodeBlock(_kind) => {
237+
TagEnd::CodeBlock => {
231238
self.hard_break();
232239
wrap_text = true;
233240
self.indent -= 4;
234241
}
235-
Tag::List(_) => {
242+
TagEnd::List(..) => {
236243
list.pop();
237244
}
238-
Tag::Item => {
245+
TagEnd::Item => {
239246
self.flush();
240247
self.indent -= 3;
241248
self.hard_break();
242249
}
243-
Tag::FootnoteDefinition(_label) => {}
244-
Tag::Table(_) => {}
245-
Tag::TableHead => {}
246-
Tag::TableRow => {}
247-
Tag::TableCell => {}
248-
Tag::Emphasis => {}
249-
Tag::Strong => {}
250-
Tag::Strikethrough => self.word.push_str("~~"),
251-
Tag::Link(link_type, dest_url, _title) => {
252-
if dest_url.starts_with('#') {
253-
continue;
254-
}
255-
match link_type {
256-
LinkType::Autolink | LinkType::Email => {}
257-
LinkType::Inline
258-
| LinkType::Reference
259-
| LinkType::Collapsed
260-
| LinkType::Shortcut => self.flush_word(),
261-
_ => {
262-
panic!("unexpected tag {:?}", tag);
250+
TagEnd::FootnoteDefinition => {}
251+
TagEnd::Table => {}
252+
TagEnd::TableHead => {}
253+
TagEnd::TableRow => {}
254+
TagEnd::TableCell => {}
255+
TagEnd::Emphasis => {}
256+
TagEnd::Strong => {}
257+
TagEnd::Strikethrough => self.word.push_str("~~"),
258+
TagEnd::Link => {
259+
if let Some((link_type, ref dest_url)) = last_seen_link_data {
260+
if dest_url.starts_with('#') {
261+
continue;
262+
}
263+
match link_type {
264+
LinkType::Autolink | LinkType::Email => {}
265+
LinkType::Inline
266+
| LinkType::Reference
267+
| LinkType::Collapsed
268+
| LinkType::Shortcut => self.flush_word(),
269+
_ => {
270+
panic!("unexpected tag {:?}", tag_end);
271+
}
263272
}
273+
self.flush_word();
274+
write!(self.word, "<{}>", dest_url)?;
264275
}
265-
self.flush_word();
266-
write!(self.word, "<{}>", dest_url)?;
267276
}
268-
Tag::Image(_link_type, _dest_url, _title) => {}
277+
TagEnd::Image | TagEnd::HtmlBlock | TagEnd::MetadataBlock(..) => {}
269278
},
270279
Event::Text(t) | Event::Code(t) => {
271280
if wrap_text {
@@ -337,6 +346,7 @@ impl<'e> TextRenderer<'e> {
337346
self.flush();
338347
}
339348
Event::TaskListMarker(_b) => unimplemented!(),
349+
Event::InlineHtml(..) => unimplemented!(),
340350
}
341351
}
342352
Ok(())
@@ -451,20 +461,20 @@ impl Table {
451461
| Tag::Strong => {}
452462
Tag::Strikethrough => self.cell.push_str("~~"),
453463
// Links not yet supported, they usually won't fit.
454-
Tag::Link(_, _, _) => {}
464+
Tag::Link { .. } => {}
455465
_ => bail!("unexpected tag in table: {:?}", tag),
456466
},
457-
Event::End(tag) => match tag {
458-
Tag::Table(_) => return self.render(indent),
459-
Tag::TableCell => {
467+
Event::End(tag_end) => match tag_end {
468+
TagEnd::Table => return self.render(indent),
469+
TagEnd::TableCell => {
460470
let cell = mem::replace(&mut self.cell, String::new());
461471
self.row.push(cell);
462472
}
463-
Tag::TableHead | Tag::TableRow => {
473+
TagEnd::TableHead | TagEnd::TableRow => {
464474
let row = mem::replace(&mut self.row, Vec::new());
465475
self.rows.push(row);
466476
}
467-
Tag::Strikethrough => self.cell.push_str("~~"),
477+
TagEnd::Strikethrough => self.cell.push_str("~~"),
468478
_ => {}
469479
},
470480
Event::Text(t) | Event::Code(t) => {

crates/mdman/src/lib.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! mdman markdown to man converter.
22
33
use anyhow::{bail, Context, Error};
4-
use pulldown_cmark::{CowStr, Event, LinkType, Options, Parser, Tag};
4+
use pulldown_cmark::{CowStr, Event, LinkType, Options, Parser, Tag, TagEnd};
55
use std::collections::HashMap;
66
use std::fs;
77
use std::io::{self, BufRead};
@@ -74,14 +74,21 @@ pub(crate) fn md_parser(input: &str, url: Option<Url>) -> EventIter<'_> {
7474
let parser = parser.into_offset_iter();
7575
// Translate all links to include the base url.
7676
let parser = parser.map(move |(event, range)| match event {
77-
Event::Start(Tag::Link(lt, dest_url, title)) if !matches!(lt, LinkType::Email) => (
78-
Event::Start(Tag::Link(lt, join_url(url.as_ref(), dest_url), title)),
79-
range,
80-
),
81-
Event::End(Tag::Link(lt, dest_url, title)) if !matches!(lt, LinkType::Email) => (
82-
Event::End(Tag::Link(lt, join_url(url.as_ref(), dest_url), title)),
77+
Event::Start(Tag::Link {
78+
link_type,
79+
dest_url,
80+
title,
81+
id,
82+
}) if !matches!(link_type, LinkType::Email) => (
83+
Event::Start(Tag::Link {
84+
link_type,
85+
dest_url: join_url(url.as_ref(), dest_url),
86+
title,
87+
id,
88+
}),
8389
range,
8490
),
91+
Event::End(TagEnd::Link) => (Event::End(TagEnd::Link), range),
8592
_ => (event, range),
8693
});
8794
Box::new(parser)

0 commit comments

Comments
 (0)