Skip to content

Commit cdabdfa

Browse files
Simplify DOM by removing IDs for code tags
1 parent fc61cca commit cdabdfa

File tree

2 files changed

+16
-52
lines changed

2 files changed

+16
-52
lines changed

src/librustdoc/html/render.rs

+9-38
Original file line numberDiff line numberDiff line change
@@ -2586,8 +2586,7 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait)
25862586
let name = m.name.as_ref().unwrap();
25872587
let item_type = m.type_();
25882588
let id = cx.derive_id(format!("{}.{}", item_type, name));
2589-
let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space()));
2590-
write!(w, "<h3 id='{id}' class='method'><code id='{ns_id}'>", id = id, ns_id = ns_id);
2589+
write!(w, "<h3 id='{id}' class='method'><code>", id = id);
25912590
render_assoc_item(w, m, AssocItemLink::Anchor(Some(&id)), ItemType::Impl);
25922591
write!(w, "</code>");
25932592
render_stability_since(w, m, t);
@@ -2972,20 +2971,14 @@ fn item_struct(w: &mut Buffer, cx: &Context, it: &clean::Item, s: &clean::Struct
29722971
ItemType::StructField,
29732972
field.name.as_ref().unwrap()
29742973
));
2975-
let ns_id = cx.derive_id(format!(
2976-
"{}.{}",
2977-
field.name.as_ref().unwrap(),
2978-
ItemType::StructField.name_space()
2979-
));
29802974
write!(
29812975
w,
29822976
"<span id=\"{id}\" class=\"{item_type} small-section-header\">\
29832977
<a href=\"#{id}\" class=\"anchor field\"></a>\
2984-
<code id=\"{ns_id}\">{name}: {ty}</code>\
2978+
<code>{name}: {ty}</code>\
29852979
</span>",
29862980
item_type = ItemType::StructField,
29872981
id = id,
2988-
ns_id = ns_id,
29892982
name = field.name.as_ref().unwrap(),
29902983
ty = ty.print()
29912984
);
@@ -3103,18 +3096,12 @@ fn item_enum(w: &mut Buffer, cx: &Context, it: &clean::Item, e: &clean::Enum) {
31033096
for variant in &e.variants {
31043097
let id =
31053098
cx.derive_id(format!("{}.{}", ItemType::Variant, variant.name.as_ref().unwrap()));
3106-
let ns_id = cx.derive_id(format!(
3107-
"{}.{}",
3108-
variant.name.as_ref().unwrap(),
3109-
ItemType::Variant.name_space()
3110-
));
31113099
write!(
31123100
w,
31133101
"<div id=\"{id}\" class=\"variant small-section-header\">\
3114-
<a href=\"#{id}\" class=\"anchor field\"></a>\
3115-
<code id='{ns_id}'>{name}",
3102+
<a href=\"#{id}\" class=\"anchor field\"></a>\
3103+
<code>{name}",
31163104
id = id,
3117-
ns_id = ns_id,
31183105
name = variant.name.as_ref().unwrap()
31193106
);
31203107
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) {
31553142
variant.name.as_ref().unwrap(),
31563143
field.name.as_ref().unwrap()
31573144
));
3158-
let ns_id = cx.derive_id(format!(
3159-
"{}.{}.{}.{}",
3160-
variant.name.as_ref().unwrap(),
3161-
ItemType::Variant.name_space(),
3162-
field.name.as_ref().unwrap(),
3163-
ItemType::StructField.name_space()
3164-
));
31653145
write!(
31663146
w,
31673147
"<span id=\"{id}\" class=\"variant small-section-header\">\
31683148
<a href=\"#{id}\" class=\"anchor field\"></a>\
3169-
<code id='{ns_id}'>{f}:&nbsp;{t}\
3149+
<code>{f}:&nbsp;{t}\
31703150
</code></span>",
31713151
id = id,
3172-
ns_id = ns_id,
31733152
f = field.name.as_ref().unwrap(),
31743153
t = ty.print()
31753154
);
@@ -3661,9 +3640,7 @@ fn render_impl(
36613640
// Only render when the method is not static or we allow static methods
36623641
if render_method_item {
36633642
let id = cx.derive_id(format!("{}.{}", item_type, name));
3664-
let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space()));
3665-
write!(w, "<h4 id='{}' class=\"{}{}\">", id, item_type, extra_class);
3666-
write!(w, "<code id='{}'>", ns_id);
3643+
write!(w, "<h4 id='{}' class=\"{}{}\"><code>", id, item_type, extra_class);
36673644
render_assoc_item(w, item, link.anchor(&id), ItemType::Impl);
36683645
write!(w, "</code>");
36693646
render_stability_since_raw(w, item.stable_since(), outer_version);
@@ -3679,17 +3656,13 @@ fn render_impl(
36793656
}
36803657
clean::TypedefItem(ref tydef, _) => {
36813658
let id = cx.derive_id(format!("{}.{}", ItemType::AssocType, name));
3682-
let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space()));
3683-
write!(w, "<h4 id='{}' class=\"{}{}\">", id, item_type, extra_class);
3684-
write!(w, "<code id='{}'>", ns_id);
3659+
write!(w, "<h4 id='{}' class=\"{}{}\"><code>", id, item_type, extra_class);
36853660
assoc_type(w, item, &Vec::new(), Some(&tydef.type_), link.anchor(&id), "");
36863661
write!(w, "</code></h4>");
36873662
}
36883663
clean::AssocConstItem(ref ty, ref default) => {
36893664
let id = cx.derive_id(format!("{}.{}", item_type, name));
3690-
let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space()));
3691-
write!(w, "<h4 id='{}' class=\"{}{}\">", id, item_type, extra_class);
3692-
write!(w, "<code id='{}'>", ns_id);
3665+
write!(w, "<h4 id='{}' class=\"{}{}\"><code>", id, item_type, extra_class);
36933666
assoc_const(w, item, ty, default.as_ref(), link.anchor(&id), "");
36943667
write!(w, "</code>");
36953668
render_stability_since_raw(w, item.stable_since(), outer_version);
@@ -3704,9 +3677,7 @@ fn render_impl(
37043677
}
37053678
clean::AssocTypeItem(ref bounds, ref default) => {
37063679
let id = cx.derive_id(format!("{}.{}", item_type, name));
3707-
let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space()));
3708-
write!(w, "<h4 id='{}' class=\"{}{}\">", id, item_type, extra_class);
3709-
write!(w, "<code id='{}'>", ns_id);
3680+
write!(w, "<h4 id='{}' class=\"{}{}\"><code>", id, item_type, extra_class);
37103681
assoc_type(w, item, bounds, default.as_ref(), link.anchor(&id), "");
37113682
write!(w, "</code></h4>");
37123683
}

