Skip to content

Commit a337156

Browse files
authored
Rollup merge of #104772 - GuillaumeGomez:small-accessibility-improvement, r=notriddle
Small accessibility improvements From this [reddit post](https://www.reddit.com/r/rust/comments/z1gyz7/accessible_documentation/), I started to check a bit how to improve accessibility and how we could add test for it. So these two fixes come from the use of the [pa11y tool](https://github.com/pa11y/pa11y). To make it work, I had to update its puppeteer version to the last one but otherwise it seems to be quite nice. I didn't fix all the errors it reported because they were about colors. To get the same result as mine, you can use this config: ```json { "ignore": [ "WCAG2AA.Principle1.Guideline1_4.1_4_3.G18.Fail", "WCAG2AA.Principle3.Guideline3_2.3_2_2.H32.2" ] } ``` I think trying to improve accessibility is something we should definitely aim for. I'll try to integrate a tool to enforce this check (very likely `pa11y`) directly into the CI. cc ``@jsha`` r? ``@notriddle``
2 parents 84ff4ab + aa73e29 commit a337156

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

src/librustdoc/html/render/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ fn write_impl_section_heading(w: &mut Buffer, title: &str, id: &str) {
10711071
w,
10721072
"<h2 id=\"{id}\" class=\"small-section-header\">\
10731073
{title}\
1074-
<a href=\"#{id}\" class=\"anchor\"></a>\
1074+
<a href=\"#{id}\" class=\"anchor\">§</a>\
10751075
</h2>"
10761076
);
10771077
}
@@ -1536,7 +1536,7 @@ fn render_impl(
15361536
render_rightside(w, cx, item, containing_item, render_mode);
15371537
if trait_.is_some() {
15381538
// Anchors are only used on trait impls.
1539-
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
1539+
write!(w, "<a href=\"#{}\" class=\"anchor\">§</a>", id);
15401540
}
15411541
w.write_str("<h4 class=\"code-header\">");
15421542
render_assoc_item(
@@ -1562,7 +1562,7 @@ fn render_impl(
15621562
render_rightside(w, cx, item, containing_item, render_mode);
15631563
if trait_.is_some() {
15641564
// Anchors are only used on trait impls.
1565-
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
1565+
write!(w, "<a href=\"#{}\" class=\"anchor\">§</a>", id);
15661566
}
15671567
w.write_str("<h4 class=\"code-header\">");
15681568
assoc_const(
@@ -1587,7 +1587,7 @@ fn render_impl(
15871587
write!(w, "<section id=\"{}\" class=\"{}{}\">", id, item_type, in_trait_class);
15881588
if trait_.is_some() {
15891589
// Anchors are only used on trait impls.
1590-
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
1590+
write!(w, "<a href=\"#{}\" class=\"anchor\">§</a>", id);
15911591
}
15921592
w.write_str("<h4 class=\"code-header\">");
15931593
assoc_type(
@@ -1613,7 +1613,7 @@ fn render_impl(
16131613
);
16141614
if trait_.is_some() {
16151615
// Anchors are only used on trait impls.
1616-
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
1616+
write!(w, "<a href=\"#{}\" class=\"anchor\">§</a>", id);
16171617
}
16181618
w.write_str("<h4 class=\"code-header\">");
16191619
assoc_type(
@@ -1846,7 +1846,7 @@ pub(crate) fn render_impl_summary(
18461846
};
18471847
write!(w, "<section id=\"{}\" class=\"impl has-srclink\"{}>", id, aliases);
18481848
render_rightside(w, cx, &i.impl_item, containing_item, RenderMode::Normal);
1849-
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
1849+
write!(w, "<a href=\"#{}\" class=\"anchor\">§</a>", id);
18501850
write!(w, "<h3 class=\"code-header\">");
18511851

18521852
if let Some(use_absolute) = use_absolute {

src/librustdoc/html/render/print_item.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
717717
write!(
718718
w,
719719
"<h2 id=\"{0}\" class=\"small-section-header\">\
720-
{1}<a href=\"#{0}\" class=\"anchor\"></a>\
720+
{1}<a href=\"#{0}\" class=\"anchor\">§</a>\
721721
</h2>{2}",
722722
id, title, extra_content
723723
)
@@ -1147,7 +1147,7 @@ fn item_union(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean:
11471147
write!(
11481148
w,
11491149
"<h2 id=\"fields\" class=\"fields small-section-header\">\
1150-
Fields<a href=\"#fields\" class=\"anchor\"></a>\
1150+
Fields<a href=\"#fields\" class=\"anchor\">§</a>\
11511151
</h2>"
11521152
);
11531153
for (field, ty) in fields {
@@ -1156,7 +1156,7 @@ fn item_union(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean:
11561156
write!(
11571157
w,
11581158
"<span id=\"{id}\" class=\"{shortty} small-section-header\">\
1159-
<a href=\"#{id}\" class=\"anchor field\"></a>\
1159+
<a href=\"#{id}\" class=\"anchor field\">§</a>\
11601160
<code>{name}: {ty}</code>\
11611161
</span>",
11621162
id = id,
@@ -1262,7 +1262,7 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
12621262
write!(
12631263
w,
12641264
"<h2 id=\"variants\" class=\"variants small-section-header\">\
1265-
Variants{}<a href=\"#variants\" class=\"anchor\"></a>\
1265+
Variants{}<a href=\"#variants\" class=\"anchor\">§</a>\
12661266
</h2>",
12671267
document_non_exhaustive_header(it)
12681268
);
@@ -1273,7 +1273,7 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
12731273
write!(
12741274
w,
12751275
"<section id=\"{id}\" class=\"variant\">\
1276-
<a href=\"#{id}\" class=\"anchor\"></a>",
1276+
<a href=\"#{id}\" class=\"anchor\">§</a>",
12771277
id = id,
12781278
);
12791279
render_stability_since_raw_with_extra(
@@ -1325,7 +1325,7 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
13251325
w,
13261326
"<div class=\"sub-variant-field\">\
13271327
<span id=\"{id}\" class=\"small-section-header\">\
1328-
<a href=\"#{id}\" class=\"anchor field\"></a>\
1328+
<a href=\"#{id}\" class=\"anchor field\">§</a>\
13291329
<code>{f}:&nbsp;{t}</code>\
13301330
</span>",
13311331
id = id,
@@ -1477,7 +1477,7 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean
14771477
write!(
14781478
w,
14791479
"<h2 id=\"fields\" class=\"fields small-section-header\">\
1480-
{}{}<a href=\"#fields\" class=\"anchor\"></a>\
1480+
{}{}<a href=\"#fields\" class=\"anchor\">§</a>\
14811481
</h2>",
14821482
if s.ctor_kind.is_none() { "Fields" } else { "Tuple Fields" },
14831483
document_non_exhaustive_header(it)
@@ -1490,7 +1490,7 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean
14901490
write!(
14911491
w,
14921492
"<span id=\"{id}\" class=\"{item_type} small-section-header\">\
1493-
<a href=\"#{id}\" class=\"anchor field\"></a>\
1493+
<a href=\"#{id}\" class=\"anchor field\">§</a>\
14941494
<code>{name}: {ty}</code>\
14951495
</span>",
14961496
item_type = ItemType::StructField,
@@ -1908,7 +1908,7 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) {
19081908
writeln!(
19091909
w,
19101910
"<h2 id=\"layout\" class=\"small-section-header\"> \
1911-
Layout<a href=\"#layout\" class=\"anchor\"></a></h2>"
1911+
Layout<a href=\"#layout\" class=\"anchor\">§</a></h2>"
19121912
);
19131913
writeln!(w, "<div class=\"docblock\">");
19141914

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

-3
Original file line numberDiff line numberDiff line change
@@ -730,9 +730,6 @@ a {
730730
h2.small-section-header > .anchor {
731731
padding-right: 6px;
732732
}
733-
.anchor::before {
734-
content: '§';
735-
}
736733

737734
.main-heading a:hover,
738735
.example-wrap > pre.rust a:hover,

src/librustdoc/html/templates/page.html

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ <h2></h2> {#- -#}
115115
<input {# -#}
116116
class="search-input" {# -#}
117117
name="search" {# -#}
118+
aria-label="Run search in the documentation" {# -#}
118119
autocomplete="off" {# -#}
119120
spellcheck="false" {# -#}
120121
placeholder="Click or press ‘S’ to search, ‘?’ for more options…" {# -#}

0 commit comments

Comments
 (0)