-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
rustdoc: Add anchors to section headers #12687
Conversation
Is the yellow highlight necessary? I don't think it serves any purpose and it adds visual noise imo. Looks good otherwise. |
It was initially implemented for jumping to methods and such because it's quite a forest once you get into the nitty gritty. That may be a little different from this, but I kinda like the highlights (not that I have a designer license any more) |
What happens with something like # General Topic 1
## Example
# General Topic 2
## Example Do both |
@huonw, good catch. I think I'll again adopt what github does and name the second one |
Expanding on that example above, AFAICT each markdown chunk is rendered in isolation via a These should have unique anchors too: I guess just adding the current method/function/whatever to the subsection would work (e.g. |
Oh, I guess one could just put the parent information into the markdown struct itself via a |
Updated with a task-local map which is reset across page boundaries. |
// Make sure our hyphenated ID is unique for this page | ||
let id = local_data::get_mut(used_header_map, |map| { | ||
let map = map.unwrap(); | ||
match map.find(&id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't this be
match map.find_mut(&id) {
None => {}
Some(a) => { *a += 1; format!("{}-{}", id, a - 1); return }
}
map.insert(id.clone(), 1);
?
(Not that performance matters much here.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks cleaner to me!
I'm not keen on having the implicit almost-global (especially if this part of rustdoc is ever parallised, but I guess this is unlikely to happen, since markdown rendering is now really fast since we're not shelling out to pandoc, right?), but it is certainly a neat solution to this. |
I think this strategy would work with parallelism because we'll only ever parallelize on the granularity of rendering pages, not rendering within a page itself (we generate a huge number of pages). |
Updated with comments |
This commit adds a appear-on-over link to all section headers to generated documentation. Each header also receives an id now, even those generated through markdown. The purpose of this is to provide easy to link to sections. This modifies the default header markdown generation because the default id added looks like "toc_NN" which is difficult to reconcile among all sections (by default each section gets a "toc_0" id), and it's also not very descriptive of where you're going. This chooses to adopt the github-style anchors by taking the contents of the title and hyphen-separating them (after lower casing). Closes rust-lang#12681
This commit adds a appear-on-over link to all section headers to generated documentation. Each header also receives an id now, even those generated through markdown. The purpose of this is to provide easy to link to sections. This modifies the default header markdown generation because the default id added looks like "toc_NN" which is difficult to reconcile among all sections (by default each section gets a "toc_0" id), and it's also not very descriptive of where you're going. This chooses to adopt the github-style anchors by taking the contents of the title and hyphen-separating them (after lower casing). Closes #12681
Improve documentation for `buildScripts.overrideCommand` / `checkOnSave.overrideCommand`
…Frednet Don't suggest `Box::default()` in functions with differing generics Fixes rust-lang#12684 changelog: none
This commit adds a appear-on-over link to all section headers to generated
documentation. Each header also receives an id now, even those generated through
markdown. The purpose of this is to provide easy to link to sections.
This modifies the default header markdown generation because the default id
added looks like "toc_NN" which is difficult to reconcile among all sections (by
default each section gets a "toc_0" id), and it's also not very descriptive of
where you're going.
This chooses to adopt the github-style anchors by taking the contents of the
title and hyphen-separating them (after lower casing).
Closes #12681