Skip to content

Commit 9449848

Browse files
authored
Rollup merge of #101778 - notriddle:notriddle/docblock-short-p, r=GuillaumeGomez
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. Preview: https://notriddle.com/notriddle-rustdoc-test/docblock-short-p/std/index.html
2 parents b22055c + 11a52dc commit 9449848

File tree

5 files changed

+26
-38
lines changed

5 files changed

+26
-38
lines changed

src/librustdoc/html/markdown.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,11 @@ impl MarkdownSummaryLine<'_> {
11191119

11201120
let mut s = String::new();
11211121

1122-
html::push_html(&mut s, LinkReplacer::new(SummaryLine::new(p), links));
1122+
let without_paragraphs = LinkReplacer::new(SummaryLine::new(p), links).filter(|event| {
1123+
!matches!(event, Event::Start(Tag::Paragraph) | Event::End(Tag::Paragraph))
1124+
});
1125+
1126+
html::push_html(&mut s, without_paragraphs);
11231127

11241128
s
11251129
}

src/librustdoc/html/static/css/rustdoc.css

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -609,16 +609,12 @@ h2.location a {
609609
.docblock-short {
610610
overflow-wrap: break-word;
611611
overflow-wrap: anywhere;
612-
}
613-
.docblock-short p {
614-
display: inline;
615612
overflow: hidden;
616613
text-overflow: ellipsis;
617-
margin: 0;
618614
}
619615
/* Wrap non-pre code blocks (`text`) but not (```text```). */
620616
.docblock > :not(pre) > code,
621-
.docblock-short > :not(pre) > code {
617+
.docblock-short > code {
622618
white-space: pre-wrap;
623619
}
624620

src/test/rustdoc-gui/label-next-to-symbol.goml

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,9 @@ compare-elements-position: (
3131
)
3232

3333
// Ensure no wrap
34-
compare-elements-position-near: (
35-
"//*[@class='item-left module-item']//a[text()='replaced_function']",
36-
"//*[@class='item-right docblock-short']//p[text()='a thing with a label']",
37-
{"y": 2},
38-
)
39-
// compare parent elements
4034
compare-elements-position: (
4135
"//*[@class='item-left module-item']//a[text()='replaced_function']/..",
42-
"//*[@class='item-right docblock-short']//p[text()='a thing with a label']/..",
36+
"//*[@class='item-right docblock-short'][text()='a thing with a label']",
4337
("y"),
4438
)
4539

@@ -60,19 +54,13 @@ compare-elements-position: (
6054
)
6155

6256
// Ensure wrap
63-
compare-elements-position-near-false: (
64-
"//*[@class='item-left module-item']//a[text()='replaced_function']",
65-
"//*[@class='item-right docblock-short']//p[text()='a thing with a label']",
66-
{"y": 12},
67-
)
68-
// compare parent elements
6957
compare-elements-position-false: (
7058
"//*[@class='item-left module-item']//a[text()='replaced_function']/..",
71-
"//*[@class='item-right docblock-short']//p[text()='a thing with a label']/..",
59+
"//*[@class='item-right docblock-short'][text()='a thing with a label']",
7260
("y"),
7361
)
7462
compare-elements-position-false: (
7563
".item-left .stab.deprecated",
76-
"//*[@class='item-right docblock-short']//p[text()='a thing with a label']",
64+
"//*[@class='item-right docblock-short'][text()='a thing with a label']",
7765
("y"),
7866
)

src/test/rustdoc/short-docblock.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
#![crate_name = "foo"]
22

3-
// @has foo/index.html '//*[@class="item-right docblock-short"]/p' 'fooo'
4-
// @!has foo/index.html '//*[@class="item-right docblock-short"]/p/h1' 'fooo'
3+
// @has foo/index.html '//*[@class="item-right docblock-short"]' 'fooo'
4+
// @!has foo/index.html '//*[@class="item-right docblock-short"]/h1' 'fooo'
55
// @has foo/fn.foo.html '//h2[@id="fooo"]/a[@href="#fooo"]' 'fooo'
66

77
/// # fooo
88
///
99
/// foo
1010
pub fn foo() {}
1111

12-
// @has foo/index.html '//*[@class="item-right docblock-short"]/p' 'mooood'
13-
// @!has foo/index.html '//*[@class="item-right docblock-short"]/p/h2' 'mooood'
12+
// @has foo/index.html '//*[@class="item-right docblock-short"]' 'mooood'
13+
// @!has foo/index.html '//*[@class="item-right docblock-short"]/h2' 'mooood'
1414
// @has foo/foo/index.html '//h3[@id="mooood"]/a[@href="#mooood"]' 'mooood'
1515

1616
/// ## mooood
1717
///
1818
/// foo mod
1919
pub mod foo {}
2020

21-
// @has foo/index.html '//*[@class="item-right docblock-short"]/p/a[@href=\
21+
// @has foo/index.html '//*[@class="item-right docblock-short"]/a[@href=\
2222
// "https://nougat.world"]/code' 'nougat'
2323

2424
/// [`nougat`](https://nougat.world)

src/test/rustdoc/trait-impl.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,26 @@ pub trait Trait {
2121
pub struct Struct;
2222

2323
impl Trait for Struct {
24-
// @has trait_impl/struct.Struct.html '//*[@id="method.a"]/../../div[@class="docblock"]/p' 'Some long docs'
25-
// @!has - '//*[@id="method.a"]/../../div[@class="docblock"]/p' 'link will be added'
26-
// @has - '//*[@id="method.a"]/../../div[@class="docblock"]/p/a' 'Read more'
27-
// @has - '//*[@id="method.a"]/../../div[@class="docblock"]/p/a/@href' 'trait.Trait.html#tymethod.a'
24+
// @has trait_impl/struct.Struct.html '//*[@id="method.a"]/../../div[@class="docblock"]' 'Some long docs'
25+
// @!has - '//*[@id="method.a"]/../../div[@class="docblock"]' 'link will be added'
26+
// @has - '//*[@id="method.a"]/../../div[@class="docblock"]/a' 'Read more'
27+
// @has - '//*[@id="method.a"]/../../div[@class="docblock"]/a/@href' 'trait.Trait.html#tymethod.a'
2828
fn a() {}
2929

30-
// @has - '//*[@id="method.b"]/../../div[@class="docblock"]/p' 'These docs contain'
31-
// @has - '//*[@id="method.b"]/../../div[@class="docblock"]/p/a' 'reference link'
32-
// @has - '//*[@id="method.b"]/../../div[@class="docblock"]/p/a/@href' 'https://example.com'
33-
// @has - '//*[@id="method.b"]/../../div[@class="docblock"]/p/a' 'Read more'
34-
// @has - '//*[@id="method.b"]/../../div[@class="docblock"]/p/a/@href' 'trait.Trait.html#tymethod.b'
30+
// @has - '//*[@id="method.b"]/../../div[@class="docblock"]' 'These docs contain'
31+
// @has - '//*[@id="method.b"]/../../div[@class="docblock"]/a' 'reference link'
32+
// @has - '//*[@id="method.b"]/../../div[@class="docblock"]/a/@href' 'https://example.com'
33+
// @has - '//*[@id="method.b"]/../../div[@class="docblock"]/a' 'Read more'
34+
// @has - '//*[@id="method.b"]/../../div[@class="docblock"]/a/@href' 'trait.Trait.html#tymethod.b'
3535
fn b() {}
3636

37-
// @!has - '//*[@id="method.c"]/../../div[@class="docblock"]/p' 'code block'
37+
// @!has - '//*[@id="method.c"]/../../div[@class="docblock"]' 'code block'
3838
// @has - '//*[@id="method.c"]/../../div[@class="docblock"]/a' 'Read more'
3939
// @has - '//*[@id="method.c"]/../../div[@class="docblock"]/a/@href' 'trait.Trait.html#tymethod.c'
4040
fn c() {}
4141

42-
// @has - '//*[@id="method.d"]/../../div[@class="docblock"]/p' 'Escaped formatting a*b*c* works'
43-
// @!has - '//*[@id="method.d"]/../../div[@class="docblock"]/p/em' ''
42+
// @has - '//*[@id="method.d"]/../../div[@class="docblock"]' 'Escaped formatting a*b*c* works'
43+
// @!has - '//*[@id="method.d"]/../../div[@class="docblock"]/em' ''
4444
fn d() {}
4545

4646
// @has - '//*[@id="impl-Trait-for-Struct"]/h3//a/@href' 'trait.Trait.html'

0 commit comments

Comments
 (0)