diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2025-01-17 17:20:35 +0100 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2025-01-17 22:36:48 +0100 |
| commit | b6ad420a20ab7e024298c62de2336dfea23098e2 (patch) | |
| tree | 3cc8cc5a07bd2ed7ce9dea560fb148d5b004612e | |
| parent | bcd0683e5dce1945b5d940714742e7502883bb5c (diff) | |
| download | rust-b6ad420a20ab7e024298c62de2336dfea23098e2.tar.gz rust-b6ad420a20ab7e024298c62de2336dfea23098e2.zip | |
Replace ul/li list with dl/dd/dt elements
| -rw-r--r-- | src/librustdoc/html/render/print_item.rs | 30 | ||||
| -rw-r--r-- | src/librustdoc/html/static/css/rustdoc.css | 32 |
2 files changed, 29 insertions, 33 deletions
diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 1376bdb2e90..62b1917dfa4 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -140,10 +140,8 @@ macro_rules! item_template_methods { }; } -const ITEM_TABLE_OPEN: &str = "<ul class=\"item-table\">"; -const ITEM_TABLE_CLOSE: &str = "</ul>"; -const ITEM_TABLE_ROW_OPEN: &str = "<li>"; -const ITEM_TABLE_ROW_CLOSE: &str = "</li>"; +const ITEM_TABLE_OPEN: &str = "<dl class=\"item-table\">"; +const ITEM_TABLE_CLOSE: &str = "</dl>"; // A component in a `use` path, like `string` in std::string::ToString struct PathComponent { @@ -413,24 +411,22 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl clean::ExternCrateItem { ref src } => { use crate::html::format::anchor; - w.write_str(ITEM_TABLE_ROW_OPEN); match *src { Some(src) => write!( w, - "<div class=\"item-name\"><code>{}extern crate {} as {};", + "<dt class=\"item-name\"><code>{}extern crate {} as {};", visibility_print_with_space(myitem, cx), anchor(myitem.item_id.expect_def_id(), src, cx), EscapeBodyTextWithWbr(myitem.name.unwrap().as_str()), ), None => write!( w, - "<div class=\"item-name\"><code>{}extern crate {};", + "<dt class=\"item-name\"><code>{}extern crate {};", visibility_print_with_space(myitem, cx), anchor(myitem.item_id.expect_def_id(), myitem.name.unwrap(), cx), ), } - w.write_str("</code></div>"); - w.write_str(ITEM_TABLE_ROW_CLOSE); + w.write_str("</code></dt>"); } clean::ImportItem(ref import) => { @@ -438,7 +434,6 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl extra_info_tags(tcx, myitem, item, Some(import_def_id)).to_string() }); - w.write_str(ITEM_TABLE_ROW_OPEN); let id = match import.kind { clean::ImportKind::Simple(s) => { 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 let (stab_tags_before, stab_tags_after) = if stab_tags.is_empty() { ("", "") } else { - ("<div class=\"desc docblock-short\">", "</div>") + ("<dd class=\"desc docblock-short\">", "</dd>") }; write!( w, - "<div class=\"item-name\"{id}>\ + "<dt class=\"item-name\"{id}>\ <code>{vis}{imp}</code>\ - </div>\ + </dt>\ {stab_tags_before}{stab_tags}{stab_tags_after}", vis = visibility_print_with_space(myitem, cx), imp = import.print(cx), ); - w.write_str(ITEM_TABLE_ROW_CLOSE); } _ => { @@ -492,22 +486,21 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl _ => "", }; - w.write_str(ITEM_TABLE_ROW_OPEN); let docs = MarkdownSummaryLine(&myitem.doc_value(), &myitem.links(cx)).into_string(); let (docs_before, docs_after) = if docs.is_empty() { ("", "") } else { - ("<div class=\"desc docblock-short\">", "</div>") + ("<dd class=\"desc docblock-short\">", "</dd>") }; write!( w, - "<div class=\"item-name\">\ + "<dt class=\"item-name\">\ <a class=\"{class}\" href=\"{href}\" title=\"{title}\">{name}</a>\ {visibility_and_hidden}\ {unsafety_flag}\ {stab_tags}\ - </div>\ + </dt>\ {docs_before}{docs}{docs_after}", name = EscapeBodyTextWithWbr(myitem.name.unwrap().as_str()), visibility_and_hidden = visibility_and_hidden, @@ -521,7 +514,6 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl .collect::<Vec<_>>() .join(" "), ); - w.write_str(ITEM_TABLE_ROW_CLOSE); } } } diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index a1ab258ff30..5c41832d440 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1102,20 +1102,17 @@ table, } .item-table { - display: table; padding: 0; margin: 0; width: 100%; } -.item-table > li { - display: table-row; -} -.item-table > li > div { - display: table-cell; -} -.item-table > li > .item-name { +.item-table > .item-name { padding-right: 1.25rem; } +.item-table > dd { + margin-inline-start: 0; + margin-left: 0; +} .search-results-title { margin-top: 0; @@ -2476,8 +2473,7 @@ in src-script.js and main.js } /* Display an alternating layout on tablets and phones */ - .item-table, .item-row, .item-table > li, .item-table > li > div, - .search-results > a, .search-results > a > div { + .item-row, .search-results > a, .search-results > a > div { display: block; } @@ -2485,7 +2481,7 @@ in src-script.js and main.js .search-results > a { padding: 5px 0px; } - .search-results > a > div.desc, .item-table > li > div.desc { + .search-results > a > div.desc, .item-table dd.desc { padding-left: 2em; } .search-results .result-name { @@ -2546,12 +2542,20 @@ in src-script.js and main.js box-shadow: 0 0 4px var(--main-background-color); } - .item-table > li > .item-name { - width: 33%; + /* Since the screen is wide enough, we show items on their description on the same line. */ + .item-table { + display: grid; + grid-template-columns: 33% 67%; } - .item-table > li > div { + .item-table > dt, .item-table > dd { overflow-wrap: anywhere; } + .item-table > dt { + grid-column-start: 1; + } + .item-table > dd { + grid-column-start: 2; + } } @media print { |
