diff options
| author | Michael Howell <michael@notriddle.com> | 2024-02-06 10:22:24 -0700 |
|---|---|---|
| committer | Michael Howell <michael@notriddle.com> | 2024-08-20 16:27:42 -0700 |
| commit | 1aebff96ade6518038e0f7522d3304bd0f9bf891 (patch) | |
| tree | 5ddd0be347cd48d3a4797c0d7e7481c89c46544b /tests/rustdoc | |
| parent | 5aea14073eee9e403c3bb857490cd6aa4a395531 (diff) | |
| download | rust-1aebff96ade6518038e0f7522d3304bd0f9bf891.tar.gz rust-1aebff96ade6518038e0f7522d3304bd0f9bf891.zip | |
Add Top TOC support to rustdoc
This commit adds the headers for the top level documentation to rustdoc's existing table of contents, along with associated items. It only show two levels of headers. Going further would require the sidebar to be wider, and that seems unnecessary (the crates that have manually-built TOCs usually don't need deeply nested headers).
Diffstat (limited to 'tests/rustdoc')
| -rw-r--r-- | tests/rustdoc/sidebar/sidebar-all-page.rs (renamed from tests/rustdoc/sidebar-all-page.rs) | 0 | ||||
| -rw-r--r-- | tests/rustdoc/sidebar/sidebar-items.rs (renamed from tests/rustdoc/sidebar-items.rs) | 0 | ||||
| -rw-r--r-- | tests/rustdoc/sidebar/sidebar-link-generation.rs (renamed from tests/rustdoc/sidebar-link-generation.rs) | 0 | ||||
| -rw-r--r-- | tests/rustdoc/sidebar/sidebar-links-to-foreign-impl.rs (renamed from tests/rustdoc/sidebar-links-to-foreign-impl.rs) | 0 | ||||
| -rw-r--r-- | tests/rustdoc/sidebar/top-toc-html.rs | 19 | ||||
| -rw-r--r-- | tests/rustdoc/sidebar/top-toc-idmap.rs | 44 |
6 files changed, 63 insertions, 0 deletions
diff --git a/tests/rustdoc/sidebar-all-page.rs b/tests/rustdoc/sidebar/sidebar-all-page.rs index 1f97a414048..1f97a414048 100644 --- a/tests/rustdoc/sidebar-all-page.rs +++ b/tests/rustdoc/sidebar/sidebar-all-page.rs diff --git a/tests/rustdoc/sidebar-items.rs b/tests/rustdoc/sidebar/sidebar-items.rs index f3812143a7d..f3812143a7d 100644 --- a/tests/rustdoc/sidebar-items.rs +++ b/tests/rustdoc/sidebar/sidebar-items.rs diff --git a/tests/rustdoc/sidebar-link-generation.rs b/tests/rustdoc/sidebar/sidebar-link-generation.rs index ee868ec75d3..ee868ec75d3 100644 --- a/tests/rustdoc/sidebar-link-generation.rs +++ b/tests/rustdoc/sidebar/sidebar-link-generation.rs diff --git a/tests/rustdoc/sidebar-links-to-foreign-impl.rs b/tests/rustdoc/sidebar/sidebar-links-to-foreign-impl.rs index 7c039eeb39f..7c039eeb39f 100644 --- a/tests/rustdoc/sidebar-links-to-foreign-impl.rs +++ b/tests/rustdoc/sidebar/sidebar-links-to-foreign-impl.rs diff --git a/tests/rustdoc/sidebar/top-toc-html.rs b/tests/rustdoc/sidebar/top-toc-html.rs new file mode 100644 index 00000000000..6fc84c1964c --- /dev/null +++ b/tests/rustdoc/sidebar/top-toc-html.rs @@ -0,0 +1,19 @@ +// ignore-tidy-linelength + +#![crate_name = "foo"] +#![feature(lazy_type_alias)] +#![allow(incomplete_features)] + +//! # Basic [link](https://example.com) and *emphasis* +//! +//! This test case covers TOC entries with rich text inside. +//! Rustdoc normally supports headers with links, but for the +//! TOC, that would break the layout. +//! +//! For consistency, emphasis is also filtered out. + +// @has foo/index.html +// User header +// @has - '//section[@id="TOC"]/ul[@class="block top-toc"]/li/a[@href="#basic-link-and-emphasis"]' 'Basic link and emphasis' +// @count - '//section[@id="TOC"]/ul[@class="block top-toc"]/li/a[@href="#basic-link-and-emphasis"]/em' 0 +// @count - '//section[@id="TOC"]/ul[@class="block top-toc"]/li/a[@href="#basic-link-and-emphasis"]/a' 0 diff --git a/tests/rustdoc/sidebar/top-toc-idmap.rs b/tests/rustdoc/sidebar/top-toc-idmap.rs new file mode 100644 index 00000000000..ccfc7336e9f --- /dev/null +++ b/tests/rustdoc/sidebar/top-toc-idmap.rs @@ -0,0 +1,44 @@ +#![crate_name = "foo"] +#![feature(lazy_type_alias)] +#![allow(incomplete_features)] + +//! # Structs +//! +//! This header has the same name as a built-in header, +//! and we need to make sure they're disambiguated with +//! suffixes. +//! +//! Module-like headers get derived from the internal ID map, +//! so the *internal* one gets a suffix here. To make sure it +//! works right, the one in the `top-toc` needs to match the one +//! in the `top-doc`, and the one that's not in the `top-doc` +//! needs to match the one that isn't in the `top-toc`. + +// @has foo/index.html +// User header +// @has - '//section[@id="TOC"]/ul[@class="block top-toc"]/li/a[@href="#structs"]' 'Structs' +// @has - '//details[@class="toggle top-doc"]/div[@class="docblock"]/h2[@id="structs"]' 'Structs' +// Built-in header +// @has - '//section[@id="TOC"]/ul[@class="block"]/li/a[@href="#structs-1"]' 'Structs' +// @has - '//section[@id="main-content"]/h2[@id="structs-1"]' 'Structs' + +/// # Fields +/// ## Fields +/// ### Fields +/// +/// The difference between struct-like headers and module-like headers +/// is strange, but not actually a problem as long as we're consistent. + +// @has foo/struct.MyStruct.html +// User header +// @has - '//section[@id="TOC"]/ul[@class="block top-toc"]/li/a[@href="#fields-1"]' 'Fields' +// @has - '//details[@class="toggle top-doc"]/div[@class="docblock"]/h2[@id="fields-1"]' 'Fields' +// Only one level of nesting +// @count - '//section[@id="TOC"]/ul[@class="block top-toc"]//a' 2 +// Built-in header +// @has - '//section[@id="TOC"]/h3/a[@href="#fields"]' 'Fields' +// @has - '//section[@id="main-content"]/h2[@id="fields"]' 'Fields' + +pub struct MyStruct { + pub fields: i32, +} |
