diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2022-10-11 18:37:55 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-11 18:37:55 +0900 |
| commit | 3011538b80a52aedb2d7374798ffa35ea742d475 (patch) | |
| tree | 5003688052141d525b0e9c626a1e24c4c8fc916d /src/librustdoc | |
| parent | 98764c0c7292d866d795f69ccd286d0599e06361 (diff) | |
| parent | 44f466cb08650a721d06dece85385506633d55fc (diff) | |
| download | rust-3011538b80a52aedb2d7374798ffa35ea742d475.tar.gz rust-3011538b80a52aedb2d7374798ffa35ea742d475.zip | |
Rollup merge of #102898 - notriddle:notriddle/sidebar-block, r=GuillaumeGomez
rustdoc: remove unneeded `<div>` wrapper from sidebar DOM When this was added, the sidebar had a bit more complex style. It can be removed, now. Preview: https://notriddle.com/notriddle-rustdoc-demos/sidebar-block/std/index.html
Diffstat (limited to 'src/librustdoc')
| -rw-r--r-- | src/librustdoc/html/render/mod.rs | 24 | ||||
| -rw-r--r-- | src/librustdoc/html/static/css/rustdoc.css | 5 | ||||
| -rw-r--r-- | src/librustdoc/html/static/js/main.js | 26 |
3 files changed, 21 insertions, 34 deletions
diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 4bbb322d370..1e162bf314b 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1853,12 +1853,12 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) { buffer.write_str("<div class=\"sidebar-elems\">"); if it.is_crate() { - write!(buffer, "<div class=\"block\"><ul>"); + write!(buffer, "<ul class=\"block\">"); if let Some(ref version) = cx.cache().crate_version { write!(buffer, "<li class=\"version\">Version {}</li>", Escape(version)); } write!(buffer, "<li><a id=\"all-types\" href=\"all.html\">All Items</a></li>"); - buffer.write_str("</ul></div>"); + buffer.write_str("</ul>"); } match *it.kind { @@ -2258,8 +2258,7 @@ fn extract_for_impl_name(item: &clean::Item, cx: &Context<'_>) -> Option<(String } } -/// Don't call this function directly!!! Use `print_sidebar_title` or `print_sidebar_block` instead! -fn print_sidebar_title_inner(buf: &mut Buffer, id: &str, title: &str) { +fn print_sidebar_title(buf: &mut Buffer, id: &str, title: &str) { write!( buf, "<h3 class=\"sidebar-title\">\ @@ -2269,25 +2268,18 @@ fn print_sidebar_title_inner(buf: &mut Buffer, id: &str, title: &str) { ); } -fn print_sidebar_title(buf: &mut Buffer, id: &str, title: &str) { - buf.push_str("<div class=\"block\">"); - print_sidebar_title_inner(buf, id, title); - buf.push_str("</div>"); -} - fn print_sidebar_block( buf: &mut Buffer, id: &str, title: &str, items: impl Iterator<Item = impl fmt::Display>, ) { - buf.push_str("<div class=\"block\">"); - print_sidebar_title_inner(buf, id, title); - buf.push_str("<ul>"); + print_sidebar_title(buf, id, title); + buf.push_str("<ul class=\"block\">"); for item in items { write!(buf, "<li>{}</li>", item); } - buf.push_str("</ul></div>"); + buf.push_str("</ul>"); } fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean::Trait) { @@ -2676,9 +2668,7 @@ pub(crate) fn sidebar_module_like(buf: &mut Buffer, item_sections_in_use: FxHash write!( buf, "<section>\ - <div class=\"block\">\ - <ul>{}</ul>\ - </div>\ + <ul class=\"block\">{}</ul>\ </section>", sidebar ); diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index d4228a2ebc6..661aed71298 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -501,13 +501,14 @@ img { width: 100px; } -.block ul, .block li { +ul.block, .block li { padding: 0; margin: 0; list-style: none; } .block a, +.sidebar h3 a, h2.location a { display: block; padding: 0.25rem; @@ -767,7 +768,7 @@ h2.small-section-header > .anchor { text-decoration: underline; } -.block a.current.crate { font-weight: 500; } +.crate.block a.current { font-weight: 500; } /* In most contexts we use `overflow-wrap: anywhere` to ensure that we can wrap as much as needed on mobile (see diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index 359dd41b13f..0180c0ead8d 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -442,12 +442,10 @@ function loadCss(cssFileName) { return; } - const div = document.createElement("div"); - div.className = "block " + shortty; const h3 = document.createElement("h3"); h3.innerHTML = `<a href="index.html#${id}">${longty}</a>`; - div.appendChild(h3); const ul = document.createElement("ul"); + ul.className = "block " + shortty; for (const item of filtered) { const name = item[0]; @@ -473,8 +471,8 @@ function loadCss(cssFileName) { li.appendChild(link); ul.appendChild(li); } - div.appendChild(ul); - sidebar.appendChild(div); + sidebar.appendChild(h3); + sidebar.appendChild(ul); } if (sidebar) { @@ -592,27 +590,25 @@ function loadCss(cssFileName) { return; } // Draw a convenient sidebar of known crates if we have a listing - const div = document.createElement("div"); - div.className = "block crate"; - div.innerHTML = "<h3>Crates</h3>"; + const h3 = document.createElement("h3"); + h3.innerHTML = "Crates"; const ul = document.createElement("ul"); - div.appendChild(ul); + ul.className = "block crate"; for (const crate of window.ALL_CRATES) { - let klass = "crate"; - if (window.rootPath !== "./" && crate === window.currentCrate) { - klass += " current"; - } const link = document.createElement("a"); link.href = window.rootPath + crate + "/index.html"; - link.className = klass; + if (window.rootPath !== "./" && crate === window.currentCrate) { + link.className = "current"; + } link.textContent = crate; const li = document.createElement("li"); li.appendChild(link); ul.appendChild(li); } - sidebarElems.appendChild(div); + sidebarElems.appendChild(h3); + sidebarElems.appendChild(ul); } |
