Description
Following up on #87059 (big thanks @ahicks92 for the detailed feedback!):
[...] Rustdoc didn't do h tags right. It's not exactly systemic, but it's something like (level + 3) % 6, where what should be heading levels 4-6 (examples, etc) become heading level 1 and 2. This is confusing, but once you learn things like impl blocks tend to be heading level 3 and functions are usually level 4, you effectively have a "jump to next function" keystroke and so on.
Here's what's happening: in Markdown #
generally represents an h1
, ##
represents h2
, and so on. That means each docblock often has h1
s and h2
s in them, even though they are nested under higher-up h1
s and h2
s. For instance, https://doc.rust-lang.org/1.55.0/std/io/trait.Read.html has an <h1>Trait std::io::Read</h1>
and an <h1>Examples</h1>
. The latter should be <h2>
. Similarly, there's an <h4>fn read...</h4>
, with an <h1>Errors</h1>
nested under it. The latter should be <h5>
.
Per https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements#usage_notes:
Avoid skipping heading levels: always start from
<h1>
, followed by<h2>
and so on.
Use only one<h1>
per page or view. It should concisely describe the overall purpose of the content.
Fortunately, we already control the <h{level}>
tag that's emitted based on Markdown. The code is here:
rust/src/librustdoc/html/markdown.rs
Lines 535 to 540 in 2b6ed3b
- Add a way to keep track of what heading level we're generating Markdown into: are we nested under an
<h1>
or under an<h4>
? - Adjust the
{level}
interpolation to add the number of levels appropriate. This should be capped at 6, since h6 is the highest defined in HTML. - Adjust CSS styles appropriately.