diff options
| author | Michael Howell <michael@notriddle.com> | 2024-09-10 22:03:54 -0700 |
|---|---|---|
| committer | Michael Howell <michael@notriddle.com> | 2024-09-23 09:21:39 -0700 |
| commit | cc3ffe4c912ff00baeec1f52bb16389136a23a27 (patch) | |
| tree | 24599ad802b54140eea6ef91d9383f23ef9c4919 | |
| parent | e31a719cceb693a00f558eaa448152246b28b31b (diff) | |
| download | rust-cc3ffe4c912ff00baeec1f52bb16389136a23a27.tar.gz rust-cc3ffe4c912ff00baeec1f52bb16389136a23a27.zip | |
Tweak breadcrumbs list
| -rw-r--r-- | src/librustdoc/html/static/css/rustdoc.css | 5 | ||||
| -rw-r--r-- | src/librustdoc/html/static/js/main.js | 11 | ||||
| -rw-r--r-- | src/librustdoc/html/templates/print_item.html | 11 | ||||
| -rw-r--r-- | tests/rustdoc-gui/search-result-go-to-first.goml | 2 | ||||
| -rw-r--r-- | tests/rustdoc-gui/toggle-click-deadspace.goml | 2 | ||||
| -rw-r--r-- | tests/rustdoc/empty-mod-private.rs | 6 | ||||
| -rw-r--r-- | tests/rustdoc/empty-mod-public.rs | 6 | ||||
| -rw-r--r-- | tests/rustdoc/inline_cross/renamed-via-module.rs | 8 | ||||
| -rw-r--r-- | tests/rustdoc/titles.rs | 22 |
9 files changed, 39 insertions, 34 deletions
diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 2dfe5107210..0237677f9d4 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -194,6 +194,11 @@ h1, h2, h3, h4 { display: flex; align-items: end; } +.rustdoc-breadcrumbs a { + padding: 4px 0; + margin: -4px 0; + z-index: 1; +} /* The only headings that get underlines are: Markdown-generated headings within the top-doc Rustdoc-generated h2 section headings (e.g. "Implementations", "Required Methods", etc) diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index 3e8c903afcb..2fb686effc1 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -1,6 +1,6 @@ // Local js definitions: /* global addClass, getSettingValue, hasClass, searchState, updateLocalStorage */ -/* global onEach, onEachLazy, removeClass, getVar */ +/* global onEachLazy, removeClass, getVar */ "use strict"; @@ -1826,14 +1826,11 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm return; } but.onclick = () => { - const parent = but.parentElement; const path = []; - - onEach(parent.childNodes, child => { - if (child.tagName === "A") { - path.push(child.textContent); - } + onEachLazy(document.querySelectorAll(".rustdoc-breadcrumbs a"), a => { + path.push(a.textContent); }); + path.push(document.querySelector("title").textContent.split(" ")[0]); copyContentToClipboard(path.join("::")); copyButtonAnimation(but); diff --git a/src/librustdoc/html/templates/print_item.html b/src/librustdoc/html/templates/print_item.html index 2c9f8dbddf0..32ded1fbe42 100644 --- a/src/librustdoc/html/templates/print_item.html +++ b/src/librustdoc/html/templates/print_item.html @@ -1,8 +1,11 @@ <div class="main-heading"> {# #} {% if !path_components.is_empty() %} <span class="rustdoc-breadcrumbs"> - {% for component in path_components %} - <a href="{{component.path|safe}}index.html">{{component.name}}</a>::<wbr> + {% for (i, component) in path_components.iter().enumerate() %} + {% if i != 0 %} + ::<wbr> + {% endif %} + <a href="{{component.path|safe}}index.html">{{component.name}}</a> {% endfor %} </span> {% endif %} @@ -15,7 +18,7 @@ Copy item path {# #} </button> {# #} </h1> {# #} - <rustdoc-toolbar></rustdoc-toolbar> + <rustdoc-toolbar></rustdoc-toolbar> {# #} <span class="sub-heading"> {% if !stability_since_raw.is_empty() %} {{ stability_since_raw|safe +}} @@ -26,5 +29,5 @@ <a class="src" href="{{href|safe}}">source</a> {#+ #} {% else %} {% endmatch %} - </span> + </span> {# #} </div> {# #} diff --git a/tests/rustdoc-gui/search-result-go-to-first.goml b/tests/rustdoc-gui/search-result-go-to-first.goml index 1e3850969e3..136213c517e 100644 --- a/tests/rustdoc-gui/search-result-go-to-first.goml +++ b/tests/rustdoc-gui/search-result-go-to-first.goml @@ -16,5 +16,5 @@ assert-css: ("#main-content", {"display": "none"}) // Now we can check that the feature is working as expected! go-to: "file://" + |DOC_PATH| + "/test_docs/index.html?search=struct%3AFoo&go_to_first=true" // Waiting for the page to load... -wait-for-text: (".main-heading .rustdoc-breadcrumbs", "test_docs::") +wait-for-text: (".main-heading .rustdoc-breadcrumbs", "test_docs") wait-for-text: (".main-heading h1", "Struct FooCopy item path") diff --git a/tests/rustdoc-gui/toggle-click-deadspace.goml b/tests/rustdoc-gui/toggle-click-deadspace.goml index cbb0a2d5eb0..caca1b61493 100644 --- a/tests/rustdoc-gui/toggle-click-deadspace.goml +++ b/tests/rustdoc-gui/toggle-click-deadspace.goml @@ -12,5 +12,5 @@ assert-attribute-false: (".impl-items .toggle", {"open": ""}) // Click the "Trait" part of "impl Trait" and verify it navigates. click: "#impl-Trait-for-Foo h3 a:first-of-type" -assert-text: (".main-heading .rustdoc-breadcrumbs", "lib2::") +assert-text: (".main-heading .rustdoc-breadcrumbs", "lib2") assert-text: (".main-heading h1", "Trait TraitCopy item path") diff --git a/tests/rustdoc/empty-mod-private.rs b/tests/rustdoc/empty-mod-private.rs index 2b446deda33..5a8638cd5f5 100644 --- a/tests/rustdoc/empty-mod-private.rs +++ b/tests/rustdoc/empty-mod-private.rs @@ -3,17 +3,17 @@ //@ has 'empty_mod_private/index.html' '//a[@href="foo/index.html"]' 'foo' //@ hasraw 'empty_mod_private/sidebar-items.js' 'foo' //@ matches 'empty_mod_private/foo/index.html' '//h1' 'Module foo' -//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'empty_mod_private::' +//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'empty_mod_private' mod foo {} //@ has 'empty_mod_private/index.html' '//a[@href="bar/index.html"]' 'bar' //@ hasraw 'empty_mod_private/sidebar-items.js' 'bar' //@ matches 'empty_mod_private/bar/index.html' '//h1' 'Module bar' -//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'empty_mod_private::' +//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'empty_mod_private' mod bar { //@ has 'empty_mod_private/bar/index.html' '//a[@href="baz/index.html"]' 'baz' //@ hasraw 'empty_mod_private/bar/sidebar-items.js' 'baz' //@ matches 'empty_mod_private/bar/baz/index.html' '//h1' 'Module baz' - //@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'empty_mod_private::bar::' + //@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'empty_mod_private::bar' mod baz {} } diff --git a/tests/rustdoc/empty-mod-public.rs b/tests/rustdoc/empty-mod-public.rs index 97f41a807c6..f06ac69f3ed 100644 --- a/tests/rustdoc/empty-mod-public.rs +++ b/tests/rustdoc/empty-mod-public.rs @@ -1,17 +1,17 @@ //@ has 'empty_mod_public/index.html' '//a[@href="foo/index.html"]' 'foo' //@ hasraw 'empty_mod_public/sidebar-items.js' 'foo' //@ matches 'empty_mod_public/foo/index.html' '//h1' 'Module foo' -//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'empty_mod_public::' +//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'empty_mod_public' pub mod foo {} //@ has 'empty_mod_public/index.html' '//a[@href="bar/index.html"]' 'bar' //@ hasraw 'empty_mod_public/sidebar-items.js' 'bar' //@ matches 'empty_mod_public/bar/index.html' '//h1' 'Module bar' -//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'empty_mod_public::' +//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'empty_mod_public' pub mod bar { //@ has 'empty_mod_public/bar/index.html' '//a[@href="baz/index.html"]' 'baz' //@ hasraw 'empty_mod_public/bar/sidebar-items.js' 'baz' //@ matches 'empty_mod_public/bar/baz/index.html' '//h1' 'Module baz' - //@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'empty_mod_public::bar::' + //@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'empty_mod_public::bar' pub mod baz {} } diff --git a/tests/rustdoc/inline_cross/renamed-via-module.rs b/tests/rustdoc/inline_cross/renamed-via-module.rs index a5af9b96f6c..8bcdd9f7a39 100644 --- a/tests/rustdoc/inline_cross/renamed-via-module.rs +++ b/tests/rustdoc/inline_cross/renamed-via-module.rs @@ -11,18 +11,18 @@ extern crate foo; //@ has - '//a/[@href="struct.StepBy.html"]' "StepBy" //@ has foo/iter/struct.DeprecatedStepBy.html //@ has - '//h1' "Struct DeprecatedStepBy" -//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::iter::' +//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::iter' //@ has foo/iter/struct.StepBy.html //@ has - '//h1' "Struct StepBy" -//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::iter::' +//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::iter' //@ has bar/iter/index.html //@ has - '//a/[@href="struct.DeprecatedStepBy.html"]' "DeprecatedStepBy" //@ has - '//a/[@href="struct.StepBy.html"]' "StepBy" //@ has bar/iter/struct.DeprecatedStepBy.html //@ has - '//h1' "Struct DeprecatedStepBy" -//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'bar::iter::' +//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'bar::iter' //@ has bar/iter/struct.StepBy.html //@ has - '//h1' "Struct StepBy" -//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'bar::iter::' +//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'bar::iter' pub use foo::iter; diff --git a/tests/rustdoc/titles.rs b/tests/rustdoc/titles.rs index 6113878a03f..922068adc59 100644 --- a/tests/rustdoc/titles.rs +++ b/tests/rustdoc/titles.rs @@ -6,7 +6,7 @@ //@ count 'foo/index.html' '//h2[@class="location"]' 0 //@ matches 'foo/foo_mod/index.html' '//h1' 'Module foo_mod' -//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::' +//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo' //@ matches - '//h2[@class="location"]' 'Module foo_mod' pub mod foo_mod { pub struct __Thing {} @@ -14,36 +14,36 @@ pub mod foo_mod { extern "C" { //@ matches 'foo/fn.foo_ffn.html' '//h1' 'Function foo_ffn' - //@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::' + //@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo' pub fn foo_ffn(); } //@ matches 'foo/fn.foo_fn.html' '//h1' 'Function foo_fn' -//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::' +//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo' pub fn foo_fn() {} //@ matches 'foo/trait.FooTrait.html' '//h1' 'Trait FooTrait' -//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::' +//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo' //@ matches - '//h2[@class="location"]' 'FooTrait' pub trait FooTrait {} //@ matches 'foo/struct.FooStruct.html' '//h1' 'Struct FooStruct' -//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::' +//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo' //@ matches - '//h2[@class="location"]' 'FooStruct' pub struct FooStruct; //@ matches 'foo/enum.FooEnum.html' '//h1' 'Enum FooEnum' -//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::' +//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo' //@ matches - '//h2[@class="location"]' 'FooEnum' pub enum FooEnum {} //@ matches 'foo/type.FooType.html' '//h1' 'Type Alias FooType' -//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::' +//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo' //@ matches - '//h2[@class="location"]' 'FooType' pub type FooType = FooStruct; //@ matches 'foo/macro.foo_macro.html' '//h1' 'Macro foo_macro' -//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::' +//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo' #[macro_export] macro_rules! foo_macro { () => {}; @@ -55,15 +55,15 @@ macro_rules! foo_macro { mod bool {} //@ matches 'foo/static.FOO_STATIC.html' '//h1' 'Static FOO_STATIC' -//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::' +//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo' pub static FOO_STATIC: FooStruct = FooStruct; extern "C" { //@ matches 'foo/static.FOO_FSTATIC.html' '//h1' 'Static FOO_FSTATIC' - //@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::' + //@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo' pub static FOO_FSTATIC: FooStruct; } //@ matches 'foo/constant.FOO_CONSTANT.html' '//h1' 'Constant FOO_CONSTANT' -//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo::' +//@ matches - '//*[@class="rustdoc-breadcrumbs"]' 'foo' pub const FOO_CONSTANT: FooStruct = FooStruct; |
