diff options
Diffstat (limited to 'src/librustdoc/html/render')
| -rw-r--r-- | src/librustdoc/html/render/mod.rs | 23 | ||||
| -rw-r--r-- | src/librustdoc/html/render/print_item.rs | 28 |
2 files changed, 38 insertions, 13 deletions
diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index ea57831c0e5..5b54b32e4dd 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -509,7 +509,7 @@ fn document(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, parent: Option info!("Documenting {}", name); } document_item_info(w, cx, item, parent); - document_full(w, item, cx); + document_full_collapsible(w, item, cx); } /// Render md_text as markdown. @@ -561,10 +561,29 @@ fn document_short( } } +fn document_full_collapsible(w: &mut Buffer, item: &clean::Item, cx: &Context<'_>) { + document_full_inner(w, item, cx, true); +} + fn document_full(w: &mut Buffer, item: &clean::Item, cx: &Context<'_>) { + document_full_inner(w, item, cx, false); +} + +fn document_full_inner(w: &mut Buffer, item: &clean::Item, cx: &Context<'_>, is_collapsible: bool) { if let Some(s) = cx.shared.maybe_collapsed_doc_value(item) { debug!("Doc block: =====\n{}\n=====", s); - render_markdown(w, cx, &s, item.links(cx)); + if is_collapsible { + w.write_str( + "<details class=\"rustdoc-toggle top-doc\" open>\ + <summary class=\"hideme\">\ + <span>Expand description</span>\ + </summary>", + ); + render_markdown(w, cx, &s, item.links(cx)); + w.write_str("</details>"); + } else { + render_markdown(w, cx, &s, item.links(cx)); + } } } diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 70b5458ece8..ea97091ffcb 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -1464,17 +1464,23 @@ fn document_non_exhaustive_header(item: &clean::Item) -> &str { fn document_non_exhaustive(w: &mut Buffer, item: &clean::Item) { if item.is_non_exhaustive() { - write!(w, "<div class=\"docblock non-exhaustive non-exhaustive-{}\">", { - if item.is_struct() { - "struct" - } else if item.is_enum() { - "enum" - } else if item.is_variant() { - "variant" - } else { - "type" + write!( + w, + "<details class=\"rustdoc-toggle non-exhaustive\">\ + <summary class=\"hideme\"><span>{}</span></summary>\ + <div class=\"docblock\">", + { + if item.is_struct() { + "This struct is marked as non-exhaustive" + } else if item.is_enum() { + "This enum is marked as non-exhaustive" + } else if item.is_variant() { + "This variant is marked as non-exhaustive" + } else { + "This type is marked as non-exhaustive" + } } - }); + ); if item.is_struct() { w.write_str( @@ -1502,6 +1508,6 @@ fn document_non_exhaustive(w: &mut Buffer, item: &clean::Item) { ); } - w.write_str("</div>"); + w.write_str("</div></details>"); } } |
