Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent urls in headings #68224

Merged
merged 4 commits into from
Jan 18, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
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)),
ollie27 marked this conversation as resolved.
Show resolved Hide resolved
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
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// # Implementing [stuff](http://a.a) somewhere
/// # Implementing [stuff](http://a.a "title") somewhere

We may as well check that the link title doesn't show up accidentally while we're at it.

///
/// hello
pub fn foo() {}