Simplify DOM by removing IDs for code tags
This commit is contained in:
parent
fc61cca41c
commit
cdabdfa104
2 changed files with 16 additions and 52 deletions
|
@ -2586,8 +2586,7 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait)
|
|||
let name = m.name.as_ref().unwrap();
|
||||
let item_type = m.type_();
|
||||
let id = cx.derive_id(format!("{}.{}", item_type, name));
|
||||
let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space()));
|
||||
write!(w, "<h3 id='{id}' class='method'><code id='{ns_id}'>", id = id, ns_id = ns_id);
|
||||
write!(w, "<h3 id='{id}' class='method'><code>", id = id);
|
||||
render_assoc_item(w, m, AssocItemLink::Anchor(Some(&id)), ItemType::Impl);
|
||||
write!(w, "</code>");
|
||||
render_stability_since(w, m, t);
|
||||
|
@ -2972,20 +2971,14 @@ fn item_struct(w: &mut Buffer, cx: &Context, it: &clean::Item, s: &clean::Struct
|
|||
ItemType::StructField,
|
||||
field.name.as_ref().unwrap()
|
||||
));
|
||||
let ns_id = cx.derive_id(format!(
|
||||
"{}.{}",
|
||||
field.name.as_ref().unwrap(),
|
||||
ItemType::StructField.name_space()
|
||||
));
|
||||
write!(
|
||||
w,
|
||||
"<span id=\"{id}\" class=\"{item_type} small-section-header\">\
|
||||
<a href=\"#{id}\" class=\"anchor field\"></a>\
|
||||
<code id=\"{ns_id}\">{name}: {ty}</code>\
|
||||
<code>{name}: {ty}</code>\
|
||||
</span>",
|
||||
item_type = ItemType::StructField,
|
||||
id = id,
|
||||
ns_id = ns_id,
|
||||
name = field.name.as_ref().unwrap(),
|
||||
ty = ty.print()
|
||||
);
|
||||
|
@ -3103,18 +3096,12 @@ fn item_enum(w: &mut Buffer, cx: &Context, it: &clean::Item, e: &clean::Enum) {
|
|||
for variant in &e.variants {
|
||||
let id =
|
||||
cx.derive_id(format!("{}.{}", ItemType::Variant, variant.name.as_ref().unwrap()));
|
||||
let ns_id = cx.derive_id(format!(
|
||||
"{}.{}",
|
||||
variant.name.as_ref().unwrap(),
|
||||
ItemType::Variant.name_space()
|
||||
));
|
||||
write!(
|
||||
w,
|
||||
"<div id=\"{id}\" class=\"variant small-section-header\">\
|
||||
<a href=\"#{id}\" class=\"anchor field\"></a>\
|
||||
<code id='{ns_id}'>{name}",
|
||||
<code>{name}",
|
||||
id = id,
|
||||
ns_id = ns_id,
|
||||
name = variant.name.as_ref().unwrap()
|
||||
);
|
||||
if let clean::VariantItem(ref var) = variant.inner {
|
||||
|
@ -3155,21 +3142,13 @@ fn item_enum(w: &mut Buffer, cx: &Context, it: &clean::Item, e: &clean::Enum) {
|
|||
variant.name.as_ref().unwrap(),
|
||||
field.name.as_ref().unwrap()
|
||||
));
|
||||
let ns_id = cx.derive_id(format!(
|
||||
"{}.{}.{}.{}",
|
||||
variant.name.as_ref().unwrap(),
|
||||
ItemType::Variant.name_space(),
|
||||
field.name.as_ref().unwrap(),
|
||||
ItemType::StructField.name_space()
|
||||
));
|
||||
write!(
|
||||
w,
|
||||
"<span id=\"{id}\" class=\"variant small-section-header\">\
|
||||
<a href=\"#{id}\" class=\"anchor field\"></a>\
|
||||
<code id='{ns_id}'>{f}: {t}\
|
||||
<code>{f}: {t}\
|
||||
</code></span>",
|
||||
id = id,
|
||||
ns_id = ns_id,
|
||||
f = field.name.as_ref().unwrap(),
|
||||
t = ty.print()
|
||||
);
|
||||
|
@ -3661,9 +3640,7 @@ fn render_impl(
|
|||
// Only render when the method is not static or we allow static methods
|
||||
if render_method_item {
|
||||
let id = cx.derive_id(format!("{}.{}", item_type, name));
|
||||
let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space()));
|
||||
write!(w, "<h4 id='{}' class=\"{}{}\">", id, item_type, extra_class);
|
||||
write!(w, "<code id='{}'>", ns_id);
|
||||
write!(w, "<h4 id='{}' class=\"{}{}\"><code>", id, item_type, extra_class);
|
||||
render_assoc_item(w, item, link.anchor(&id), ItemType::Impl);
|
||||
write!(w, "</code>");
|
||||
render_stability_since_raw(w, item.stable_since(), outer_version);
|
||||
|
@ -3679,17 +3656,13 @@ fn render_impl(
|
|||
}
|
||||
clean::TypedefItem(ref tydef, _) => {
|
||||
let id = cx.derive_id(format!("{}.{}", ItemType::AssocType, name));
|
||||
let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space()));
|
||||
write!(w, "<h4 id='{}' class=\"{}{}\">", id, item_type, extra_class);
|
||||
write!(w, "<code id='{}'>", ns_id);
|
||||
write!(w, "<h4 id='{}' class=\"{}{}\"><code>", id, item_type, extra_class);
|
||||
assoc_type(w, item, &Vec::new(), Some(&tydef.type_), link.anchor(&id), "");
|
||||
write!(w, "</code></h4>");
|
||||
}
|
||||
clean::AssocConstItem(ref ty, ref default) => {
|
||||
let id = cx.derive_id(format!("{}.{}", item_type, name));
|
||||
let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space()));
|
||||
write!(w, "<h4 id='{}' class=\"{}{}\">", id, item_type, extra_class);
|
||||
write!(w, "<code id='{}'>", ns_id);
|
||||
write!(w, "<h4 id='{}' class=\"{}{}\"><code>", id, item_type, extra_class);
|
||||
assoc_const(w, item, ty, default.as_ref(), link.anchor(&id), "");
|
||||
write!(w, "</code>");
|
||||
render_stability_since_raw(w, item.stable_since(), outer_version);
|
||||
|
@ -3704,9 +3677,7 @@ fn render_impl(
|
|||
}
|
||||
clean::AssocTypeItem(ref bounds, ref default) => {
|
||||
let id = cx.derive_id(format!("{}.{}", item_type, name));
|
||||
let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space()));
|
||||
write!(w, "<h4 id='{}' class=\"{}{}\">", id, item_type, extra_class);
|
||||
write!(w, "<code id='{}'>", ns_id);
|
||||
write!(w, "<h4 id='{}' class=\"{}{}\"><code>", id, item_type, extra_class);
|
||||
assoc_type(w, item, bounds, default.as_ref(), link.anchor(&id), "");
|
||||
write!(w, "</code></h4>");
|
||||
}
|
||||
|
|
|
@ -306,14 +306,6 @@ function defocusSearchBar() {
|
|||
function expandSection(id) {
|
||||
var elem = document.getElementById(id);
|
||||
if (elem && isHidden(elem)) {
|
||||
if (elem.tagName === "CODE" && elem.parentNode.tagName === "H4") {
|
||||
// We are in a trait implementation, what we want is the parent.
|
||||
elem = elem.parentNode;
|
||||
if (elem.id !== null && elem.id.length > 0) {
|
||||
// Change the id to the parent which is "more clear" and better for users.
|
||||
window.location.hash = elem.id;
|
||||
}
|
||||
}
|
||||
var h3 = elem.parentNode.previousElementSibling;
|
||||
if (h3 && h3.tagName !== "H3") {
|
||||
h3 = h3.previousElementSibling; // skip div.docblock
|
||||
|
@ -2561,6 +2553,13 @@ function defocusSearchBar() {
|
|||
|
||||
onEachLazy(document.getElementsByClassName("docblock"), buildToggleWrapper);
|
||||
onEachLazy(document.getElementsByClassName("sub-variant"), buildToggleWrapper);
|
||||
var pageId = getPageId();
|
||||
|
||||
autoCollapse(pageId, getCurrentValue("rustdoc-collapse") === "true");
|
||||
|
||||
if (pageId !== null) {
|
||||
expandSection(pageId);
|
||||
}
|
||||
}());
|
||||
|
||||
function createToggleWrapper(tog) {
|
||||
|
@ -2696,12 +2695,6 @@ function defocusSearchBar() {
|
|||
hideSidebar();
|
||||
};
|
||||
|
||||
autoCollapse(pageId, getCurrentValue("rustdoc-collapse") === "true");
|
||||
|
||||
if (pageId !== null) {
|
||||
expandSection(pageId);
|
||||
}
|
||||
|
||||
if (main) {
|
||||
onEachLazy(main.getElementsByClassName("loading-content"), function(e) {
|
||||
e.remove();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue