Skip to content

Commit f19548b

Browse files
committed
Make h2 headings hyperlinks
1 parent 03360be commit f19548b

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

src/librustdoc/html/render/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ fn render_assoc_items_inner(
10541054
AssocItemRender::All => {
10551055
tmp_buf.write_str(
10561056
"<h2 id=\"implementations\" class=\"small-section-header\">\
1057-
Implementations<a href=\"#implementations\" class=\"anchor\"></a>\
1057+
<a href=\"#implementations\">Implementations</a>\
10581058
</h2>",
10591059
);
10601060
RenderMode::Normal
@@ -1068,8 +1068,8 @@ fn render_assoc_items_inner(
10681068
write!(
10691069
tmp_buf,
10701070
"<h2 id=\"{id}\" class=\"small-section-header\">\
1071-
<span>Methods from {trait_}&lt;Target = {type_}&gt;</span>\
10721071
<a href=\"#{id}\" class=\"anchor\"></a>\
1072+
<span>Methods from {trait_}&lt;Target = {type_}&gt;</span>\
10731073
</h2>",
10741074
id = id,
10751075
trait_ = trait_.print(cx),
@@ -1131,7 +1131,7 @@ fn render_assoc_items_inner(
11311131
write!(
11321132
w,
11331133
"<h2 id=\"trait-implementations\" class=\"small-section-header\">\
1134-
Trait Implementations<a href=\"#trait-implementations\" class=\"anchor\"></a>\
1134+
<a href=\"#trait-implementations\">Trait Implementations</a>\
11351135
</h2>\
11361136
<div id=\"trait-implementations-list\">{}</div>",
11371137
impls
@@ -1141,8 +1141,7 @@ fn render_assoc_items_inner(
11411141
if !synthetic.is_empty() {
11421142
w.write_str(
11431143
"<h2 id=\"synthetic-implementations\" class=\"small-section-header\">\
1144-
Auto Trait Implementations\
1145-
<a href=\"#synthetic-implementations\" class=\"anchor\"></a>\
1144+
<a href=\"#synthetic-implementations\">Auto Trait Implementations</a>\
11461145
</h2>\
11471146
<div id=\"synthetic-implementations-list\">",
11481147
);
@@ -1153,8 +1152,9 @@ fn render_assoc_items_inner(
11531152
if !blanket_impl.is_empty() {
11541153
w.write_str(
11551154
"<h2 id=\"blanket-implementations\" class=\"small-section-header\">\
1156-
Blanket Implementations\
1157-
<a href=\"#blanket-implementations\" class=\"anchor\"></a>\
1155+
<a href=\"#blanket-implementations\">\
1156+
Blanket Implementations\
1157+
</a>\
11581158
</h2>\
11591159
<div id=\"blanket-implementations-list\">",
11601160
);

src/librustdoc/html/render/print_item.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
660660
write!(
661661
w,
662662
"<h2 id=\"{0}\" class=\"small-section-header\">\
663-
{1}<a href=\"#{0}\" class=\"anchor\"></a>\
663+
<a href=\"#{0}\">{1}</a>\
664664
</h2>{2}",
665665
id, title, extra_content
666666
)
@@ -1001,7 +1001,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni
10011001
write!(
10021002
w,
10031003
"<h2 id=\"fields\" class=\"fields small-section-header\">\
1004-
Fields<a href=\"#fields\" class=\"anchor\"></a></h2>"
1004+
<a href=\"#fields\">Fields</a></h2>"
10051005
);
10061006
for (field, ty) in fields {
10071007
let name = field.name.as_ref().expect("union field name");
@@ -1108,7 +1108,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
11081108
write!(
11091109
w,
11101110
"<h2 id=\"variants\" class=\"variants small-section-header\">\
1111-
Variants{}<a href=\"#variants\" class=\"anchor\"></a></h2>",
1111+
<a href=\"#variants\">Variants{}</a></h2>",
11121112
document_non_exhaustive_header(it)
11131113
);
11141114
document_non_exhaustive(w, it);
@@ -1300,7 +1300,7 @@ fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
13001300
write!(
13011301
w,
13021302
"<h2 id=\"fields\" class=\"fields small-section-header\">\
1303-
{}{}<a href=\"#fields\" class=\"anchor\"></a>\
1303+
<a href=\"#fields\">{}{}</a>\
13041304
</h2>",
13051305
if let CtorKind::Fictive = s.struct_type { "Fields" } else { "Tuple Fields" },
13061306
document_non_exhaustive_header(it)
@@ -1732,7 +1732,8 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
17321732
return;
17331733
}
17341734

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

17381739
let tcx = cx.tcx();

src/librustdoc/html/static/css/rustdoc.css

+6
Original file line numberDiff line numberDiff line change
@@ -1129,13 +1129,19 @@ a.test-arrow:hover{
11291129
text-decoration: none;
11301130
}
11311131

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

1140+
#deref-methods-str > a.anchor:before {
1141+
position: relative;
1142+
left: -0.5em;
1143+
}
1144+
11391145
.section-header:hover a {
11401146
text-decoration: none;
11411147
}

src/test/rustdoc-gui/anchors.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ assert-css: (".in-band a", {"color": "rgb(0, 0, 0)"})
2323

2424
// We move the cursor over the "Implementations" title so the anchor is displayed.
2525
move-cursor-to: "h2#implementations"
26-
assert-css: ("h2#implementations a.anchor", {"color": "rgb(0, 0, 0)"})
26+
assert-css: ("h2#implementations", {"color": "rgb(0, 0, 0)"})
2727

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

0 commit comments

Comments
 (0)