diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2021-04-24 12:17:03 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-24 12:17:03 +0900 |
| commit | b4544698d39d9e6995a32b41b33f327b9b0f3f82 (patch) | |
| tree | d1dc1e26f31f7672ff9ac41b5596907a5bd8e68e /src/librustdoc/html/render | |
| parent | 5321f9559bdb81fe0f2dda881bef2934ca65eba2 (diff) | |
| parent | 569096cbaffe39fbede339430c5ed8e80d991a80 (diff) | |
| download | rust-b4544698d39d9e6995a32b41b33f327b9b0f3f82.tar.gz rust-b4544698d39d9e6995a32b41b33f327b9b0f3f82.zip | |
Rollup merge of #84320 - jsha:details-implementors, r=Manishearth,Nemo157,GuillaumeGomez
Use details tag for trait implementors. Part of #83332 and following on from #83337 and #83355. This removes one category of JS-generated toggles (implementors), and replaces them with a `<details>` tag. This simplifies the JS, and fixes some bugs where things that were supposed to be hidden by the toggle were not hidden. Compare https://hoffman-andrews.com/rust/details-implementors/std/io/trait.Read.html#impl-Read vs https://doc.rust-lang.org/nightly/std/io/trait.Read.html#implementors. This introduces a `left: -23px` to put the toggle in the correct place, matching the current style for `.collapse-toggle`. It's worth noting this introduces a slight behavior change: since the entire line is now a `<summary>`, any part of the line is clickable. So for instance, in `impl Read for File`, clicking `impl` or `for` will collapse / expand the docs. Clicking `Read` or `File` still links to the appropriate documentation as before.
Diffstat (limited to 'src/librustdoc/html/render')
| -rw-r--r-- | src/librustdoc/html/render/mod.rs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index d773f37ad90..251185a9788 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1284,6 +1284,7 @@ fn render_impl( let cache = cx.cache(); let traits = &cache.traits; let trait_ = i.trait_did_full(cache).map(|did| &traits[&did]); + let mut close_tags = String::new(); if render_mode == RenderMode::Normal { let id = cx.derive_id(match i.inner_impl().trait_ { @@ -1302,7 +1303,12 @@ fn render_impl( format!(" aliases=\"{}\"", aliases.join(",")) }; if let Some(use_absolute) = use_absolute { - write!(w, "<h3 id=\"{}\" class=\"impl\"{}><code class=\"in-band\">", id, aliases); + write!( + w, + "<details class=\"rustdoc-toggle implementors-toggle\"><summary><h3 id=\"{}\" class=\"impl\"{}><code class=\"in-band\">", + id, aliases + ); + close_tags.insert_str(0, "</details>"); write!(w, "{}", i.inner_impl().print(use_absolute, cx)); if show_def_docs { for it in &i.inner_impl().items { @@ -1325,11 +1331,12 @@ fn render_impl( } else { write!( w, - "<h3 id=\"{}\" class=\"impl\"{}><code class=\"in-band\">{}</code>", + "<details class=\"rustdoc-toggle implementors-toggle\"><summary><h3 id=\"{}\" class=\"impl\"{}><code class=\"in-band\">{}</code>", id, aliases, i.inner_impl().print(false, cx) ); + close_tags.insert_str(0, "</details>"); } write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id); render_stability_since_raw( @@ -1341,6 +1348,7 @@ fn render_impl( ); write_srclink(cx, &i.impl_item, w); w.write_str("</h3>"); + w.write_str("</summary>"); if trait_.is_some() { if let Some(portability) = portability(&i.impl_item, Some(parent)) { @@ -1542,6 +1550,7 @@ fn render_impl( } w.write_str("<div class=\"impl-items\">"); + close_tags.insert_str(0, "</div>"); for trait_item in &i.inner_impl().items { doc_impl_item( w, @@ -1612,7 +1621,7 @@ fn render_impl( ); } } - w.write_str("</div>"); + w.write_str(&close_tags); } fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) { |
