Include shortcut links in markdown_links

This commit is contained in:
Manish Goregaokar 2018-02-18 13:37:52 -08:00
parent 6818551c6f
commit f60aeec5d5

View file

@ -731,18 +731,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
}