Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make h2 headings hyperlinks #92057

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ fn render_assoc_items_inner(
AssocItemRender::All => {
tmp_buf.write_str(
"<h2 id=\"implementations\" class=\"small-section-header\">\
Implementations<a href=\"#implementations\" class=\"anchor\"></a>\
<a href=\"#implementations\">Implementations</a>\
</h2>",
);
RenderMode::Normal
Expand All @@ -1068,8 +1068,8 @@ fn render_assoc_items_inner(
write!(
tmp_buf,
"<h2 id=\"{id}\" class=\"small-section-header\">\
<span>Methods from {trait_}&lt;Target = {type_}&gt;</span>\
<a href=\"#{id}\" class=\"anchor\"></a>\
<span>Methods from {trait_}&lt;Target = {type_}&gt;</span>\
</h2>",
id = id,
trait_ = trait_.print(cx),
Expand Down Expand Up @@ -1131,7 +1131,7 @@ fn render_assoc_items_inner(
write!(
w,
"<h2 id=\"trait-implementations\" class=\"small-section-header\">\
Trait Implementations<a href=\"#trait-implementations\" class=\"anchor\"></a>\
<a href=\"#trait-implementations\">Trait Implementations</a>\
</h2>\
<div id=\"trait-implementations-list\">{}</div>",
impls
Expand All @@ -1141,8 +1141,7 @@ fn render_assoc_items_inner(
if !synthetic.is_empty() {
w.write_str(
"<h2 id=\"synthetic-implementations\" class=\"small-section-header\">\
Auto Trait Implementations\
<a href=\"#synthetic-implementations\" class=\"anchor\"></a>\
<a href=\"#synthetic-implementations\">Auto Trait Implementations</a>\
</h2>\
<div id=\"synthetic-implementations-list\">",
);
Expand All @@ -1153,8 +1152,9 @@ fn render_assoc_items_inner(
if !blanket_impl.is_empty() {
w.write_str(
"<h2 id=\"blanket-implementations\" class=\"small-section-header\">\
Blanket Implementations\
<a href=\"#blanket-implementations\" class=\"anchor\"></a>\
<a href=\"#blanket-implementations\">\
Blanket Implementations\
</a>\
</h2>\
<div id=\"blanket-implementations-list\">",
);
Expand Down
11 changes: 6 additions & 5 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
write!(
w,
"<h2 id=\"{0}\" class=\"small-section-header\">\
{1}<a href=\"#{0}\" class=\"anchor\"></a>\
<a href=\"#{0}\">{1}</a>\
</h2>{2}",
id, title, extra_content
)
Expand Down Expand Up @@ -1001,7 +1001,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni
write!(
w,
"<h2 id=\"fields\" class=\"fields small-section-header\">\
Fields<a href=\"#fields\" class=\"anchor\"></a></h2>"
<a href=\"#fields\">Fields</a></h2>"
);
for (field, ty) in fields {
let name = field.name.as_ref().expect("union field name");
Expand Down Expand Up @@ -1108,7 +1108,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
write!(
w,
"<h2 id=\"variants\" class=\"variants small-section-header\">\
Variants{}<a href=\"#variants\" class=\"anchor\"></a></h2>",
<a href=\"#variants\">Variants{}</a></h2>",
document_non_exhaustive_header(it)
);
document_non_exhaustive(w, it);
Expand Down Expand Up @@ -1300,7 +1300,7 @@ fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
write!(
w,
"<h2 id=\"fields\" class=\"fields small-section-header\">\
{}{}<a href=\"#fields\" class=\"anchor\"></a>\
<a href=\"#fields\">{}{}</a>\
</h2>",
if let CtorKind::Fictive = s.struct_type { "Fields" } else { "Tuple Fields" },
document_non_exhaustive_header(it)
Expand Down Expand Up @@ -1732,7 +1732,8 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
return;
}

writeln!(w, "<h2 class=\"small-section-header\">Layout</h2>");
writeln!(w, "<h2 id=\"layout\" class=\"small-section-header\">");
writeln!(w, "<a href=\"#layout\">Layout</a></h2>");
writeln!(w, "<div class=\"docblock\">");

let tcx = cx.tcx();
Expand Down
6 changes: 6 additions & 0 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -1129,13 +1129,19 @@ a.test-arrow:hover{
text-decoration: none;
}

.small-section-header:hover > a:before,
.section-header:hover a:before {
position: absolute;
left: -25px;
padding-right: 10px; /* avoid gap that causes hover to disappear */
content: '\2002\00a7\2002';
}

#deref-methods-str > a.anchor:before {
position: relative;
left: -0.5em;
}

.section-header:hover a {
text-decoration: none;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-gui/anchors.goml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ assert-css: (".in-band a", {"color": "rgb(0, 0, 0)"})

// We move the cursor over the "Implementations" title so the anchor is displayed.
move-cursor-to: "h2#implementations"
assert-css: ("h2#implementations a.anchor", {"color": "rgb(0, 0, 0)"})
assert-css: ("h2#implementations", {"color": "rgb(0, 0, 0)"})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's supposed to check that the anchor is displayed, which isn't tested here.


// Same thing with the impl block title.
move-cursor-to: "#impl"
Expand Down