rustdoc: clean up DOM by removing .dockblock-short p

On https://doc.rust-lang.org/nightly/std/ this reduces the number out of
`document.querySelectorAll("*").length` from 1278 to 1103.
This commit is contained in:
Michael Howell 2022-09-13 14:22:38 -07:00
parent 1ce51982b8
commit 11a52dc61a
5 changed files with 26 additions and 38 deletions

View File

@ -1119,7 +1119,11 @@ impl MarkdownSummaryLine<'_> {
let mut s = String::new(); let mut s = String::new();
html::push_html(&mut s, LinkReplacer::new(SummaryLine::new(p), links)); let without_paragraphs = LinkReplacer::new(SummaryLine::new(p), links).filter(|event| {
!matches!(event, Event::Start(Tag::Paragraph) | Event::End(Tag::Paragraph))
});
html::push_html(&mut s, without_paragraphs);
s s
} }

View File

@ -609,16 +609,12 @@ h2.location a {
.docblock-short { .docblock-short {
overflow-wrap: break-word; overflow-wrap: break-word;
overflow-wrap: anywhere; overflow-wrap: anywhere;
}
.docblock-short p {
display: inline;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
margin: 0;
} }
/* Wrap non-pre code blocks (`text`) but not (```text```). */ /* Wrap non-pre code blocks (`text`) but not (```text```). */
.docblock > :not(pre) > code, .docblock > :not(pre) > code,
.docblock-short > :not(pre) > code { .docblock-short > code {
white-space: pre-wrap; white-space: pre-wrap;
} }

View File

@ -31,15 +31,9 @@ compare-elements-position: (
) )
// Ensure no wrap // Ensure no wrap
compare-elements-position-near: (
"//*[@class='item-left module-item']//a[text()='replaced_function']",
"//*[@class='item-right docblock-short']//p[text()='a thing with a label']",
{"y": 2},
)
// compare parent elements
compare-elements-position: ( compare-elements-position: (
"//*[@class='item-left module-item']//a[text()='replaced_function']/..", "//*[@class='item-left module-item']//a[text()='replaced_function']/..",
"//*[@class='item-right docblock-short']//p[text()='a thing with a label']/..", "//*[@class='item-right docblock-short'][text()='a thing with a label']",
("y"), ("y"),
) )
@ -60,19 +54,13 @@ compare-elements-position: (
) )
// Ensure wrap // Ensure wrap
compare-elements-position-near-false: (
"//*[@class='item-left module-item']//a[text()='replaced_function']",
"//*[@class='item-right docblock-short']//p[text()='a thing with a label']",
{"y": 12},
)
// compare parent elements
compare-elements-position-false: ( compare-elements-position-false: (
"//*[@class='item-left module-item']//a[text()='replaced_function']/..", "//*[@class='item-left module-item']//a[text()='replaced_function']/..",
"//*[@class='item-right docblock-short']//p[text()='a thing with a label']/..", "//*[@class='item-right docblock-short'][text()='a thing with a label']",
("y"), ("y"),
) )
compare-elements-position-false: ( compare-elements-position-false: (
".item-left .stab.deprecated", ".item-left .stab.deprecated",
"//*[@class='item-right docblock-short']//p[text()='a thing with a label']", "//*[@class='item-right docblock-short'][text()='a thing with a label']",
("y"), ("y"),
) )

View File

@ -1,7 +1,7 @@
#![crate_name = "foo"] #![crate_name = "foo"]
// @has foo/index.html '//*[@class="item-right docblock-short"]/p' 'fooo' // @has foo/index.html '//*[@class="item-right docblock-short"]' 'fooo'
// @!has foo/index.html '//*[@class="item-right docblock-short"]/p/h1' 'fooo' // @!has foo/index.html '//*[@class="item-right docblock-short"]/h1' 'fooo'
// @has foo/fn.foo.html '//h2[@id="fooo"]/a[@href="#fooo"]' 'fooo' // @has foo/fn.foo.html '//h2[@id="fooo"]/a[@href="#fooo"]' 'fooo'
/// # fooo /// # fooo
@ -9,8 +9,8 @@
/// foo /// foo
pub fn foo() {} pub fn foo() {}
// @has foo/index.html '//*[@class="item-right docblock-short"]/p' 'mooood' // @has foo/index.html '//*[@class="item-right docblock-short"]' 'mooood'
// @!has foo/index.html '//*[@class="item-right docblock-short"]/p/h2' 'mooood' // @!has foo/index.html '//*[@class="item-right docblock-short"]/h2' 'mooood'
// @has foo/foo/index.html '//h3[@id="mooood"]/a[@href="#mooood"]' 'mooood' // @has foo/foo/index.html '//h3[@id="mooood"]/a[@href="#mooood"]' 'mooood'
/// ## mooood /// ## mooood
@ -18,7 +18,7 @@ pub fn foo() {}
/// foo mod /// foo mod
pub mod foo {} pub mod foo {}
// @has foo/index.html '//*[@class="item-right docblock-short"]/p/a[@href=\ // @has foo/index.html '//*[@class="item-right docblock-short"]/a[@href=\
// "https://nougat.world"]/code' 'nougat' // "https://nougat.world"]/code' 'nougat'
/// [`nougat`](https://nougat.world) /// [`nougat`](https://nougat.world)

