Skip to content

Bump pulldown-cmark #6217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/ide/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ itertools = "0.9.0"
log = "0.4.8"
rustc-hash = "1.1.0"
oorandom = "11.1.2"
pulldown-cmark-to-cmark = "5.0.0"
pulldown-cmark = {version = "0.7.2", default-features = false}
pulldown-cmark-to-cmark = "6.0.0"
pulldown-cmark = { version = "0.8.0", default-features = false }
url = "2.1.1"

stdx = { path = "../stdx", version = "0.0.0" }
Expand Down
25 changes: 14 additions & 11 deletions crates/ide/src/doc_links.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! Resolves and rewrites links in markdown documentation.

use std::convert::TryFrom;
use std::iter::once;

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 url::Url;

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

/// 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 {
let doc = Parser::new_with_broken_link_callback(
markdown,
Options::empty(),
Some(&|label, _| Some((/*url*/ label.to_string(), /*title*/ label.to_string()))),
);
let mut cb = |link: BrokenLink| {
Some((
/*url*/ link.reference.to_owned().into(),
/*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| {
// This check is imperfect, there's some overlap between valid intra-doc links
Expand Down Expand Up @@ -66,11 +69,11 @@ pub fn remove_links(markdown: &str) -> String {
let mut opts = Options::empty();
opts.insert(Options::ENABLE_FOOTNOTES);

let doc = Parser::new_with_broken_link_callback(
markdown,
opts,
Some(&|_, _| Some((String::new(), String::new()))),
);
let mut cb = |_: BrokenLink| {
let empty = InlineStr::try_from("").unwrap();
Some((CowStr::Inlined(empty.clone()), CowStr::Inlined(empty)))
};
let doc = Parser::new_with_broken_link_callback(markdown, opts, Some(&mut cb));
let doc = doc.filter_map(move |evt| match evt {
Event::Start(Tag::Link(link_type, ref target, ref title)) => {
if link_type == LinkType::Inline && target.contains("://") {
Expand Down