Skip to content

Commit 0a297ac

Browse files
notriddlepietroalbini
authored andcommitted
Rustdoc accessibility: make the sidebar headers actual headers
Part of rust-lang#87059 Preview it at: https://notriddle.com/notriddle-rustdoc-test/rustdoc-sidebar-header/std/index.html
1 parent 2818e74 commit 0a297ac

File tree

3 files changed

+34
-29
lines changed

3 files changed

+34
-29
lines changed

src/librustdoc/html/render/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
527527
};
528528
let sidebar = if let Some(ref version) = self.cache.crate_version {
529529
format!(
530-
"<p class=\"location\">Crate {}</p>\
530+
"<h2 class=\"location\">Crate {}</h2>\
531531
<div class=\"block version\">\
532532
<p>Version {}</p>\
533533
</div>\
@@ -554,7 +554,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
554554
page.root_path = "./";
555555

556556
let mut style_files = self.shared.style_files.clone();
557-
let sidebar = "<p class=\"location\">Settings</p><div class=\"sidebar-elems\"></div>";
557+
let sidebar = "<h2 class=\"location\">Settings</h2><div class=\"sidebar-elems\"></div>";
558558
style_files.push(StylePath { path: PathBuf::from("settings.css"), disabled: false });
559559
let v = layout::render(
560560
&self.shared.layout,

src/librustdoc/html/render/mod.rs

+27-27
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,7 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
16901690
{
16911691
write!(
16921692
buffer,
1693-
"<p class=\"location\">{}{}</p>",
1693+
"<h2 class=\"location\">{}{}</h2>",
16941694
match *it.kind {
16951695
clean::StructItem(..) => "Struct ",
16961696
clean::TraitItem(..) => "Trait ",
@@ -1753,7 +1753,7 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
17531753
// to navigate the documentation (though slightly inefficiently).
17541754

17551755
if !it.is_mod() {
1756-
buffer.write_str("<p class=\"location\">Other items in<br>");
1756+
buffer.write_str("<h2 class=\"location\">Other items in<br>");
17571757
for (i, name) in cx.current.iter().take(parentlen).enumerate() {
17581758
if i > 0 {
17591759
buffer.write_str("::<wbr>");
@@ -1765,7 +1765,7 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
17651765
*name
17661766
);
17671767
}
1768-
buffer.write_str("</p>");
1768+
buffer.write_str("</h2>");
17691769
}
17701770

17711771
// Sidebar refers to the enclosing module, not this module.
@@ -1876,7 +1876,7 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
18761876
ret.sort();
18771877

18781878
out.push_str(
1879-
"<a class=\"sidebar-title\" href=\"#implementations\">Methods</a>\
1879+
"<h3 class=\"sidebar-title\"><a href=\"#implementations\">Methods</a></h3>\
18801880
<div class=\"sidebar-links\">",
18811881
);
18821882
for line in ret {
@@ -1941,24 +1941,24 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
19411941

19421942
if !concrete_format.is_empty() {
19431943
out.push_str(
1944-
"<a class=\"sidebar-title\" href=\"#trait-implementations\">\
1945-
Trait Implementations</a>",
1944+
"<h3 class=\"sidebar-title\"><a href=\"#trait-implementations\">\
1945+
Trait Implementations</a></h3>",
19461946
);
19471947
write_sidebar_links(out, concrete_format);
19481948
}
19491949

19501950
if !synthetic_format.is_empty() {
19511951
out.push_str(
1952-
"<a class=\"sidebar-title\" href=\"#synthetic-implementations\">\
1953-
Auto Trait Implementations</a>",
1952+
"<h3 class=\"sidebar-title\"><a href=\"#synthetic-implementations\">\
1953+
Auto Trait Implementations</a></h3>",
19541954
);
19551955
write_sidebar_links(out, synthetic_format);
19561956
}
19571957

19581958
if !blanket_format.is_empty() {
19591959
out.push_str(
1960-
"<a class=\"sidebar-title\" href=\"#blanket-implementations\">\
1961-
Blanket Implementations</a>",
1960+
"<h3 class=\"sidebar-title\"><a href=\"#blanket-implementations\">\
1961+
Blanket Implementations</a></h3>",
19621962
);
19631963
write_sidebar_links(out, blanket_format);
19641964
}
@@ -2010,7 +2010,7 @@ fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &V
20102010
if !ret.is_empty() {
20112011
write!(
20122012
out,
2013-
"<a class=\"sidebar-title\" href=\"#deref-methods\">Methods from {}&lt;Target={}&gt;</a>",
2013+
"<h3 class=\"sidebar-title\"><a href=\"#deref-methods\">Methods from {}&lt;Target={}&gt;</a></h3>",
20142014
Escape(&format!("{:#}", impl_.inner_impl().trait_.as_ref().unwrap().print(cx))),
20152015
Escape(&format!("{:#}", real_target.print(cx))),
20162016
);
@@ -2046,7 +2046,7 @@ fn sidebar_struct(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, s: &clea
20462046
if !fields.is_empty() {
20472047
if let CtorKind::Fictive = s.struct_type {
20482048
sidebar.push_str(
2049-
"<a class=\"sidebar-title\" href=\"#fields\">Fields</a>\
2049+
"<h3 class=\"sidebar-title\"><a href=\"#fields\">Fields</a></h3>\
20502050
<div class=\"sidebar-links\">",
20512051
);
20522052

@@ -2123,8 +2123,8 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
21232123
print_sidebar_section(
21242124
buf,
21252125
&t.items,
2126-
"<a class=\"sidebar-title\" href=\"#associated-types\">\
2127-
Associated Types</a><div class=\"sidebar-links\">",
2126+
"<h3 class=\"sidebar-title\"><a href=\"#associated-types\">\
2127+
Associated Types</a></h3><div class=\"sidebar-links\">",
21282128
|m| m.is_associated_type(),
21292129
|out, sym| write!(out, "<a href=\"#associatedtype.{0}\">{0}</a>", sym),
21302130
"</div>",
@@ -2133,8 +2133,8 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
21332133
print_sidebar_section(
21342134
buf,
21352135
&t.items,
2136-
"<a class=\"sidebar-title\" href=\"#associated-const\">\
2137-
Associated Constants</a><div class=\"sidebar-links\">",
2136+
"<h3 class=\"sidebar-title\"><a href=\"#associated-const\">\
2137+
Associated Constants</a></h3><div class=\"sidebar-links\">",
21382138
|m| m.is_associated_const(),
21392139
|out, sym| write!(out, "<a href=\"#associatedconstant.{0}\">{0}</a>", sym),
21402140
"</div>",
@@ -2143,8 +2143,8 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
21432143
print_sidebar_section(
21442144
buf,
21452145
&t.items,
2146-
"<a class=\"sidebar-title\" href=\"#required-methods\">\
2147-
Required Methods</a><div class=\"sidebar-links\">",
2146+
"<h3 class=\"sidebar-title\"><a href=\"#required-methods\">\
2147+
Required Methods</a></h3><div class=\"sidebar-links\">",
21482148
|m| m.is_ty_method(),
21492149
|out, sym| write!(out, "<a href=\"#tymethod.{0}\">{0}</a>", sym),
21502150
"</div>",
@@ -2153,8 +2153,8 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
21532153
print_sidebar_section(
21542154
buf,
21552155
&t.items,
2156-
"<a class=\"sidebar-title\" href=\"#provided-methods\">\
2157-
Provided Methods</a><div class=\"sidebar-links\">",
2156+
"<h3 class=\"sidebar-title\"><a href=\"#provided-methods\">\
2157+
Provided Methods</a></h3><div class=\"sidebar-links\">",
21582158
|m| m.is_method(),
21592159
|out, sym| write!(out, "<a href=\"#method.{0}\">{0}</a>", sym),
21602160
"</div>",
@@ -2176,8 +2176,8 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
21762176
if !res.is_empty() {
21772177
res.sort();
21782178
buf.push_str(
2179-
"<a class=\"sidebar-title\" href=\"#foreign-impls\">\
2180-
Implementations on Foreign Types</a>\
2179+
"<h3 class=\"sidebar-title\"><a href=\"#foreign-impls\">\
2180+
Implementations on Foreign Types</a></h3>\
21812181
<div class=\"sidebar-links\">",
21822182
);
21832183
for (name, id) in res.into_iter() {
@@ -2189,11 +2189,11 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
21892189

21902190
sidebar_assoc_items(cx, buf, it);
21912191

2192-
buf.push_str("<a class=\"sidebar-title\" href=\"#implementors\">Implementors</a>");
2192+
buf.push_str("<h3 class=\"sidebar-title\"><a href=\"#implementors\">Implementors</a></h3>");
21932193
if t.is_auto {
21942194
buf.push_str(
2195-
"<a class=\"sidebar-title\" \
2196-
href=\"#synthetic-implementors\">Auto Implementors</a>",
2195+
"<h3 class=\"sidebar-title\"><a \
2196+
href=\"#synthetic-implementors\">Auto Implementors</a></h3>",
21972197
);
21982198
}
21992199

@@ -2236,7 +2236,7 @@ fn sidebar_union(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, u: &clean
22362236

22372237
if !fields.is_empty() {
22382238
sidebar.push_str(
2239-
"<a class=\"sidebar-title\" href=\"#fields\">Fields</a>\
2239+
"<h3 class=\"sidebar-title\"><a href=\"#fields\">Fields</a></h3>\
22402240
<div class=\"sidebar-links\">",
22412241
);
22422242

@@ -2268,7 +2268,7 @@ fn sidebar_enum(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, e: &clean:
22682268
if !variants.is_empty() {
22692269
variants.sort_unstable();
22702270
sidebar.push_str(&format!(
2271-
"<a class=\"sidebar-title\" href=\"#variants\">Variants</a>\
2271+
"<h3 class=\"sidebar-title\"><a href=\"#variants\">Variants</a></h3>\
22722272
<div class=\"sidebar-links\">{}</div>",
22732273
variants.join(""),
22742274
));

src/librustdoc/html/static/rustdoc.css

+5
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,12 @@ nav.sub {
293293
.sidebar .location {
294294
border: 1px solid;
295295
font-size: 17px;
296+
font-weight: inherit;
296297
margin: 30px 10px 20px 10px;
297298
text-align: center;
298299
word-wrap: break-word;
300+
font-weight: inherit;
301+
padding: 0;
299302
}
300303

301304
.sidebar .version {
@@ -348,6 +351,8 @@ nav.sub {
348351
text-align: center;
349352
font-size: 17px;
350353
margin-bottom: 5px;
354+
font-weight: inherit;
355+
padding: 0;
351356
}
352357

353358
.sidebar-links {

0 commit comments

Comments
 (0)