Skip to content

Commit 4165de4

Browse files
authored
Rollup merge of #107783 - notriddle:notriddle/item-table-ul, r=GuillaumeGomez
rustdoc: simplify DOM for `.item-table` This switches from using `<div>` to the more semantic `<ul>`, and using class names that rhyme with the classes the search results table uses.
2 parents e802713 + 894c986 commit 4165de4

23 files changed

+103
-101
lines changed

src/librustdoc/html/render/print_item.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ use crate::html::{highlight, static_files};
3939
use askama::Template;
4040
use itertools::Itertools;
4141

42-
const ITEM_TABLE_OPEN: &str = "<div class=\"item-table\">";
43-
const ITEM_TABLE_CLOSE: &str = "</div>";
44-
const ITEM_TABLE_ROW_OPEN: &str = "<div class=\"item-row\">";
45-
const ITEM_TABLE_ROW_CLOSE: &str = "</div>";
42+
const ITEM_TABLE_OPEN: &str = "<ul class=\"item-table\">";
43+
const ITEM_TABLE_CLOSE: &str = "</ul>";
44+
const ITEM_TABLE_ROW_OPEN: &str = "<li>";
45+
const ITEM_TABLE_ROW_CLOSE: &str = "</li>";
4646

4747
// A component in a `use` path, like `string` in std::string::ToString
4848
struct PathComponent {
@@ -338,14 +338,14 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
338338
match *src {
339339
Some(src) => write!(
340340
w,
341-
"<div class=\"item-left\"><code>{}extern crate {} as {};",
341+
"<div class=\"item-name\"><code>{}extern crate {} as {};",
342342
visibility_print_with_space(myitem.visibility(tcx), myitem.item_id, cx),
343343
anchor(myitem.item_id.expect_def_id(), src, cx),
344344
myitem.name.unwrap(),
345345
),
346346
None => write!(
347347
w,
348-
"<div class=\"item-left\"><code>{}extern crate {};",
348+
"<div class=\"item-name\"><code>{}extern crate {};",
349349
visibility_print_with_space(myitem.visibility(tcx), myitem.item_id, cx),
350350
anchor(myitem.item_id.expect_def_id(), myitem.name.unwrap(), cx),
351351
),
@@ -384,11 +384,11 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
384384
let (stab_tags_before, stab_tags_after) = if stab_tags.is_empty() {
385385
("", "")
386386
} else {
387-
("<div class=\"item-right docblock-short\">", "</div>")
387+
("<div class=\"desc docblock-short\">", "</div>")
388388
};
389389
write!(
390390
w,
391-
"<div class=\"item-left\"{id}>\
391+
"<div class=\"item-name\"{id}>\
392392
<code>{vis}{imp}</code>\
393393
</div>\
394394
{stab_tags_before}{stab_tags}{stab_tags_after}",
@@ -426,11 +426,11 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
426426
let (docs_before, docs_after) = if docs.is_empty() {
427427
("", "")
428428
} else {
429-
("<div class=\"item-right docblock-short\">", "</div>")
429+
("<div class=\"desc docblock-short\">", "</div>")
430430
};
431431
write!(
432432
w,
433-
"<div class=\"item-left\">\
433+
"<div class=\"item-name\">\
434434
<a class=\"{class}\" href=\"{href}\" title=\"{title}\">{name}</a>\
435435
{visibility_emoji}\
436436
{unsafety_flag}\

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

+9-7
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ h1, h2, h3, h4, h5, h6,
201201
.mobile-topbar,
202202
.search-input,
203203
.search-results .result-name,
204-
.item-left > a,
204+
.item-name > a,
205205
.out-of-band,
206206
span.since,
207207
a.srclink,
@@ -750,14 +750,16 @@ table,
750750

751751
.item-table {
752752
display: table;
753+
padding: 0;
754+
margin: 0;
753755
}
754-
.item-row {
756+
.item-table > li {
755757
display: table-row;
756758
}
757-
.item-left, .item-right {
759+
.item-table > li > div {
758760
display: table-cell;
759761
}
760-
.item-left {
762+
.item-table > li > .item-name {
761763
padding-right: 1.25rem;
762764
}
763765

@@ -962,7 +964,7 @@ so that we can apply CSS-filters to change the arrow color in themes */
962964
padding: 3px;
963965
margin-bottom: 5px;
964966
}
965-
.item-left .stab {
967+
.item-name .stab {
966968
margin-left: 0.3125em;
967969
}
968970
.stab {
@@ -1695,7 +1697,7 @@ in storage.js
16951697
}
16961698

16971699
/* Display an alternating layout on tablets and phones */
1698-
.item-table, .item-row, .item-left, .item-right,
1700+
.item-table, .item-row, .item-table > li, .item-table > li > div,
16991701
.search-results > a, .search-results > a > div {
17001702
display: block;
17011703
}
@@ -1704,7 +1706,7 @@ in storage.js
17041706
.search-results > a {
17051707
padding: 5px 0px;
17061708
}
1707-
.search-results > a > div.desc, .item-right {
1709+
.search-results > a > div.desc, .item-table > li > div.desc {
17081710
padding-left: 2em;
17091711
}
17101712

tests/rustdoc-gui/huge-collection-of-constants.goml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
goto: "file://" + |DOC_PATH| + "/test_docs/huge_amount_of_consts/index.html"
44

55
compare-elements-position-near-false: (
6-
"//*[@class='item-table']//div[last()-1]",
7-
"//*[@class='item-table']//div[last()-3]",
6+
"//ul[@class='item-table']/li[last()-1]",
7+
"//ul[@class='item-table']/li[last()-3]",
88
{"y": 12},
99
)
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This test ensures that <table> elements aren't display in items summary.
22
goto: "file://" + |DOC_PATH| + "/lib2/summary_table/index.html"
33
// We check that we picked the right item first.
4-
assert-text: (".item-table .item-left", "Foo")
4+
assert-text: (".item-table .item-name", "Foo")
55
// Then we check that its summary is empty.
6-
assert-false: ".item-table .item-right"
6+
assert-false: ".item-table .desc"

tests/rustdoc-gui/label-next-to-symbol.goml

+18-18
Original file line numberDiff line numberDiff line change
@@ -9,58 +9,58 @@ assert: (".stab.portability")
99

1010
// make sure that deprecated and portability have the right colors
1111
assert-css: (
12-
".item-table .item-left .stab.deprecated",
12+
".item-table .item-name .stab.deprecated",
1313
{ "background-color": "rgb(255, 245, 214)" },
1414
)
1515
assert-css: (
16-
".item-table .item-left .stab.portability",
16+
".item-table .item-name .stab.portability",
1717
{ "background-color": "rgb(255, 245, 214)" },
1818
)
1919

2020
// table like view
21-
assert-css: (".item-right.docblock-short", { "padding-left": "0px" })
21+
assert-css: (".desc.docblock-short", { "padding-left": "0px" })
2222
compare-elements-position-near: (
23-
"//*[@class='item-left']//a[text()='replaced_function']",
24-
".item-left .stab.deprecated",
23+
"//*[@class='item-name']//a[text()='replaced_function']",
24+
".item-name .stab.deprecated",
2525
{"y": 2},
2626
)
2727
compare-elements-position: (
28-
".item-left .stab.deprecated",
29-
".item-left .stab.portability",
28+
".item-name .stab.deprecated",
29+
".item-name .stab.portability",
3030
("y"),
3131
)
3232

3333
// Ensure no wrap
3434
compare-elements-position: (
35-
"//*[@class='item-left']//a[text()='replaced_function']/..",
36-
"//*[@class='item-right docblock-short'][text()='a thing with a label']",
35+
"//*[@class='item-name']//a[text()='replaced_function']/..",
36+
"//*[@class='desc docblock-short'][text()='a thing with a label']",
3737
("y"),
3838
)
3939

4040

4141
// Mobile view
4242
size: (600, 600)
4343
// staggered layout with 2em spacing
44-
assert-css: (".item-right.docblock-short", { "padding-left": "32px" })
44+
assert-css: (".desc.docblock-short", { "padding-left": "32px" })
4545
compare-elements-position-near: (
46-
"//*[@class='item-left']//a[text()='replaced_function']",
47-
".item-left .stab.deprecated",
46+
"//*[@class='item-name']//a[text()='replaced_function']",
47+
".item-name .stab.deprecated",
4848
{"y": 2},
4949
)
5050
compare-elements-position: (
51-
".item-left .stab.deprecated",
52-
".item-left .stab.portability",
51+
".item-name .stab.deprecated",
52+
".item-name .stab.portability",
5353
("y"),
5454
)
5555

5656
// Ensure wrap
5757
compare-elements-position-false: (
58-
"//*[@class='item-left']//a[text()='replaced_function']/..",
59-
"//*[@class='item-right docblock-short'][text()='a thing with a label']",
58+
"//*[@class='item-name']//a[text()='replaced_function']/..",
59+
"//*[@class='desc docblock-short'][text()='a thing with a label']",
6060
("y"),
6161
)
6262
compare-elements-position-false: (
63-
".item-left .stab.deprecated",
64-
"//*[@class='item-right docblock-short'][text()='a thing with a label']",
63+
".item-name .stab.deprecated",
64+
"//*[@class='desc docblock-short'][text()='a thing with a label']",
6565
("y"),
6666
)
+13-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This test checks that the correct font is used on module items (in index.html pages).
22
goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
33
assert-css: (
4-
".item-table .item-left > a",
4+
".item-table .item-name > a",
55
{"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'},
66
ALL,
77
)
@@ -13,55 +13,55 @@ assert-css: (
1313

1414
// modules
1515
assert-css: (
16-
"#modules + .item-table .item-left a",
16+
"#modules + .item-table .item-name a",
1717
{"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'},
1818
)
1919
assert-css: (
20-
"#modules + .item-table .item-right.docblock-short",
20+
"#modules + .item-table .desc.docblock-short",
2121
{"font-family": '"Source Serif 4", NanumBarunGothic, serif'},
2222
)
2323
// structs
2424
assert-css: (
25-
"#structs + .item-table .item-left a",
25+
"#structs + .item-table .item-name a",
2626
{"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'},
2727
)
2828
assert-css: (
29-
"#structs + .item-table .item-right.docblock-short",
29+
"#structs + .item-table .desc.docblock-short",
3030
{"font-family": '"Source Serif 4", NanumBarunGothic, serif'},
3131
)
3232
// enums
3333
assert-css: (
34-
"#enums + .item-table .item-left a",
34+
"#enums + .item-table .item-name a",
3535
{"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'},
3636
)
3737
assert-css: (
38-
"#enums + .item-table .item-right.docblock-short",
38+
"#enums + .item-table .desc.docblock-short",
3939
{"font-family": '"Source Serif 4", NanumBarunGothic, serif'},
4040
)
4141
// traits
4242
assert-css: (
43-
"#traits + .item-table .item-left a",
43+
"#traits + .item-table .item-name a",
4444
{"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'},
4545
)
4646
assert-css: (
47-
"#traits + .item-table .item-right.docblock-short",
47+
"#traits + .item-table .desc.docblock-short",
4848
{"font-family": '"Source Serif 4", NanumBarunGothic, serif'},
4949
)
5050
// functions
5151
assert-css: (
52-
"#functions + .item-table .item-left a",
52+
"#functions + .item-table .item-name a",
5353
{"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'},
5454
)
5555
assert-css: (
56-
"#functions + .item-table .item-right.docblock-short",
56+
"#functions + .item-table .desc.docblock-short",
5757
{"font-family": '"Source Serif 4", NanumBarunGothic, serif'},
5858
)
5959
// keywords
6060
assert-css: (
61-
"#keywords + .item-table .item-left a",
61+
"#keywords + .item-table .item-name a",
6262
{"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'},
6363
)
6464
assert-css: (
65-
"#keywords + .item-table .item-right.docblock-short",
65+
"#keywords + .item-table .desc.docblock-short",
6666
{"font-family": '"Source Serif 4", NanumBarunGothic, serif'},
6767
)

tests/rustdoc-gui/sidebar.goml

+5-5
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ assert-text: (".sidebar-elems section ul > li:nth-child(8)", "Functions")
7070
assert-text: (".sidebar-elems section ul > li:nth-child(9)", "Type Definitions")
7171
assert-text: (".sidebar-elems section ul > li:nth-child(10)", "Unions")
7272
assert-text: (".sidebar-elems section ul > li:nth-child(11)", "Keywords")
73-
assert-text: ("#structs + .item-table .item-left > a", "Foo")
74-
click: "#structs + .item-table .item-left > a"
73+
assert-text: ("#structs + .item-table .item-name > a", "Foo")
74+
click: "#structs + .item-table .item-name > a"
7575

7676
// PAGE: struct.Foo.html
7777
assert-count: (".sidebar .location", 1)
@@ -103,8 +103,8 @@ assert-text: (".sidebar-elems > section ul.block > li:nth-child(2)", "Structs")
103103
assert-text: (".sidebar-elems > section ul.block > li:nth-child(3)", "Traits")
104104
assert-text: (".sidebar-elems > section ul.block > li:nth-child(4)", "Functions")
105105
assert-text: (".sidebar-elems > section ul.block > li:nth-child(5)", "Type Definitions")
106-
assert-text: ("#functions + .item-table .item-left > a", "foobar")
107-
click: "#functions + .item-table .item-left > a"
106+
assert-text: ("#functions + .item-table .item-name > a", "foobar")
107+
click: "#functions + .item-table .item-name > a"
108108

109109
// PAGE: fn.foobar.html
110110
// In items containing no items (like functions or constants) and in modules, we have no
@@ -127,7 +127,7 @@ assert-text: (".sidebar > .location", "Module sub_sub_module")
127127
// We check that we don't have the crate list.
128128
assert-false: ".sidebar-elems .crate"
129129
assert-text: (".sidebar-elems > section ul > li:nth-child(1)", "Functions")
130-
assert-text: ("#functions + .item-table .item-left > a", "foo")
130+
assert-text: ("#functions + .item-table .item-name > a", "foo")
131131

132132
// Links to trait implementations in the sidebar should not wrap even if they are long.
133133
goto: "file://" + |DOC_PATH| + "/lib2/struct.HasALongTraitWithParams.html"

tests/rustdoc-gui/unsafe-fn.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ define-function: (
1919
local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}
2020
// We reload the page so the local storage settings are being used.
2121
reload:
22-
assert-css: (".item-left sup", {"color": |color|})
22+
assert-css: (".item-name sup", {"color": |color|})
2323
},
2424
)
2525

tests/rustdoc/cfg_doc_reexport.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#![no_core]
66

77
// @has 'foo/index.html'
8-
// @has - '//*[@class="item-left"]/*[@class="stab portability"]' 'foobar'
9-
// @has - '//*[@class="item-left"]/*[@class="stab portability"]' 'bar'
8+
// @has - '//*[@class="item-name"]/*[@class="stab portability"]' 'foobar'
9+
// @has - '//*[@class="item-name"]/*[@class="stab portability"]' 'bar'
1010

1111
#[doc(cfg(feature = "foobar"))]
1212
mod imp_priv {

tests/rustdoc/deprecated.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
// @has deprecated/index.html '//*[@class="item-left"]/span[@class="stab deprecated"]' \
1+
// @has deprecated/index.html '//*[@class="item-name"]/span[@class="stab deprecated"]' \
22
// 'Deprecated'
3-
// @has - '//*[@class="item-right docblock-short"]' 'Deprecated docs'
3+
// @has - '//*[@class="desc docblock-short"]' 'Deprecated docs'
44

55
// @has deprecated/struct.S.html '//*[@class="stab deprecated"]' \
66
// 'Deprecated since 1.0.0: text'
77
/// Deprecated docs
88
#[deprecated(since = "1.0.0", note = "text")]
99
pub struct S;
1010

11-
// @matches deprecated/index.html '//*[@class="item-right docblock-short"]' '^Docs'
11+
// @matches deprecated/index.html '//*[@class="desc docblock-short"]' '^Docs'
1212
/// Docs
1313
pub struct T;
1414

tests/rustdoc/doc-cfg.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct Portable;
1212
// @has doc_cfg/unix_only/index.html \
1313
// '//*[@id="main-content"]/*[@class="item-info"]/*[@class="stab portability"]' \
1414
// 'Available on Unix only.'
15-
// @matches - '//*[@class="item-left"]//*[@class="stab portability"]' '\AARM\Z'
15+
// @matches - '//*[@class="item-name"]//*[@class="stab portability"]' '\AARM\Z'
1616
// @count - '//*[@class="stab portability"]' 2
1717
#[doc(cfg(unix))]
1818
pub mod unix_only {
@@ -42,7 +42,7 @@ pub mod unix_only {
4242
// @has doc_cfg/wasi_only/index.html \
4343
// '//*[@id="main-content"]/*[@class="item-info"]/*[@class="stab portability"]' \
4444
// 'Available on WASI only.'
45-
// @matches - '//*[@class="item-left"]//*[@class="stab portability"]' '\AWebAssembly\Z'
45+
// @matches - '//*[@class="item-name"]//*[@class="stab portability"]' '\AWebAssembly\Z'
4646
// @count - '//*[@class="stab portability"]' 2
4747
#[doc(cfg(target_os = "wasi"))]
4848
pub mod wasi_only {
@@ -74,7 +74,7 @@ pub mod wasi_only {
7474

7575
// the portability header is different on the module view versus the full view
7676
// @has doc_cfg/index.html
77-
// @matches - '//*[@class="item-left"]//*[@class="stab portability"]' '\Aavx\Z'
77+
// @matches - '//*[@class="item-name"]//*[@class="stab portability"]' '\Aavx\Z'
7878

7979
// @has doc_cfg/fn.uses_target_feature.html
8080
// @has - '//*[@id="main-content"]/*[@class="item-info"]/*[@class="stab portability"]' \

tests/rustdoc/duplicate-cfg.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#![feature(doc_cfg)]
33

44
// @has 'foo/index.html'
5-
// @matches '-' '//*[@class="item-left"]//*[@class="stab portability"]' '^sync$'
6-
// @has '-' '//*[@class="item-left"]//*[@class="stab portability"]/@title' 'Available on crate feature `sync` only'
5+
// @matches '-' '//*[@class="item-name"]//*[@class="stab portability"]' '^sync$'
6+
// @has '-' '//*[@class="item-name"]//*[@class="stab portability"]/@title' 'Available on crate feature `sync` only'
77

88
// @has 'foo/struct.Foo.html'
99
// @has '-' '//*[@class="stab portability"]' 'sync'

0 commit comments

Comments
 (0)