Skip to content

Commit

Permalink
Prevent urls in headings
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jan 14, 2020
1 parent bf84eb5 commit 1bf9f69
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/librustdoc/html/markdown.rs
Expand Up @@ -380,7 +380,11 @@ impl<'a, 'b, 'ids, I: Iterator<Item = Event<'a>>> Iterator for HeadingLinks<'a,
}
_ => {}
}
self.buf.push_back(event);
match event {
Event::Start(Tag::Link(_, _, text)) => self.buf.push_back(Event::Text(text)),
Event::End(Tag::Link(..)) => {}
event => self.buf.push_back(event),
}
}
let id = self.id_map.derive(id);

Expand All @@ -395,7 +399,7 @@ impl<'a, 'b, 'ids, I: Iterator<Item = Event<'a>>> Iterator for HeadingLinks<'a,

let start_tags = format!(
"<h{level} id=\"{id}\" class=\"section-header\">\
<a href=\"#{id}\">",
<a href=\"#{id}\">",
id = id,
level = level
);
Expand Down
12 changes: 12 additions & 0 deletions src/test/rustdoc/remove-url-from-headings.rs
@@ -0,0 +1,12 @@
#![crate_name = "foo"]

// @has foo/fn.foo.html
// !@has - '//a[@href="http://a.a"]'
// @has - '//a[@href="#implementing-stuff-somewhere"]' 'Implementing stuff somewhere'

/// fooo
///
/// # Implementing [stuff](http://a.a) somewhere
///
/// hello
pub fn foo() {}

0 comments on commit 1bf9f69

Please sign in to comment.