src/librustdoc/html/static/main.js

+7-14
Original file line numberDiff line numberDiff line change
@@ -306,14 +306,6 @@ function defocusSearchBar() {
306306
function expandSection(id) {
307307
var elem = document.getElementById(id);
308308
if (elem && isHidden(elem)) {
309-
if (elem.tagName === "CODE" && elem.parentNode.tagName === "H4") {
310-
// We are in a trait implementation, what we want is the parent.
311-
elem = elem.parentNode;
312-
if (elem.id !== null && elem.id.length > 0) {
313-
// Change the id to the parent which is "more clear" and better for users.
314-
window.location.hash = elem.id;
315-
}
316-
}
317309
var h3 = elem.parentNode.previousElementSibling;
318310
if (h3 && h3.tagName !== "H3") {
319311
h3 = h3.previousElementSibling; // skip div.docblock
@@ -2561,6 +2553,13 @@ function defocusSearchBar() {
25612553

25622554
onEachLazy(document.getElementsByClassName("docblock"), buildToggleWrapper);
25632555
onEachLazy(document.getElementsByClassName("sub-variant"), buildToggleWrapper);
2556+
var pageId = getPageId();
2557+
2558+
autoCollapse(pageId, getCurrentValue("rustdoc-collapse") === "true");
2559+
2560+
if (pageId !== null) {
2561+
expandSection(pageId);
2562+
}
25642563
}());
25652564

25662565
function createToggleWrapper(tog) {
@@ -2696,12 +2695,6 @@ function defocusSearchBar() {
26962695
hideSidebar();
26972696
};
26982697

2699-
autoCollapse(pageId, getCurrentValue("rustdoc-collapse") === "true");
2700-
2701-
if (pageId !== null) {
2702-
expandSection(pageId);
2703-
}
2704-
27052698
if (main) {
27062699
onEachLazy(main.getElementsByClassName("loading-content"), function(e) {
27072700
e.remove();

0 commit comments

Comments
 (0)