about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Howell <michael@notriddle.com>2022-09-13 14:22:38 -0700
committerMichael Howell <michael@notriddle.com>2022-09-13 16:03:11 -0700
commit11a52dc61afda5ea82cff3e783e24f2302bdce3f (patch)
tree1a32da099966f24768788a6715c6c9425d4e9ac1
parent1ce51982b8550c782ded466c1abff0d2b2e21c4e (diff)
downloadrust-11a52dc61afda5ea82cff3e783e24f2302bdce3f.tar.gz
rust-11a52dc61afda5ea82cff3e783e24f2302bdce3f.zip
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.
-rw-r--r--src/librustdoc/html/markdown.rs6
-rw-r--r--src/librustdoc/html/static/css/rustdoc.css6
-rw-r--r--src/test/rustdoc-gui/label-next-to-symbol.goml18
-rw-r--r--src/test/rustdoc/short-docblock.rs10
-rw-r--r--src/test/rustdoc/trait-impl.rs24
5 files changed, 26 insertions, 38 deletions
diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs
index ec2e129c364..43d07d4a533 100644
--- a/src/librustdoc/html/markdown.rs
+++ b/src/librustdoc/html/markdown.rs
@@ -1119,7 +1119,11 @@ impl MarkdownSummaryLine<'_> {
 
         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
     }
diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css
index 011c559b34b..14f27eb6fa8 100644
--- a/src/librustdoc/html/static/css/rustdoc.css
+++ b/src/librustdoc/html/static/css/rustdoc.css
@@ -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;
 }
 
diff --git a/src/test/rustdoc-gui/label-next-to-symbol.goml b/src/test/rustdoc-gui/label-next-to-symbol.goml
index f9081189a86..4b4cea2621f 100644
--- a/src/test/rustdoc-gui/label-next-to-symbol.goml
+++ b/src/test/rustdoc-gui/label-next-to-symbol.goml
@@ -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"),
 )
diff --git a/src/test/rustdoc/short-docblock.rs b/src/test/rustdoc/short-docblock.rs
index 17c44eab091..1a8a689be1d 100644
--- a/src/test/rustdoc/short-docblock.rs
+++ b/src/test/rustdoc/short-docblock.rs
@@ -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)
diff --git a/src/test/rustdoc/trait-impl.rs b/src/test/rustdoc/trait-impl.rs
index 4d5173f6024..195cdf009b9 100644
--- a/src/test/rustdoc/trait-impl.rs
+++ b/src/test/rustdoc/trait-impl.rs
@@ -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'