aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock8
-rw-r--r--crates/ide/Cargo.toml4
-rw-r--r--crates/ide/src/doc_links.rs25
3 files changed, 20 insertions, 17 deletions
diff --git a/Cargo.lock b/Cargo.lock
index b890b6e19..bcd89f3a8 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1191,9 +1191,9 @@ dependencies = [
1191 1191
1192[[package]] 1192[[package]]
1193name = "pulldown-cmark" 1193name = "pulldown-cmark"
1194version = "0.7.2" 1194version = "0.8.0"
1195source = "registry+https://github.com/rust-lang/crates.io-index" 1195source = "registry+https://github.com/rust-lang/crates.io-index"
1196checksum = "ca36dea94d187597e104a5c8e4b07576a8a45aa5db48a65e12940d3eb7461f55" 1196checksum = "ffade02495f22453cd593159ea2f59827aae7f53fa8323f756799b670881dcf8"
1197dependencies = [ 1197dependencies = [
1198 "bitflags", 1198 "bitflags",
1199 "memchr", 1199 "memchr",
@@ -1202,9 +1202,9 @@ dependencies = [
1202 1202
1203[[package]] 1203[[package]]
1204name = "pulldown-cmark-to-cmark" 1204name = "pulldown-cmark-to-cmark"
1205version = "5.0.0" 1205version = "6.0.0"
1206source = "registry+https://github.com/rust-lang/crates.io-index" 1206source = "registry+https://github.com/rust-lang/crates.io-index"
1207checksum = "32accf4473121d8c0b508ca5673363703762d6cc59cf25af1df48f653346f736" 1207checksum = "e8f2b9878102358ec65434fdd1a9a161f8648bb2f531acc9260e4d094c96de23"
1208dependencies = [ 1208dependencies = [
1209 "pulldown-cmark", 1209 "pulldown-cmark",
1210] 1210]
diff --git a/crates/ide/Cargo.toml b/crates/ide/Cargo.toml
index f0257403d..29dc9a6a8 100644
--- a/crates/ide/Cargo.toml
+++ b/crates/ide/Cargo.toml
@@ -16,8 +16,8 @@ itertools = "0.9.0"
16log = "0.4.8" 16log = "0.4.8"
17rustc-hash = "1.1.0" 17rustc-hash = "1.1.0"
18oorandom = "11.1.2" 18oorandom = "11.1.2"
19pulldown-cmark-to-cmark = "5.0.0" 19pulldown-cmark-to-cmark = "6.0.0"
20pulldown-cmark = {version = "0.7.2", default-features = false} 20pulldown-cmark = { version = "0.8.0", default-features = false }
21url = "2.1.1" 21url = "2.1.1"
22 22
23stdx = { path = "../stdx", version = "0.0.0" } 23stdx = { path = "../stdx", version = "0.0.0" }
diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs
index 06af36b73..db3f911c8 100644
--- a/crates/ide/src/doc_links.rs
+++ b/crates/ide/src/doc_links.rs
@@ -1,9 +1,10 @@
1//! Resolves and rewrites links in markdown documentation. 1//! Resolves and rewrites links in markdown documentation.
2 2
3use std::convert::TryFrom;
3use std::iter::once; 4use std::iter::once;
4 5
5use itertools::Itertools; 6use itertools::Itertools;
6use pulldown_cmark::{CowStr, Event, LinkType, Options, Parser, Tag}; 7use pulldown_cmark::{BrokenLink, CowStr, Event, InlineStr, LinkType, Options, Parser, Tag};
7use pulldown_cmark_to_cmark::{cmark_with_options, Options as CmarkOptions}; 8use pulldown_cmark_to_cmark::{cmark_with_options, Options as CmarkOptions};
8use url::Url; 9use url::Url;
9 10
@@ -24,11 +25,13 @@ pub type DocumentationLink = String;
24 25
25/// Rewrite documentation links in markdown to point to an online host (e.g. docs.rs) 26/// Rewrite documentation links in markdown to point to an online host (e.g. docs.rs)
26pub fn rewrite_links(db: &RootDatabase, markdown: &str, definition: &Definition) -> String { 27pub fn rewrite_links(db: &RootDatabase, markdown: &str, definition: &Definition) -> String {
27 let doc = Parser::new_with_broken_link_callback( 28 let mut cb = |link: BrokenLink| {
28 markdown, 29 Some((
29 Options::empty(), 30 /*url*/ link.reference.to_owned().into(),
30 Some(&|label, _| Some((/*url*/ label.to_string(), /*title*/ label.to_string()))), 31 /*title*/ link.reference.to_owned().into(),
31 ); 32 ))
33 };
34 let doc = Parser::new_with_broken_link_callback(markdown, Options::empty(), Some(&mut cb));
32 35
33 let doc = map_links(doc, |target, title: &str| { 36 let doc = map_links(doc, |target, title: &str| {
34 // This check is imperfect, there's some overlap between valid intra-doc links 37 // This check is imperfect, there's some overlap between valid intra-doc links
@@ -66,11 +69,11 @@ pub fn remove_links(markdown: &str) -> String {
66 let mut opts = Options::empty(); 69 let mut opts = Options::empty();
67 opts.insert(Options::ENABLE_FOOTNOTES); 70 opts.insert(Options::ENABLE_FOOTNOTES);
68 71
69 let doc = Parser::new_with_broken_link_callback( 72 let mut cb = |_: BrokenLink| {
70 markdown, 73 let empty = InlineStr::try_from("").unwrap();
71 opts, 74 Some((CowStr::Inlined(empty.clone()), CowStr::Inlined(empty)))
72 Some(&|_, _| Some((String::new(), String::new()))), 75 };
73 ); 76 let doc = Parser::new_with_broken_link_callback(markdown, opts, Some(&mut cb));
74 let doc = doc.filter_map(move |evt| match evt { 77 let doc = doc.filter_map(move |evt| match evt {
75 Event::Start(Tag::Link(link_type, ref target, ref title)) => { 78 Event::Start(Tag::Link(link_type, ref target, ref title)) => {
76 if link_type == LinkType::Inline && target.contains("://") { 79 if link_type == LinkType::Inline && target.contains("://") {