Rollup merge of #48335 - Manishearth:shortcut-links, r=QuietMisdreavus
Implement implied shortcut links for intra-rustdoc-links cc https://github.com/rust-lang/rust/issues/43466 Needs https://github.com/google/pulldown-cmark/pull/126 r? @QuietMisdreavus
This commit is contained in:
commit
fe1293f8a9
8
src/Cargo.lock
generated
8
src/Cargo.lock
generated
@ -1086,7 +1086,7 @@ dependencies = [
|
||||
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"open 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pulldown-cmark 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -1383,7 +1383,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "pulldown-cmark"
|
||||
version = "0.1.0"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -2104,7 +2104,7 @@ dependencies = [
|
||||
name = "rustdoc"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"pulldown-cmark 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@ -2886,7 +2886,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum pest 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0a6dda33d67c26f0aac90d324ab2eb7239c819fc7b2552fe9faa4fe88441edc8"
|
||||
"checksum pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3a8b4c6b8165cd1a1cd4b9b120978131389f64bdaf456435caa41e630edba903"
|
||||
"checksum pulldown-cmark 0.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "378e941dbd392c101f2cb88097fa4d7167bc421d4b88de3ff7dbee503bc3233b"
|
||||
"checksum pulldown-cmark 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a656fdb8b6848f896df5e478a0eb9083681663e37dcb77dd16981ff65329fe8b"
|
||||
"checksum pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d6fdf85cda6cadfae5428a54661d431330b312bc767ddbc57adbedc24da66e32"
|
||||
"checksum quick-error 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eda5fe9b71976e62bc81b781206aaa076401769b2143379d3eb2118388babac4"
|
||||
"checksum quine-mc_cluskey 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "07589615d719a60c8dd8a4622e7946465dfef20d1a428f969e3443e7386d5f45"
|
||||
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
|
||||
|
@ -10,5 +10,5 @@ path = "lib.rs"
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
pulldown-cmark = { version = "0.1.0", default-features = false }
|
||||
pulldown-cmark = { version = "0.1.2", default-features = false }
|
||||
tempdir = "0.3"
|
||||
|
@ -1044,7 +1044,7 @@ fn resolve(cx: &DocContext, path_str: &str, is_val: bool) -> Result<(Def, Option
|
||||
|
||||
/// Resolve a string as a macro
|
||||
fn macro_resolve(cx: &DocContext, path_str: &str) -> Option<Def> {
|
||||
use syntax::ext::base::MacroKind;
|
||||
use syntax::ext::base::{MacroKind, SyntaxExtension};
|
||||
use syntax::ext::hygiene::Mark;
|
||||
let segment = ast::PathSegment {
|
||||
identifier: ast::Ident::from_str(path_str),
|
||||
@ -1061,7 +1061,11 @@ fn macro_resolve(cx: &DocContext, path_str: &str) -> Option<Def> {
|
||||
let res = resolver
|
||||
.resolve_macro_to_def_inner(mark, &path, MacroKind::Bang, false);
|
||||
if let Ok(def) = res {
|
||||
Some(def)
|
||||
if let SyntaxExtension::DeclMacro(..) = *resolver.get_macro(def) {
|
||||
Some(def)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else if let Some(def) = resolver.all_macros.get(&path_str.into()) {
|
||||
Some(*def)
|
||||
} else {
|
||||
|
@ -591,7 +591,15 @@ impl<'a> fmt::Display for Markdown<'a> {
|
||||
opts.insert(OPTION_ENABLE_TABLES);
|
||||
opts.insert(OPTION_ENABLE_FOOTNOTES);
|
||||
|
||||
let p = Parser::new_ext(md, opts);
|
||||
let replacer = |_: &str, s: &str| {
|
||||
if let Some(&(_, ref replace)) = links.into_iter().find(|link| &*link.0 == s) {
|
||||
Some((replace.clone(), s.to_owned()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
let p = Parser::new_with_broken_link_callback(md, opts, Some(&replacer));
|
||||
|
||||
let mut s = String::with_capacity(md.len() * 3 / 2);
|
||||
|
||||
@ -662,7 +670,16 @@ impl<'a> fmt::Display for MarkdownSummaryLine<'a> {
|
||||
// This is actually common enough to special-case
|
||||
if md.is_empty() { return Ok(()) }
|
||||
|
||||
let p = Parser::new(md);
|
||||
let replacer = |_: &str, s: &str| {
|
||||
if let Some(&(_, ref replace)) = links.into_iter().find(|link| &*link.0 == s) {
|
||||
Some((replace.clone(), s.to_owned()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
let p = Parser::new_with_broken_link_callback(md, Options::empty(),
|
||||
Some(&replacer));
|
||||
|
||||
let mut s = String::new();
|
||||
|
||||
@ -731,18 +748,30 @@ pub fn markdown_links(md: &str) -> Vec<String> {
|
||||
opts.insert(OPTION_ENABLE_TABLES);
|
||||
opts.insert(OPTION_ENABLE_FOOTNOTES);
|
||||
|
||||
let p = Parser::new_ext(md, opts);
|
||||
|
||||
let iter = Footnotes::new(HeadingLinks::new(p, None));
|
||||
let mut links = vec![];
|
||||
let shortcut_links = RefCell::new(vec![]);
|
||||
|
||||
for ev in iter {
|
||||
if let Event::Start(Tag::Link(dest, _)) = ev {
|
||||
debug!("found link: {}", dest);
|
||||
links.push(dest.into_owned());
|
||||
{
|
||||
let push = |_: &str, s: &str| {
|
||||
shortcut_links.borrow_mut().push(s.to_owned());
|
||||
None
|
||||
};
|
||||
let p = Parser::new_with_broken_link_callback(md, opts,
|
||||
Some(&push));
|
||||
|
||||
let iter = Footnotes::new(HeadingLinks::new(p, None));
|
||||
|
||||
for ev in iter {
|
||||
if let Event::Start(Tag::Link(dest, _)) = ev {
|
||||
debug!("found link: {}", dest);
|
||||
links.push(dest.into_owned());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut shortcut_links = shortcut_links.into_inner();
|
||||
links.extend(shortcut_links.drain(..));
|
||||
|
||||
links
|
||||
}
|
||||
|
||||
|
@ -77,3 +77,15 @@ pub trait SoAmbiguous {}
|
||||
|
||||
#[allow(bad_style)]
|
||||
pub fn SoAmbiguous() {}
|
||||
|
||||
|
||||
// @has - '//a/@href' '../intra_links/struct.ThisType.html'
|
||||
// @has - '//a/@href' '../intra_links/struct.ThisType.html#method.this_method'
|
||||
// @has - '//a/@href' '../intra_links/enum.ThisEnum.html'
|
||||
// @has - '//a/@href' '../intra_links/enum.ThisEnum.html#ThisVariant.v'
|
||||
/// Shortcut links for:
|
||||
/// * [`ThisType`]
|
||||
/// * [`ThisType::this_method`]
|
||||
/// * [ThisEnum]
|
||||
/// * [ThisEnum::ThisVariant]
|
||||
pub struct SomeOtherType;
|
||||
|
Loading…
Reference in New Issue
Block a user