]> git.lizzy.rs Git - rust.git/commitdiff
rustdoc: clean up DOM by removing `.dockblock-short p`
authorMichael Howell <michael@notriddle.com>
Tue, 13 Sep 2022 21:22:38 +0000 (14:22 -0700)
committerMichael Howell <michael@notriddle.com>
Tue, 13 Sep 2022 23:03:11 +0000 (16:03 -0700)
On https://doc.rust-lang.org/nightly/std/ this reduces the number out of
`document.querySelectorAll("*").length` from 1278 to 1103.

src/librustdoc/html/markdown.rs
src/librustdoc/html/static/css/rustdoc.css
src/test/rustdoc-gui/label-next-to-symbol.goml
src/test/rustdoc/short-docblock.rs
src/test/rustdoc/trait-impl.rs

index ec2e129c364e80e25a4885049e23c102eb2671ec..43d07d4a53337ae6100fdfb9c7ac53b745bb810e 100644 (file)
@@ -1119,7 +1119,11 @@ pub(crate) fn into_string(self) -> String {
 
         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
     }
index 011c559b34bdf03c3a90796d41a29e532d928231..14f27eb6fa8a49c1b009368da14cc5e84bc4d54f 100644 (file)
@@ -609,16 +609,12 @@ h2.location a {
 .docblock-short {
        overflow-wrap: break-word;
        overflow-wrap: anywhere;
-}
-.docblock-short p {
-       display: inline;
        overflow: hidden;
        text-overflow: ellipsis;
-       margin: 0;
 }
 /* Wrap non-pre code blocks (`text`) but not (```text```). */
 .docblock > :not(pre) > code,
-.docblock-short > :not(pre) > code {
+.docblock-short > code {
        white-space: pre-wrap;
 }
 
index f9081189a86005182258302d7bab9481c92c2048..4b4cea2621fff7deeecd2087c70bec097ff0c281 100644 (file)
@@ -31,15 +31,9 @@ compare-elements-position: (
 )
 
 // 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: (
     "//*[@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"),
 )
 
@@ -60,19 +54,13 @@ compare-elements-position: (
 )
 
 // 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: (
     "//*[@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"),
 )
 compare-elements-position-false: (
     ".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"),
 )
index 17c44eab091a6fc79cde810baff664ff5ff4f45f..1a8a689be1d1e2090f3b47c08e8a79dd593cc9fc 100644 (file)
@@ -1,7 +1,7 @@
 #![crate_name = "foo"]
 
-// @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"]' 'fooo'
+// @!has foo/index.html '//*[@class="item-right docblock-short"]/h1' 'fooo'
 // @has foo/fn.foo.html '//h2[@id="fooo"]/a[@href="#fooo"]' 'fooo'
 
 /// # fooo
@@ -9,8 +9,8 @@
 /// foo
 pub fn foo() {}
 
-// @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"]' 'mooood'
+// @!has foo/index.html '//*[@class="item-right docblock-short"]/h2' 'mooood'
 // @has foo/foo/index.html '//h3[@id="mooood"]/a[@href="#mooood"]' 'mooood'
 
 /// ## mooood
@@ -18,7 +18,7 @@ pub fn foo() {}
 /// foo mod
 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'
 
 /// [`nougat`](https://nougat.world)
index 4d5173f6024c774e167a88a348408c3795ab9f7e..195cdf009b9937f37d355f15702347a69942fe7b 100644 (file)
@@ -21,26 +21,26 @@ pub trait Trait {
 pub struct Struct;
 
 impl Trait for Struct {
-    // @has trait_impl/struct.Struct.html '//*[@id="method.a"]/../../div[@class="docblock"]/p' 'Some long docs'
-    // @!has - '//*[@id="method.a"]/../../div[@class="docblock"]/p' 'link will be added'
-    // @has - '//*[@id="method.a"]/../../div[@class="docblock"]/p/a' 'Read more'
-    // @has - '//*[@id="method.a"]/../../div[@class="docblock"]/p/a/@href' 'trait.Trait.html#tymethod.a'
+    // @has trait_impl/struct.Struct.html '//*[@id="method.a"]/../../div[@class="docblock"]' 'Some long docs'
+    // @!has - '//*[@id="method.a"]/../../div[@class="docblock"]' 'link will be added'
+    // @has - '//*[@id="method.a"]/../../div[@class="docblock"]/a' 'Read more'
+    // @has - '//*[@id="method.a"]/../../div[@class="docblock"]/a/@href' 'trait.Trait.html#tymethod.a'
     fn a() {}
 
-    // @has - '//*[@id="method.b"]/../../div[@class="docblock"]/p' 'These docs contain'
-    // @has - '//*[@id="method.b"]/../../div[@class="docblock"]/p/a' 'reference link'
-    // @has - '//*[@id="method.b"]/../../div[@class="docblock"]/p/a/@href' 'https://example.com'
-    // @has - '//*[@id="method.b"]/../../div[@class="docblock"]/p/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"]' 'These docs contain'
+    // @has - '//*[@id="method.b"]/../../div[@class="docblock"]/a' 'reference link'
+    // @has - '//*[@id="method.b"]/../../div[@class="docblock"]/a/@href' 'https://example.com'
+    // @has - '//*[@id="method.b"]/../../div[@class="docblock"]/a' 'Read more'
+    // @has - '//*[@id="method.b"]/../../div[@class="docblock"]/a/@href' 'trait.Trait.html#tymethod.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/@href' 'trait.Trait.html#tymethod.c'
     fn c() {}
 
-    // @has - '//*[@id="method.d"]/../../div[@class="docblock"]/p' 'Escaped formatting a*b*c* works'
-    // @!has - '//*[@id="method.d"]/../../div[@class="docblock"]/p/em' ''
+    // @has - '//*[@id="method.d"]/../../div[@class="docblock"]' 'Escaped formatting a*b*c* works'
+    // @!has - '//*[@id="method.d"]/../../div[@class="docblock"]/em' ''
     fn d() {}
 
     // @has - '//*[@id="impl-Trait-for-Struct"]/h3//a/@href' 'trait.Trait.html'