6217: Bump pulldown-cmark r=matklad a=lnicola



Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
This commit is contained in:
bors[bot] 2020-10-14 10:26:13 +00:00 committed by GitHub
commit b62f48f535
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 17 deletions

8
Cargo.lock generated
View file

@ -1191,9 +1191,9 @@ dependencies = [
[[package]] [[package]]
name = "pulldown-cmark" name = "pulldown-cmark"
version = "0.7.2" version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca36dea94d187597e104a5c8e4b07576a8a45aa5db48a65e12940d3eb7461f55" checksum = "ffade02495f22453cd593159ea2f59827aae7f53fa8323f756799b670881dcf8"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"memchr", "memchr",
@ -1202,9 +1202,9 @@ dependencies = [
[[package]] [[package]]
name = "pulldown-cmark-to-cmark" name = "pulldown-cmark-to-cmark"
version = "5.0.0" version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32accf4473121d8c0b508ca5673363703762d6cc59cf25af1df48f653346f736" checksum = "e8f2b9878102358ec65434fdd1a9a161f8648bb2f531acc9260e4d094c96de23"
dependencies = [ dependencies = [
"pulldown-cmark", "pulldown-cmark",
] ]

View file

@ -16,8 +16,8 @@ itertools = "0.9.0"
log = "0.4.8" log = "0.4.8"
rustc-hash = "1.1.0" rustc-hash = "1.1.0"
oorandom = "11.1.2" oorandom = "11.1.2"
pulldown-cmark-to-cmark = "5.0.0" pulldown-cmark-to-cmark = "6.0.0"
pulldown-cmark = {version = "0.7.2", default-features = false} pulldown-cmark = { version = "0.8.0", default-features = false }
url = "2.1.1" url = "2.1.1"
stdx = { path = "../stdx", version = "0.0.0" } stdx = { path = "../stdx", version = "0.0.0" }

View file

@ -1,9 +1,10 @@
//! Resolves and rewrites links in markdown documentation. //! Resolves and rewrites links in markdown documentation.
use std::convert::TryFrom;
use std::iter::once; use std::iter::once;
use itertools::Itertools; use itertools::Itertools;
use pulldown_cmark::{CowStr, Event, LinkType, Options, Parser, Tag}; use pulldown_cmark::{BrokenLink, CowStr, Event, InlineStr, LinkType, Options, Parser, Tag};
use pulldown_cmark_to_cmark::{cmark_with_options, Options as CmarkOptions}; use pulldown_cmark_to_cmark::{cmark_with_options, Options as CmarkOptions};
use url::Url; use url::Url;
@ -24,11 +25,13 @@ pub type DocumentationLink = String;
/// Rewrite documentation links in markdown to point to an online host (e.g. docs.rs) /// Rewrite documentation links in markdown to point to an online host (e.g. docs.rs)
pub fn rewrite_links(db: &RootDatabase, markdown: &str, definition: &Definition) -> String { pub fn rewrite_links(db: &RootDatabase, markdown: &str, definition: &Definition) -> String {
let doc = Parser::new_with_broken_link_callback( let mut cb = |link: BrokenLink| {
markdown, Some((
Options::empty(), /*url*/ link.reference.to_owned().into(),
Some(&|label, _| Some((/*url*/ label.to_string(), /*title*/ label.to_string()))), /*title*/ link.reference.to_owned().into(),
); ))
};
let doc = Parser::new_with_broken_link_callback(markdown, Options::empty(), Some(&mut cb));
let doc = map_links(doc, |target, title: &str| { let doc = map_links(doc, |target, title: &str| {
// This check is imperfect, there's some overlap between valid intra-doc links // This check is imperfect, there's some overlap between valid intra-doc links
@ -66,11 +69,11 @@ pub fn remove_links(markdown: &str) -> String {
let mut opts = Options::empty(); let mut opts = Options::empty();
opts.insert(Options::ENABLE_FOOTNOTES); opts.insert(Options::ENABLE_FOOTNOTES);
let doc = Parser::new_with_broken_link_callback( let mut cb = |_: BrokenLink| {
markdown, let empty = InlineStr::try_from("").unwrap();
opts, Some((CowStr::Inlined(empty.clone()), CowStr::Inlined(empty)))
Some(&|_, _| Some((String::new(), String::new()))), };
); let doc = Parser::new_with_broken_link_callback(markdown, opts, Some(&mut cb));
let doc = doc.filter_map(move |evt| match evt { let doc = doc.filter_map(move |evt| match evt {
Event::Start(Tag::Link(link_type, ref target, ref title)) => { Event::Start(Tag::Link(link_type, ref target, ref title)) => {
if link_type == LinkType::Inline && target.contains("://") { if link_type == LinkType::Inline && target.contains("://") {