1
Fork 0

librustdoc: Use correct heading levels.

- Avoid multiple <h1>s on a page.
- The <h#> tags should follow a semantic hierarchy.
- Cap at h6 (no h7)
This commit is contained in:
Mukund Lakshman 2021-10-01 06:17:15 -04:00
parent e737694a4d
commit a8a40ea9a4
65 changed files with 147 additions and 118 deletions

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
This error suggests that the expression arm corresponding to the noted pattern This error suggests that the expression arm corresponding to the noted pattern
will never be reached as for all possible values of the expression being will never be reached as for all possible values of the expression being

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
This error indicates that an empty match expression is invalid because the type This error indicates that an empty match expression is invalid because the type
it is matching on is non-empty (there exist values of this type). In safe code it is matching on is non-empty (there exist values of this type). In safe code

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
This error indicates that the bindings in a match arm would require a value to This error indicates that the bindings in a match arm would require a value to
be moved into more than one location, thus violating unique ownership. Code be moved into more than one location, thus violating unique ownership. Code

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
In a pattern, all values that don't implement the `Copy` trait have to be bound In a pattern, all values that don't implement the `Copy` trait have to be bound
the same way. The goal here is to avoid binding simultaneously by-move and the same way. The goal here is to avoid binding simultaneously by-move and

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
Constants can only be initialized by a constant value or, in a future Constants can only be initialized by a constant value or, in a future
version of Rust, a call to a const function. This error indicates the use version of Rust, a call to a const function. This error indicates the use

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
You cannot define a struct (or enum) `Foo` that requires an instance of `Foo` You cannot define a struct (or enum) `Foo` that requires an instance of `Foo`
in order to make a new `Foo` value. This is because there would be no way a in order to make a new `Foo` value. This is because there would be no way a

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
When using the `#[simd]` attribute on a tuple struct, the components of the When using the `#[simd]` attribute on a tuple struct, the components of the
tuple struct must all be of a concrete, nongeneric type so the compiler can tuple struct must all be of a concrete, nongeneric type so the compiler can

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
Too many type arguments were supplied for a function. For example: Too many type arguments were supplied for a function. For example:

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
You gave too many lifetime arguments. Erroneous code example: You gave too many lifetime arguments. Erroneous code example:

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
Too few type arguments were supplied for a function. For example: Too few type arguments were supplied for a function. For example:

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
You gave too few lifetime arguments. Example: You gave too few lifetime arguments. Example:

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
You tried to provide a lifetime to a type which doesn't need it. You tried to provide a lifetime to a type which doesn't need it.
See `E0109` for more details. See `E0109` for more details.

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
More than one `main` function was found. More than one `main` function was found.

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
More than one function was declared with the `#[main]` attribute. More than one function was declared with the `#[main]` attribute.

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
There are various restrictions on transmuting between types in Rust; for example There are various restrictions on transmuting between types in Rust; for example
types being transmuted must have the same size. To apply all these restrictions, types being transmuted must have the same size. To apply all these restrictions,

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
Imports (`use` statements) are not allowed after non-item statements, such as Imports (`use` statements) are not allowed after non-item statements, such as
variable declarations and expression statements. variable declarations and expression statements.

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
An `if let` pattern attempts to match the pattern, and enters the body if the An `if let` pattern attempts to match the pattern, and enters the body if the
match was successful. If the match is irrefutable (when it cannot fail to match was successful. If the match is irrefutable (when it cannot fail to

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
A `while let` pattern attempts to match the pattern, and enters the body if the A `while let` pattern attempts to match the pattern, and enters the body if the
match was successful. If the match is irrefutable (when it cannot fail to match was successful. If the match is irrefutable (when it cannot fail to

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
`where` clauses must use generic type parameters: it does not make sense to use `where` clauses must use generic type parameters: it does not make sense to use
them otherwise. An example causing this error: them otherwise. An example causing this error:

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
An attempt to implement the `Copy` trait for an enum failed because one of the An attempt to implement the `Copy` trait for an enum failed because one of the
variants does not implement `Copy`. To fix this, you must implement `Copy` for variants does not implement `Copy`. To fix this, you must implement `Copy` for

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
You used a function or type which doesn't fit the requirements for where it was You used a function or type which doesn't fit the requirements for where it was
used. Erroneous code examples: used. Erroneous code examples:

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
This error indicates that not enough type parameters were found in a type or This error indicates that not enough type parameters were found in a type or
trait. trait.

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
This error indicates that too many type parameters were found in a type or This error indicates that too many type parameters were found in a type or
trait. trait.

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
Two items of the same name cannot be imported without rebinding one of the Two items of the same name cannot be imported without rebinding one of the
items under a new local name. items under a new local name.

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
You can't import a type or module when the name of the item being imported is You can't import a type or module when the name of the item being imported is
the same as another type or submodule defined in the module. the same as another type or submodule defined in the module.

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
You tried to supply a type which doesn't implement some trait in a location You tried to supply a type which doesn't implement some trait in a location
which expected that trait. This error typically occurs when working with which expected that trait. This error typically occurs when working with

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
Patterns used to bind names must be irrefutable. That is, they must guarantee Patterns used to bind names must be irrefutable. That is, they must guarantee
that a name will be extracted in all cases. Instead of pattern matching the that a name will be extracted in all cases. Instead of pattern matching the

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
Mutable borrows are not allowed in pattern guards, because matching cannot have Mutable borrows are not allowed in pattern guards, because matching cannot have
side effects. Side effects could alter the matched object or the environment side effects. Side effects could alter the matched object or the environment

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
Assignments are not allowed in pattern guards, because matching cannot have Assignments are not allowed in pattern guards, because matching cannot have
side effects. Side effects could alter the matched object or the environment side effects. Side effects could alter the matched object or the environment

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
Sub-bindings, e.g. `ref x @ Some(ref y)` are now allowed under Sub-bindings, e.g. `ref x @ Some(ref y)` are now allowed under
`#![feature(bindings_after_at)]` and checked to make sure that `#![feature(bindings_after_at)]` and checked to make sure that

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
An attempt was made to access an associated constant through either a generic An attempt was made to access an associated constant through either a generic
type parameter or `Self`. This is not supported yet. An example causing this type parameter or `Self`. This is not supported yet. An example causing this

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
This error occurs when an attempt is made to partially reinitialize a This error occurs when an attempt is made to partially reinitialize a
structure that is currently uninitialized. structure that is currently uninitialized.

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
This error occurs when an attempt is made to mutate the target of a mutable This error occurs when an attempt is made to mutate the target of a mutable
reference stored inside an immutable container. reference stored inside an immutable container.

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
This error occurs when an attempt is made to mutate or mutably reference data This error occurs when an attempt is made to mutate or mutably reference data
that a closure has captured immutably. that a closure has captured immutably.

View file

@ -1 +1 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
An attempt was made to mutate data using a non-mutable reference. This An attempt was made to mutate data using a non-mutable reference. This
commonly occurs when attempting to assign to a non-mutable reference of a commonly occurs when attempting to assign to a non-mutable reference of a

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
In Rust 1.3, the default object lifetime bounds are expected to change, as In Rust 1.3, the default object lifetime bounds are expected to change, as
described in [RFC 1156]. You are getting a warning because the compiler described in [RFC 1156]. You are getting a warning because the compiler

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler ### Note: this error code is no longer emitted by the compiler
You implemented a trait, overriding one or more of its associated types but did You implemented a trait, overriding one or more of its associated types but did
not reimplement its default methods. not reimplement its default methods.

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
The length of the platform-intrinsic function `simd_shuffle` wasn't specified. The length of the platform-intrinsic function `simd_shuffle` wasn't specified.

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
The `pub` keyword was used inside a function. The `pub` keyword was used inside a function.

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
The `pub` keyword was used inside a public enum. The `pub` keyword was used inside a public enum.

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
A stability attribute was used outside of the standard library. A stability attribute was used outside of the standard library.

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
This error occurs when an attempt is made to move a borrowed variable into a This error occurs when an attempt is made to move a borrowed variable into a
closure. closure.

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
Closures cannot mutate immutable captured variables. Closures cannot mutate immutable captured variables.

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
The type-checker needed to know the type of an expression, but that type had not The type-checker needed to know the type of an expression, but that type had not
yet been inferred. yet been inferred.

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
The `unwind` attribute was malformed. The `unwind` attribute was malformed.

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
The `Default` trait was derived on an enum. The `Default` trait was derived on an enum.

View file

@ -1,4 +1,4 @@
#### Note: this error code is no longer emitted by the compiler. ### Note: this error code is no longer emitted by the compiler.
Const parameters cannot depend on type parameters. Const parameters cannot depend on type parameters.
The following is therefore invalid: The following is therefore invalid:

View file

@ -39,14 +39,14 @@ impl ExternalHtml {
let bc = format!( let bc = format!(
"{}{}", "{}{}",
bc, bc,
Markdown(&m_bc, &[], id_map, codes, edition, playground).into_string() Markdown(&m_bc, &[], id_map, codes, edition, playground, 0).into_string()
); );
let ac = load_external_files(after_content, diag)?; let ac = load_external_files(after_content, diag)?;
let m_ac = load_external_files(md_after_content, diag)?; let m_ac = load_external_files(md_after_content, diag)?;
let ac = format!( let ac = format!(
"{}{}", "{}{}",
ac, ac,
Markdown(&m_ac, &[], id_map, codes, edition, playground).into_string() Markdown(&m_ac, &[], id_map, codes, edition, playground, 0).into_string()
); );
Some(ExternalHtml { in_header: ih, before_content: bc, after_content: ac }) Some(ExternalHtml { in_header: ih, before_content: bc, after_content: ac })
} }

View file

@ -12,7 +12,7 @@
//! //!
//! let s = "My *markdown* _text_"; //! let s = "My *markdown* _text_";
//! let mut id_map = IdMap::new(); //! let mut id_map = IdMap::new();
//! let md = Markdown(s, &[], &mut id_map, ErrorCodes::Yes, Edition::Edition2015, &None); //! let md = Markdown(s, &[], &mut id_map, ErrorCodes::Yes, Edition::Edition2015, &None, 0);
//! let html = md.into_string(); //! let html = md.into_string();
//! // ... something using html //! // ... something using html
//! ``` //! ```
@ -47,6 +47,8 @@ use pulldown_cmark::{
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
const MAX_HEADER_LEVEL: u32 = 6;
/// Options for rendering Markdown in the main body of documentation. /// Options for rendering Markdown in the main body of documentation.
pub(crate) fn main_body_opts() -> Options { pub(crate) fn main_body_opts() -> Options {
Options::ENABLE_TABLES Options::ENABLE_TABLES
@ -78,6 +80,7 @@ pub struct Markdown<'a>(
/// Default edition to use when parsing doctests (to add a `fn main`). /// Default edition to use when parsing doctests (to add a `fn main`).
pub Edition, pub Edition,
pub &'a Option<Playground>, pub &'a Option<Playground>,
pub u32,
); );
/// A tuple struct like `Markdown` that renders the markdown with a table of contents. /// A tuple struct like `Markdown` that renders the markdown with a table of contents.
crate struct MarkdownWithToc<'a>( crate struct MarkdownWithToc<'a>(
@ -489,11 +492,12 @@ struct HeadingLinks<'a, 'b, 'ids, I> {
toc: Option<&'b mut TocBuilder>, toc: Option<&'b mut TocBuilder>,
buf: VecDeque<SpannedEvent<'a>>, buf: VecDeque<SpannedEvent<'a>>,
id_map: &'ids mut IdMap, id_map: &'ids mut IdMap,
level: u32,
} }
impl<'a, 'b, 'ids, I> HeadingLinks<'a, 'b, 'ids, I> { impl<'a, 'b, 'ids, I> HeadingLinks<'a, 'b, 'ids, I> {
fn new(iter: I, toc: Option<&'b mut TocBuilder>, ids: &'ids mut IdMap) -> Self { fn new(iter: I, toc: Option<&'b mut TocBuilder>, ids: &'ids mut IdMap, level: u32) -> Self {
HeadingLinks { inner: iter, toc, buf: VecDeque::new(), id_map: ids } HeadingLinks { inner: iter, toc, buf: VecDeque::new(), id_map: ids, level }
} }
} }
@ -530,6 +534,7 @@ impl<'a, 'b, 'ids, I: Iterator<Item = SpannedEvent<'a>>> Iterator
self.buf.push_front((Event::Html(format!("{} ", sec).into()), 0..0)); self.buf.push_front((Event::Html(format!("{} ", sec).into()), 0..0));
} }
let level = std::cmp::min(level + self.level + 1, MAX_HEADER_LEVEL);
self.buf.push_back((Event::Html(format!("</a></h{}>", level).into()), 0..0)); self.buf.push_back((Event::Html(format!("</a></h{}>", level).into()), 0..0));
let start_tags = format!( let start_tags = format!(
@ -1005,7 +1010,7 @@ impl LangString {
impl Markdown<'_> { impl Markdown<'_> {
pub fn into_string(self) -> String { pub fn into_string(self) -> String {
let Markdown(md, links, mut ids, codes, edition, playground) = self; let Markdown(md, links, mut ids, codes, edition, playground, level) = self;
// This is actually common enough to special-case // This is actually common enough to special-case
if md.is_empty() { if md.is_empty() {
@ -1026,7 +1031,7 @@ impl Markdown<'_> {
let mut s = String::with_capacity(md.len() * 3 / 2); let mut s = String::with_capacity(md.len() * 3 / 2);
let p = HeadingLinks::new(p, None, &mut ids); let p = HeadingLinks::new(p, None, &mut ids, level);
let p = Footnotes::new(p); let p = Footnotes::new(p);
let p = LinkReplacer::new(p.map(|(ev, _)| ev), links); let p = LinkReplacer::new(p.map(|(ev, _)| ev), links);
let p = TableWrapper::new(p); let p = TableWrapper::new(p);
@ -1048,7 +1053,7 @@ impl MarkdownWithToc<'_> {
let mut toc = TocBuilder::new(); let mut toc = TocBuilder::new();
{ {
let p = HeadingLinks::new(p, Some(&mut toc), &mut ids); let p = HeadingLinks::new(p, Some(&mut toc), &mut ids, 0);
let p = Footnotes::new(p); let p = Footnotes::new(p);
let p = TableWrapper::new(p.map(|(ev, _)| ev)); let p = TableWrapper::new(p.map(|(ev, _)| ev));
let p = CodeBlocks::new(p, codes, edition, playground); let p = CodeBlocks::new(p, codes, edition, playground);
@ -1077,7 +1082,7 @@ impl MarkdownHtml<'_> {
let mut s = String::with_capacity(md.len() * 3 / 2); let mut s = String::with_capacity(md.len() * 3 / 2);
let p = HeadingLinks::new(p, None, &mut ids); let p = HeadingLinks::new(p, None, &mut ids, 0);
let p = Footnotes::new(p); let p = Footnotes::new(p);
let p = TableWrapper::new(p.map(|(ev, _)| ev)); let p = TableWrapper::new(p.map(|(ev, _)| ev));
let p = CodeBlocks::new(p, codes, edition, playground); let p = CodeBlocks::new(p, codes, edition, playground);
@ -1295,7 +1300,7 @@ crate fn markdown_links(md: &str) -> Vec<MarkdownLink> {
// There's no need to thread an IdMap through to here because // There's no need to thread an IdMap through to here because
// the IDs generated aren't going to be emitted anywhere. // the IDs generated aren't going to be emitted anywhere.
let mut ids = IdMap::new(); let mut ids = IdMap::new();
let iter = Footnotes::new(HeadingLinks::new(p, None, &mut ids)); let iter = Footnotes::new(HeadingLinks::new(p, None, &mut ids, 0));
for ev in iter { for ev in iter {
if let Event::Start(Tag::Link(kind, dest, _)) = ev.0 { if let Event::Start(Tag::Link(kind, dest, _)) = ev.0 {

View file

@ -147,33 +147,33 @@ fn test_lang_string_tokenizer() {
fn test_header() { fn test_header() {
fn t(input: &str, expect: &str) { fn t(input: &str, expect: &str) {
let mut map = IdMap::new(); let mut map = IdMap::new();
let output = let output = Markdown(input, &[], &mut map, ErrorCodes::Yes, DEFAULT_EDITION, &None, 0)
Markdown(input, &[], &mut map, ErrorCodes::Yes, DEFAULT_EDITION, &None).into_string(); .into_string();
assert_eq!(output, expect, "original: {}", input); assert_eq!(output, expect, "original: {}", input);
} }
t( t(
"# Foo bar", "# Foo bar",
"<h1 id=\"foo-bar\" class=\"section-header\"><a href=\"#foo-bar\">Foo bar</a></h1>", "<h2 id=\"foo-bar\" class=\"section-header\"><a href=\"#foo-bar\">Foo bar</a></h2>",
); );
t( t(
"## Foo-bar_baz qux", "## Foo-bar_baz qux",
"<h2 id=\"foo-bar_baz-qux\" class=\"section-header\">\ "<h3 id=\"foo-bar_baz-qux\" class=\"section-header\">\
<a href=\"#foo-bar_baz-qux\">Foo-bar_baz qux</a></h2>", <a href=\"#foo-bar_baz-qux\">Foo-bar_baz qux</a></h3>",
); );
t( t(
"### **Foo** *bar* baz!?!& -_qux_-%", "### **Foo** *bar* baz!?!& -_qux_-%",
"<h3 id=\"foo-bar-baz--qux-\" class=\"section-header\">\ "<h4 id=\"foo-bar-baz--qux-\" class=\"section-header\">\
<a href=\"#foo-bar-baz--qux-\"><strong>Foo</strong> \ <a href=\"#foo-bar-baz--qux-\"><strong>Foo</strong> \
<em>bar</em> baz!?!&amp; -<em>qux</em>-%</a>\ <em>bar</em> baz!?!&amp; -<em>qux</em>-%</a>\
</h3>", </h4>",
); );
t( t(
"#### **Foo?** & \\*bar?!* _`baz`_ ❤ #qux", "#### **Foo?** & \\*bar?!* _`baz`_ ❤ #qux",
"<h4 id=\"foo--bar--baz--qux\" class=\"section-header\">\ "<h5 id=\"foo--bar--baz--qux\" class=\"section-header\">\
<a href=\"#foo--bar--baz--qux\"><strong>Foo?</strong> &amp; *bar?!* \ <a href=\"#foo--bar--baz--qux\"><strong>Foo?</strong> &amp; *bar?!* \
<em><code>baz</code></em> #qux</a>\ <em><code>baz</code></em> #qux</a>\
</h4>", </h5>",
); );
} }
@ -182,39 +182,39 @@ fn test_header_ids_multiple_blocks() {
let mut map = IdMap::new(); let mut map = IdMap::new();
fn t(map: &mut IdMap, input: &str, expect: &str) { fn t(map: &mut IdMap, input: &str, expect: &str) {
let output = let output =
Markdown(input, &[], map, ErrorCodes::Yes, DEFAULT_EDITION, &None).into_string(); Markdown(input, &[], map, ErrorCodes::Yes, DEFAULT_EDITION, &None, 0).into_string();
assert_eq!(output, expect, "original: {}", input); assert_eq!(output, expect, "original: {}", input);
} }
t( t(
&mut map, &mut map,
"# Example", "# Example",
"<h1 id=\"example\" class=\"section-header\"><a href=\"#example\">Example</a></h1>", "<h2 id=\"example\" class=\"section-header\"><a href=\"#example\">Example</a></h2>",
); );
t( t(
&mut map, &mut map,
"# Panics", "# Panics",
"<h1 id=\"panics\" class=\"section-header\"><a href=\"#panics\">Panics</a></h1>", "<h2 id=\"panics\" class=\"section-header\"><a href=\"#panics\">Panics</a></h2>",
); );
t( t(
&mut map, &mut map,
"# Example", "# Example",
"<h1 id=\"example-1\" class=\"section-header\"><a href=\"#example-1\">Example</a></h1>", "<h2 id=\"example-1\" class=\"section-header\"><a href=\"#example-1\">Example</a></h2>",
); );
t( t(
&mut map, &mut map,
"# Main", "# Main",
"<h1 id=\"main-1\" class=\"section-header\"><a href=\"#main-1\">Main</a></h1>", "<h2 id=\"main-1\" class=\"section-header\"><a href=\"#main-1\">Main</a></h2>",
); );
t( t(
&mut map, &mut map,
"# Example", "# Example",
"<h1 id=\"example-2\" class=\"section-header\"><a href=\"#example-2\">Example</a></h1>", "<h2 id=\"example-2\" class=\"section-header\"><a href=\"#example-2\">Example</a></h2>",
); );
t( t(
&mut map, &mut map,
"# Panics", "# Panics",
"<h1 id=\"panics-1\" class=\"section-header\"><a href=\"#panics-1\">Panics</a></h1>", "<h2 id=\"panics-1\" class=\"section-header\"><a href=\"#panics-1\">Panics</a></h2>",
); );
} }

View file

@ -471,19 +471,35 @@ fn settings(root_path: &str, suffix: &str, themes: &[StylePath]) -> Result<Strin
} }
fn document(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, parent: Option<&clean::Item>) { fn document(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, parent: Option<&clean::Item>) {
document_at_level(w, cx, item, parent, 0)
}
fn document_at_level(
w: &mut Buffer,
cx: &Context<'_>,
item: &clean::Item,
parent: Option<&clean::Item>,
level: u32,
) {
if let Some(ref name) = item.name { if let Some(ref name) = item.name {
info!("Documenting {}", name); info!("Documenting {}", name);
} }
document_item_info(w, cx, item, parent); document_item_info(w, cx, item, parent);
if parent.is_none() { if parent.is_none() {
document_full_collapsible(w, item, cx); document_full_collapsible(w, item, cx, level);
} else { } else {
document_full(w, item, cx); document_full(w, item, cx, level);
} }
} }
/// Render md_text as markdown. /// Render md_text as markdown.
fn render_markdown(w: &mut Buffer, cx: &Context<'_>, md_text: &str, links: Vec<RenderedLink>) { fn render_markdown(
w: &mut Buffer,
cx: &Context<'_>,
md_text: &str,
links: Vec<RenderedLink>,
level: u32,
) {
let mut ids = cx.id_map.borrow_mut(); let mut ids = cx.id_map.borrow_mut();
write!( write!(
w, w,
@ -494,7 +510,8 @@ fn render_markdown(w: &mut Buffer, cx: &Context<'_>, md_text: &str, links: Vec<R
&mut ids, &mut ids,
cx.shared.codes, cx.shared.codes,
cx.shared.edition(), cx.shared.edition(),
&cx.shared.playground &cx.shared.playground,
level
) )
.into_string() .into_string()
) )
@ -531,15 +548,21 @@ fn document_short(
} }
} }
fn document_full_collapsible(w: &mut Buffer, item: &clean::Item, cx: &Context<'_>) { fn document_full_collapsible(w: &mut Buffer, item: &clean::Item, cx: &Context<'_>, level: u32) {
document_full_inner(w, item, cx, true); document_full_inner(w, item, cx, true, level);
} }
fn document_full(w: &mut Buffer, item: &clean::Item, cx: &Context<'_>) { fn document_full(w: &mut Buffer, item: &clean::Item, cx: &Context<'_>, level: u32) {
document_full_inner(w, item, cx, false); document_full_inner(w, item, cx, false, level);
} }
fn document_full_inner(w: &mut Buffer, item: &clean::Item, cx: &Context<'_>, is_collapsible: bool) { fn document_full_inner(
w: &mut Buffer,
item: &clean::Item,
cx: &Context<'_>,
is_collapsible: bool,
level: u32,
) {
if let Some(s) = cx.shared.maybe_collapsed_doc_value(item) { if let Some(s) = cx.shared.maybe_collapsed_doc_value(item) {
debug!("Doc block: =====\n{}\n=====", s); debug!("Doc block: =====\n{}\n=====", s);
if is_collapsible { if is_collapsible {
@ -549,10 +572,10 @@ fn document_full_inner(w: &mut Buffer, item: &clean::Item, cx: &Context<'_>, is_
<span>Expand description</span>\ <span>Expand description</span>\
</summary>", </summary>",
); );
render_markdown(w, cx, &s, item.links(cx)); render_markdown(w, cx, &s, item.links(cx), level);
w.write_str("</details>"); w.write_str("</details>");
} else { } else {
render_markdown(w, cx, &s, item.links(cx)); render_markdown(w, cx, &s, item.links(cx), level);
} }
} }
} }
@ -1321,7 +1344,7 @@ fn render_impl(
// because impls can't have a stability. // because impls can't have a stability.
if item.doc_value().is_some() { if item.doc_value().is_some() {
document_item_info(&mut info_buffer, cx, it, Some(parent)); document_item_info(&mut info_buffer, cx, it, Some(parent));
document_full(&mut doc_buffer, item, cx); document_full(&mut doc_buffer, item, cx, 0);
short_documented = false; short_documented = false;
} else { } else {
// In case the item isn't documented, // In case the item isn't documented,
@ -1339,7 +1362,7 @@ fn render_impl(
} else { } else {
document_item_info(&mut info_buffer, cx, item, Some(parent)); document_item_info(&mut info_buffer, cx, item, Some(parent));
if rendering_params.show_def_docs { if rendering_params.show_def_docs {
document_full(&mut doc_buffer, item, cx); document_full(&mut doc_buffer, item, cx, 3);
short_documented = false; short_documented = false;
} }
} }
@ -1579,7 +1602,8 @@ fn render_impl(
&mut ids, &mut ids,
cx.shared.codes, cx.shared.codes,
cx.shared.edition(), cx.shared.edition(),
&cx.shared.playground &cx.shared.playground,
0
) )
.into_string() .into_string()
); );

View file

@ -16,10 +16,10 @@ use rustc_span::symbol::{kw, sym, Symbol};
use rustc_target::abi::{Layout, Primitive, TagEncoding, Variants}; use rustc_target::abi::{Layout, Primitive, TagEncoding, Variants};
use super::{ use super::{
collect_paths_for_type, document, ensure_trailing_slash, item_ty_to_strs, notable_traits_decl, collect_paths_for_type, document, document_at_level, ensure_trailing_slash, item_ty_to_strs,
render_assoc_item, render_assoc_items, render_attributes_in_code, render_attributes_in_pre, notable_traits_decl, render_assoc_item, render_assoc_items, render_attributes_in_code,
render_impl, render_stability_since_raw, write_srclink, AssocItemLink, Context, render_attributes_in_pre, render_impl, render_stability_since_raw, write_srclink,
ImplRenderingParameters, AssocItemLink, Context, ImplRenderingParameters,
}; };
use crate::clean::{self, GetDefId}; use crate::clean::{self, GetDefId};
use crate::formats::item_type::ItemType; use crate::formats::item_type::ItemType;
@ -626,7 +626,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
let item_type = m.type_(); let item_type = m.type_();
let id = cx.derive_id(format!("{}.{}", item_type, name)); let id = cx.derive_id(format!("{}.{}", item_type, name));
let mut content = Buffer::empty_from(w); let mut content = Buffer::empty_from(w);
document(&mut content, cx, m, Some(t)); document_at_level(&mut content, cx, m, Some(t), 3);
let toggled = !content.is_empty(); let toggled = !content.is_empty();
if toggled { if toggled {
write!(w, "<details class=\"rustdoc-toggle\" open><summary>"); write!(w, "<details class=\"rustdoc-toggle\" open><summary>");

View file

@ -126,7 +126,7 @@ h2 {
h3 { h3 {
font-size: 1.3em; font-size: 1.3em;
} }
h1, h2, h3, h4 { h1, h2, h3, h4, h5, h6 {
font-weight: 500; font-weight: 500;
margin: 20px 0 15px 0; margin: 20px 0 15px 0;
padding-bottom: 6px; padding-bottom: 6px;
@ -179,7 +179,7 @@ div.impl-items > div {
padding-left: 0; padding-left: 0;
} }
h1, h2, h3, h4, h1, h2, h3, h4, h5, h6,
.sidebar, a.source, .search-input, .search-results .result-name, .sidebar, a.source, .search-input, .search-results .result-name,
.content table td:first-child > a, .content table td:first-child > a,
.item-left > a, .item-left > a,
@ -501,21 +501,20 @@ nav.sub {
white-space: pre-wrap; white-space: pre-wrap;
} }
.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5 { .docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5, .docblock h6 {
border-bottom: 1px solid; border-bottom: 1px solid;
} }
.top-doc .docblock h1 { font-size: 1.3em; } .top-doc .docblock h2 { font-size: 1.3em; }
.top-doc .docblock h2 { font-size: 1.15em; } .top-doc .docblock h3 { font-size: 1.15em; }
.top-doc .docblock h3,
.top-doc .docblock h4, .top-doc .docblock h4,
.top-doc .docblock h5 { .top-doc .docblock h5,
.top-doc .docblock h6 {
font-size: 1em; font-size: 1em;
} }
.docblock h1 { font-size: 1em; } .docblock h5 { font-size: 1em; }
.docblock h2 { font-size: 0.95em; } .docblock h6 { font-size: 0.95em; }
.docblock h3, .docblock h4, .docblock h5 { font-size: 0.9em; }
.docblock { .docblock {
margin-left: 24px; margin-left: 24px;

View file

@ -136,7 +136,7 @@ pre, .rustdoc.source .example-wrap {
border-right: 1px solid #ffb44c; border-right: 1px solid #ffb44c;
} }
.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5 { .docblock h2, .docblock h3, .docblock h4, .docblock h5, .docblock h6 {
border-bottom-color: #5c6773; border-bottom-color: #5c6773;
} }

View file

@ -93,7 +93,7 @@ pre, .rustdoc.source .example-wrap {
background-color: #0a042f !important; background-color: #0a042f !important;
} }
.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5 { .docblock h2, .docblock h3, .docblock h4, .docblock h5, .docblock h6 {
border-bottom-color: #DDD; border-bottom-color: #DDD;
} }

View file

@ -93,7 +93,7 @@ pre, .rustdoc.source .example-wrap {
background-color: #f6fdb0 !important; background-color: #f6fdb0 !important;
} }
.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5 { .docblock h2, .docblock h3, .docblock h4, .docblock h5, .docblock h6 {
border-bottom-color: #ddd; border-bottom-color: #ddd;
} }

View file

@ -70,7 +70,7 @@ crate fn render<P: AsRef<Path>>(
let text = if !options.markdown_no_toc { let text = if !options.markdown_no_toc {
MarkdownWithToc(text, &mut ids, error_codes, edition, &playground).into_string() MarkdownWithToc(text, &mut ids, error_codes, edition, &playground).into_string()
} else { } else {
Markdown(text, &[], &mut ids, error_codes, edition, &playground).into_string() Markdown(text, &[], &mut ids, error_codes, edition, &playground, 0).into_string()
}; };
let err = write!( let err = write!(

View file

@ -6,5 +6,5 @@
extern crate external_cross; extern crate external_cross;
// @has host/struct.NeedMoreDocs.html // @has host/struct.NeedMoreDocs.html
// @has - '//h1' 'Cross-crate imported docs' // @has - '//h2' 'Cross-crate imported docs'
pub use external_cross::NeedMoreDocs; pub use external_cross::NeedMoreDocs;

View file

@ -1,6 +1,6 @@
// @has external_doc/struct.IncludeStrDocs.html // @has external_doc/struct.IncludeStrDocs.html
// @has - '//h1' 'External Docs' // @has - '//h2' 'External Docs'
// @has - '//h2' 'Inline Docs' // @has - '//h3' 'Inline Docs'
#[doc = include_str!("auxiliary/external-doc.md")] #[doc = include_str!("auxiliary/external-doc.md")]
/// ## Inline Docs /// ## Inline Docs
pub struct IncludeStrDocs; pub struct IncludeStrDocs;
@ -8,7 +8,7 @@ pub struct IncludeStrDocs;
macro_rules! dir { () => { "auxiliary" } } macro_rules! dir { () => { "auxiliary" } }
// @has external_doc/struct.EagerExpansion.html // @has external_doc/struct.EagerExpansion.html
// @has - '//h1' 'External Docs' // @has - '//h2' 'External Docs'
#[doc = include_str!(concat!(dir!(), "/external-doc.md"))] #[doc = include_str!(concat!(dir!(), "/external-doc.md"))]
/// ## Inline Docs /// ## Inline Docs
pub struct EagerExpansion; pub struct EagerExpansion;

View file

@ -1,5 +1,5 @@
// @has issue_42760/struct.NonGen.html // @has issue_42760/struct.NonGen.html
// @has - '//h1' 'Example' // @has - '//h2' 'Example'
/// Item docs. /// Item docs.
/// ///

View file

@ -2,7 +2,7 @@
// @has foo/index.html '//*[@class="item-right docblock-short"]/p' 'fooo' // @has foo/index.html '//*[@class="item-right docblock-short"]/p' 'fooo'
// @!has foo/index.html '//*[@class="item-right docblock-short"]/p/h1' 'fooo' // @!has foo/index.html '//*[@class="item-right docblock-short"]/p/h1' 'fooo'
// @has foo/fn.foo.html '//h1[@id="fooo"]/a[@href="#fooo"]' 'fooo' // @has foo/fn.foo.html '//h2[@id="fooo"]/a[@href="#fooo"]' 'fooo'
/// # fooo /// # fooo
/// ///
@ -11,7 +11,7 @@ pub fn foo() {}
// @has foo/index.html '//*[@class="item-right docblock-short"]/p' 'mooood' // @has foo/index.html '//*[@class="item-right docblock-short"]/p' 'mooood'
// @!has foo/index.html '//*[@class="item-right docblock-short"]/p/h2' 'mooood' // @!has foo/index.html '//*[@class="item-right docblock-short"]/p/h2' 'mooood'
// @has foo/foo/index.html '//h2[@id="mooood"]/a[@href="#mooood"]' 'mooood' // @has foo/foo/index.html '//h3[@id="mooood"]/a[@href="#mooood"]' 'mooood'
/// ## mooood /// ## mooood
/// ///

View file

@ -21,7 +21,7 @@
//! ``` //! ```
// @has "foo/index.html" "//p" "This is the “start” of the document! Howd you know that “its” the start?" // @has "foo/index.html" "//p" "This is the “start” of the document! Howd you know that “its” the start?"
// @has "foo/index.html" "//h1" "Header with “smart punct”" // @has "foo/index.html" "//h2" "Header with “smart punct”"
// @has "foo/index.html" '//a[@href="https://www.rust-lang.org"]' "link with “smart punct yessiree!" // @has "foo/index.html" '//a[@href="https://www.rust-lang.org"]' "link with “smart punct yessiree!"
// @has "foo/index.html" '//code' "this inline code -- it shouldn't have \"smart punct\"" // @has "foo/index.html" '//code' "this inline code -- it shouldn't have \"smart punct\""
// @has "foo/index.html" '//pre' "let x = \"don't smart-punct me -- please!\";" // @has "foo/index.html" '//pre' "let x = \"don't smart-punct me -- please!\";"

View file

@ -125,7 +125,8 @@ impl Formatter for HTMLFormatter {
&mut id_map, &mut id_map,
ErrorCodes::Yes, ErrorCodes::Yes,
DEFAULT_EDITION, DEFAULT_EDITION,
&Some(playground) &Some(playground),
0
) )
.into_string() .into_string()
)? )?

View file

@ -49,7 +49,7 @@ fn check_error_code_explanation(
} else if s.contains("compile-fail") { } else if s.contains("compile-fail") {
invalid_compile_fail_format = true; invalid_compile_fail_format = true;
} }
} else if s.starts_with("#### Note: this error code is no longer emitted by the compiler") { } else if s.starts_with("### Note: this error code is no longer emitted by the compiler") {
if !found_error_code { if !found_error_code {
error_codes.get_mut(&err_code).map(|x| x.has_test = true); error_codes.get_mut(&err_code).map(|x| x.has_test = true);
found_error_code = true; found_error_code = true;
@ -64,7 +64,7 @@ fn check_if_error_code_is_test_in_explanation(f: &str, err_code: &str) -> bool {
for line in f.lines() { for line in f.lines() {
let s = line.trim(); let s = line.trim();
if s.starts_with("#### Note: this error code is no longer emitted by the compiler") { if s.starts_with("### Note: this error code is no longer emitted by the compiler") {
return true; return true;
} }
if s.starts_with("```") { if s.starts_with("```") {