diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-01-18 19:36:03 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-18 19:36:03 +0100 |
| commit | 36e58ea6bf7aa104bad78f5e291d53887678c283 (patch) | |
| tree | f38998b3ece6087e979ff86415bfd15f5e2877d2 | |
| parent | 733c7f440e7777f35bb527f8b75cb9351d31c14d (diff) | |
| parent | 298e8ad5dc79ecb9b5b6140499e950d6ac5f09b1 (diff) | |
| download | rust-36e58ea6bf7aa104bad78f5e291d53887678c283.tar.gz rust-36e58ea6bf7aa104bad78f5e291d53887678c283.zip | |
Rollup merge of #68224 - GuillaumeGomez:prevent-urls-in-headings, r=ollie27
Prevent urls in headings Fixes #68215. cc @pietroalbini @ollie27 r? @kinnison
| -rw-r--r-- | src/librustdoc/html/markdown.rs | 7 | ||||
| -rw-r--r-- | src/test/rustdoc/remove-url-from-headings.rs | 17 |
2 files changed, 22 insertions, 2 deletions
diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index c5f88f9f7f4..c87964af020 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -380,7 +380,10 @@ impl<'a, 'b, 'ids, I: Iterator<Item = Event<'a>>> Iterator for HeadingLinks<'a, } _ => {} } - self.buf.push_back(event); + match event { + Event::Start(Tag::Link(_, _, _)) | Event::End(Tag::Link(..)) => {} + event => self.buf.push_back(event), + } } let id = self.id_map.derive(id); @@ -395,7 +398,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..9761c1ddbe2 --- /dev/null +++ b/src/test/rustdoc/remove-url-from-headings.rs @@ -0,0 +1,17 @@ +#![crate_name = "foo"] + +// @has foo/fn.foo.html +// !@has - '//a[@href="http://a.a"]' +// @has - '//a[@href="#implementing-stuff-somewhere"]' 'Implementing stuff somewhere' +// @has - '//a[@href="#another-one-urg"]' 'Another one urg' + +/// fooo +/// +/// # Implementing [stuff](http://a.a "title") somewhere +/// +/// hello +/// +/// # Another [one][two] urg +/// +/// [two]: http://a.a +pub fn foo() {} |