View File

@ -21,26 +21,26 @@ pub trait Trait {
pub struct Struct; pub struct Struct;
impl Trait for Struct { impl Trait for Struct {
// @has trait_impl/struct.Struct.html '//*[@id="method.a"]/../../div[@class="docblock"]/p' 'Some long docs' // @has trait_impl/struct.Struct.html '//*[@id="method.a"]/../../div[@class="docblock"]' 'Some long docs'
// @!has - '//*[@id="method.a"]/../../div[@class="docblock"]/p' 'link will be added' // @!has - '//*[@id="method.a"]/../../div[@class="docblock"]' 'link will be added'
// @has - '//*[@id="method.a"]/../../div[@class="docblock"]/p/a' 'Read more' // @has - '//*[@id="method.a"]/../../div[@class="docblock"]/a' 'Read more'
// @has - '//*[@id="method.a"]/../../div[@class="docblock"]/p/a/@href' 'trait.Trait.html#tymethod.a' // @has - '//*[@id="method.a"]/../../div[@class="docblock"]/a/@href' 'trait.Trait.html#tymethod.a'
fn a() {} fn a() {}
// @has - '//*[@id="method.b"]/../../div[@class="docblock"]/p' 'These docs contain' // @has - '//*[@id="method.b"]/../../div[@class="docblock"]' 'These docs contain'
// @has - '//*[@id="method.b"]/../../div[@class="docblock"]/p/a' 'reference link' // @has - '//*[@id="method.b"]/../../div[@class="docblock"]/a' 'reference link'
// @has - '//*[@id="method.b"]/../../div[@class="docblock"]/p/a/@href' 'https://example.com' // @has - '//*[@id="method.b"]/../../div[@class="docblock"]/a/@href' 'https://example.com'
// @has - '//*[@id="method.b"]/../../div[@class="docblock"]/p/a' 'Read more' // @has - '//*[@id="method.b"]/../../div[@class="docblock"]/a' 'Read more'
// @has - '//*[@id="method.b"]/../../div[@class="docblock"]/p/a/@href' 'trait.Trait.html#tymethod.b' // @has - '//*[@id="method.b"]/../../div[@class="docblock"]/a/@href' 'trait.Trait.html#tymethod.b'
fn b() {} fn b() {}
// @!has - '//*[@id="method.c"]/../../div[@class="docblock"]/p' 'code block' // @!has - '//*[@id="method.c"]/../../div[@class="docblock"]' 'code block'
// @has - '//*[@id="method.c"]/../../div[@class="docblock"]/a' 'Read more' // @has - '//*[@id="method.c"]/../../div[@class="docblock"]/a' 'Read more'
// @has - '//*[@id="method.c"]/../../div[@class="docblock"]/a/@href' 'trait.Trait.html#tymethod.c' // @has - '//*[@id="method.c"]/../../div[@class="docblock"]/a/@href' 'trait.Trait.html#tymethod.c'
fn c() {} fn c() {}
// @has - '//*[@id="method.d"]/../../div[@class="docblock"]/p' 'Escaped formatting a*b*c* works' // @has - '//*[@id="method.d"]/../../div[@class="docblock"]' 'Escaped formatting a*b*c* works'
// @!has - '//*[@id="method.d"]/../../div[@class="docblock"]/p/em' '' // @!has - '//*[@id="method.d"]/../../div[@class="docblock"]/em' ''
fn d() {} fn d() {}
// @has - '//*[@id="impl-Trait-for-Struct"]/h3//a/@href' 'trait.Trait.html' // @has - '//*[@id="impl-Trait-for-Struct"]/h3//a/@href' 'trait.Trait.html'