diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2020-01-14 19:21:10 +0100 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2020-01-14 19:21:10 +0100 |
| commit | 1bf9f69579e525a35fd712b7f00f2f24eebc6387 (patch) | |
| tree | fadd93494e06640678b3beae52ab56a7734d4254 | |
| parent | bf84eb538fd16743240434b3e837b36c35719fee (diff) | |
| download | rust-1bf9f69579e525a35fd712b7f00f2f24eebc6387.tar.gz rust-1bf9f69579e525a35fd712b7f00f2f24eebc6387.zip | |
Prevent urls in headings
| -rw-r--r-- | src/librustdoc/html/markdown.rs | 8 | ||||
| -rw-r--r-- | src/test/rustdoc/remove-url-from-headings.rs | 12 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index c5f88f9f7f4..b2f5c8e81ff 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -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); @@ -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 ); diff --git a/src/test/rustdoc/remove-url-from-headings.rs b/src/test/rustdoc/remove-url-from-headings.rs new file mode 100644 index 00000000000..7fbcdbafa74 --- /dev/null +++ b/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() {} |
