Skip to content

Commit 1d0ae9f

Browse files
committed
Generate shortcut links
1 parent f60aeec commit 1d0ae9f

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/librustdoc/html/markdown.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,15 @@ impl<'a> fmt::Display for Markdown<'a> {
591591
opts.insert(OPTION_ENABLE_TABLES);
592592
opts.insert(OPTION_ENABLE_FOOTNOTES);
593593

594-
let p = Parser::new_ext(md, opts);
594+
let replacer = |_: &str, s: &str| {
595+
if let Some(&(_, ref replace)) = links.into_iter().find(|link| &*link.0 == s) {
596+
Some((replace.clone(), s.to_owned()))
597+
} else {
598+
None
599+
}
600+
};
601+
602+
let p = Parser::new_with_broken_link_callback(md, opts, Some(&replacer));
595603

596604
let mut s = String::with_capacity(md.len() * 3 / 2);
597605

@@ -662,7 +670,16 @@ impl<'a> fmt::Display for MarkdownSummaryLine<'a> {
662670
// This is actually common enough to special-case
663671
if md.is_empty() { return Ok(()) }
664672

665-
let p = Parser::new(md);
673+
let replacer = |_: &str, s: &str| {
674+
if let Some(&(_, ref replace)) = links.into_iter().find(|link| &*link.0 == s) {
675+
Some((replace.clone(), s.to_owned()))
676+
} else {
677+
None
678+
}
679+
};
680+
681+
let p = Parser::new_with_broken_link_callback(md, Options::empty(),
682+
Some(&replacer));
666683

667684
let mut s = String::new();
668685

0 commit comments

Comments
 (0)