Auto merge of #85074 - GuillaumeGomez:end-toggle-migration, r=jsha

Migrate top doc and non-exhaustive toggles to details tag

Fixes #83332.

r? `@jsha`
This commit is contained in:
bors 2021-05-10 04:05:55 +00:00
commit 00f2bf40d6
5 changed files with 78 additions and 227 deletions

View file

@ -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));
}
}
}

View file

@ -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>");
}
}