Skip to content

Commit b62f48f

Browse files
bors[bot]lnicola
andauthored
Merge #6217
6217: Bump pulldown-cmark r=matklad a=lnicola Co-authored-by: Laurențiu Nicola <[email protected]>
2 parents 69f1c8a + e559066 commit b62f48f

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

Cargo.lock

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

crates/ide/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ itertools = "0.9.0"
1616
log = "0.4.8"
1717
rustc-hash = "1.1.0"
1818
oorandom = "11.1.2"
19-
pulldown-cmark-to-cmark = "5.0.0"
20-
pulldown-cmark = {version = "0.7.2", default-features = false}
19+
pulldown-cmark-to-cmark = "6.0.0"
20+
pulldown-cmark = { version = "0.8.0", default-features = false }
2121
url = "2.1.1"
2222

2323
stdx = { path = "../stdx", version = "0.0.0" }

crates/ide/src/doc_links.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
//! Resolves and rewrites links in markdown documentation.
22
3+
use std::convert::TryFrom;
34
use std::iter::once;
45

56
use itertools::Itertools;
6-
use pulldown_cmark::{CowStr, Event, LinkType, Options, Parser, Tag};
7+
use pulldown_cmark::{BrokenLink, CowStr, Event, InlineStr, LinkType, Options, Parser, Tag};
78
use pulldown_cmark_to_cmark::{cmark_with_options, Options as CmarkOptions};
89
use url::Url;
910

@@ -24,11 +25,13 @@ pub type DocumentationLink = String;
2425

2526
/// Rewrite documentation links in markdown to point to an online host (e.g. docs.rs)
2627
pub fn rewrite_links(db: &RootDatabase, markdown: &str, definition: &Definition) -> String {
27-
let doc = Parser::new_with_broken_link_callback(
28-
markdown,
29-
Options::empty(),
30-
Some(&|label, _| Some((/*url*/ label.to_string(), /*title*/ label.to_string()))),
31-
);
28+
let mut cb = |link: BrokenLink| {
29+
Some((
30+
/*url*/ link.reference.to_owned().into(),
31+
/*title*/ link.reference.to_owned().into(),
32+
))
33+
};
34+
let doc = Parser::new_with_broken_link_callback(markdown, Options::empty(), Some(&mut cb));
3235

3336
let doc = map_links(doc, |target, title: &str| {
3437
// This check is imperfect, there's some overlap between valid intra-doc links
@@ -66,11 +69,11 @@ pub fn remove_links(markdown: &str) -> String {
6669
let mut opts = Options::empty();
6770
opts.insert(Options::ENABLE_FOOTNOTES);
6871

69-
let doc = Parser::new_with_broken_link_callback(
70-
markdown,
71-
opts,
72-
Some(&|_, _| Some((String::new(), String::new()))),
73-
);
72+
let mut cb = |_: BrokenLink| {
73+
let empty = InlineStr::try_from("").unwrap();
74+
Some((CowStr::Inlined(empty.clone()), CowStr::Inlined(empty)))
75+
};
76+
let doc = Parser::new_with_broken_link_callback(markdown, opts, Some(&mut cb));
7477
let doc = doc.filter_map(move |evt| match evt {
7578
Event::Start(Tag::Link(link_type, ref target, ref title)) => {
7679
if link_type == LinkType::Inline && target.contains("://") {

0 commit comments

Comments
 (0)