Skip to content

Commit 0d78bd3

Browse files
Replace ul/li list with dl/dd/dt elements
1 parent 2776bdf commit 0d78bd3

File tree

2 files changed

+29
-33
lines changed

2 files changed

+29
-33
lines changed

src/librustdoc/html/render/print_item.rs

+11-19
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,8 @@ macro_rules! item_template_methods {
140140
};
141141
}
142142

143-
const ITEM_TABLE_OPEN: &str = "<ul class=\"item-table\">";
144-
const ITEM_TABLE_CLOSE: &str = "</ul>";
145-
const ITEM_TABLE_ROW_OPEN: &str = "<li>";
146-
const ITEM_TABLE_ROW_CLOSE: &str = "</li>";
143+
const ITEM_TABLE_OPEN: &str = "<dl class=\"item-table\">";
144+
const ITEM_TABLE_CLOSE: &str = "</dl>";
147145

148146
// A component in a `use` path, like `string` in std::string::ToString
149147
struct PathComponent {
@@ -413,32 +411,29 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
413411
clean::ExternCrateItem { ref src } => {
414412
use crate::html::format::anchor;
415413

416-
w.write_str(ITEM_TABLE_ROW_OPEN);
417414
match *src {
418415
Some(src) => write!(
419416
w,
420-
"<div class=\"item-name\"><code>{}extern crate {} as {};",
417+
"<dt class=\"item-name\"><code>{}extern crate {} as {};",
421418
visibility_print_with_space(myitem, cx),
422419
anchor(myitem.item_id.expect_def_id(), src, cx),
423420
EscapeBodyTextWithWbr(myitem.name.unwrap().as_str()),
424421
),
425422
None => write!(
426423
w,
427-
"<div class=\"item-name\"><code>{}extern crate {};",
424+
"<dt class=\"item-name\"><code>{}extern crate {};",
428425
visibility_print_with_space(myitem, cx),
429426
anchor(myitem.item_id.expect_def_id(), myitem.name.unwrap(), cx),
430427
),
431428
}
432-
w.write_str("</code></div>");
433-
w.write_str(ITEM_TABLE_ROW_CLOSE);
429+
w.write_str("</code></dt>");
434430
}
435431

436432
clean::ImportItem(ref import) => {
437433
let stab_tags = import.source.did.map_or_else(String::new, |import_def_id| {
438434
extra_info_tags(tcx, myitem, item, Some(import_def_id)).to_string()
439435
});
440436

441-
w.write_str(ITEM_TABLE_ROW_OPEN);
442437
let id = match import.kind {
443438
clean::ImportKind::Simple(s) => {
444439
format!(" id=\"{}\"", cx.derive_id(format!("reexport.{s}")))
@@ -448,18 +443,17 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
448443
let (stab_tags_before, stab_tags_after) = if stab_tags.is_empty() {
449444
("", "")
450445
} else {
451-
("<div class=\"desc docblock-short\">", "</div>")
446+
("<dd class=\"desc docblock-short\">", "</dd>")
452447
};
453448
write!(
454449
w,
455-
"<div class=\"item-name\"{id}>\
450+
"<dt class=\"item-name\"{id}>\
456451
<code>{vis}{imp}</code>\
457-
</div>\
452+
</dt>\
458453
{stab_tags_before}{stab_tags}{stab_tags_after}",
459454
vis = visibility_print_with_space(myitem, cx),
460455
imp = import.print(cx),
461456
);
462-
w.write_str(ITEM_TABLE_ROW_CLOSE);
463457
}
464458

465459
_ => {
@@ -492,22 +486,21 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
492486
_ => "",
493487
};
494488

495-
w.write_str(ITEM_TABLE_ROW_OPEN);
496489
let docs =
497490
MarkdownSummaryLine(&myitem.doc_value(), &myitem.links(cx)).into_string();
498491
let (docs_before, docs_after) = if docs.is_empty() {
499492
("", "")
500493
} else {
501-
("<div class=\"desc docblock-short\">", "</div>")
494+
("<dd class=\"desc docblock-short\">", "</dd>")
502495
};
503496
write!(
504497
w,
505-
"<div class=\"item-name\">\
498+
"<dt class=\"item-name\">\
506499
<a class=\"{class}\" href=\"{href}\" title=\"{title}\">{name}</a>\
507500
{visibility_and_hidden}\
508501
{unsafety_flag}\
509502
{stab_tags}\
510-
</div>\
503+
</dt>\
511504
{docs_before}{docs}{docs_after}",
512505
name = EscapeBodyTextWithWbr(myitem.name.unwrap().as_str()),
513506
visibility_and_hidden = visibility_and_hidden,
@@ -521,7 +514,6 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
521514
.collect::<Vec<_>>()
522515
.join(" "),
523516
);
524-
w.write_str(ITEM_TABLE_ROW_CLOSE);
525517
}
526518
}
527519
}

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

+18-14
Original file line numberDiff line numberDiff line change
@@ -1102,20 +1102,17 @@ table,
11021102
}
11031103

11041104
.item-table {
1105-
display: table;
11061105
padding: 0;
11071106
margin: 0;
11081107
width: 100%;
11091108
}
1110-
.item-table > li {
1111-
display: table-row;
1112-
}
1113-
.item-table > li > div {
1114-
display: table-cell;
1115-
}
1116-
.item-table > li > .item-name {
1109+
.item-table > .item-name {
11171110
padding-right: 1.25rem;
11181111
}
1112+
.item-table > dd {
1113+
margin-inline-start: 0;
1114+
margin-left: 0;
1115+
}
11191116

11201117
.search-results-title {
11211118
margin-top: 0;
@@ -2476,16 +2473,15 @@ in src-script.js and main.js
24762473
}
24772474

24782475
/* Display an alternating layout on tablets and phones */
2479-
.item-table, .item-row, .item-table > li, .item-table > li > div,
2480-
.search-results > a, .search-results > a > div {
2476+
.item-row, .search-results > a, .search-results > a > div {
24812477
display: block;
24822478
}
24832479

24842480
/* Display an alternating layout on tablets and phones */
24852481
.search-results > a {
24862482
padding: 5px 0px;
24872483
}
2488-
.search-results > a > div.desc, .item-table > li > div.desc {
2484+
.search-results > a > div.desc, .item-table dd.desc {
24892485
padding-left: 2em;
24902486
}
24912487
.search-results .result-name {
@@ -2546,12 +2542,20 @@ in src-script.js and main.js
25462542
box-shadow: 0 0 4px var(--main-background-color);
25472543
}
25482544

2549-
.item-table > li > .item-name {
2550-
width: 33%;
2545+
/* Since the screen is wide enough, we show items on their description on the same line. */
2546+
.item-table {
2547+
display: grid;
2548+
grid-template-columns: 33% 67%;
25512549
}
2552-
.item-table > li > div {
2550+
.item-table > dt, .item-table > dd {
25532551
overflow-wrap: anywhere;
25542552
}
2553+
.item-table > dt {
2554+
grid-column-start: 1;
2555+
}
2556+
.item-table > dd {
2557+
grid-column-start: 2;
2558+
}
25552559
}
25562560

25572561
@media print {

0 commit comments

Comments
 (0)