diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-11-24 08:42:36 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-24 08:42:36 +0100 |
| commit | a3371560ee465fb3a1d142b1f2672770887d3dd8 (patch) | |
| tree | f811cf77d1ecdd6b33f807717853ffc7e2f150d3 | |
| parent | 84ff4ab5a238558a009e1cc6f375b0922053b95b (diff) | |
| parent | aa73e29799456739128734b773d019c412d840c1 (diff) | |
| download | rust-a3371560ee465fb3a1d142b1f2672770887d3dd8.tar.gz rust-a3371560ee465fb3a1d142b1f2672770887d3dd8.zip | |
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``
| -rw-r--r-- | src/librustdoc/html/render/mod.rs | 12 | ||||
| -rw-r--r-- | src/librustdoc/html/render/print_item.rs | 18 | ||||
| -rw-r--r-- | src/librustdoc/html/static/css/rustdoc.css | 3 | ||||
| -rw-r--r-- | src/librustdoc/html/templates/page.html | 1 |
4 files changed, 16 insertions, 18 deletions
diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index d12874e1bfd..ef28e2a855a 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1071,7 +1071,7 @@ fn write_impl_section_heading(w: &mut Buffer, title: &str, id: &str) { w, "<h2 id=\"{id}\" class=\"small-section-header\">\ {title}\ - <a href=\"#{id}\" class=\"anchor\"></a>\ + <a href=\"#{id}\" class=\"anchor\">§</a>\ </h2>" ); } @@ -1536,7 +1536,7 @@ fn render_impl( render_rightside(w, cx, item, containing_item, render_mode); if trait_.is_some() { // Anchors are only used on trait impls. - write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id); + write!(w, "<a href=\"#{}\" class=\"anchor\">§</a>", id); } w.write_str("<h4 class=\"code-header\">"); render_assoc_item( @@ -1562,7 +1562,7 @@ fn render_impl( render_rightside(w, cx, item, containing_item, render_mode); if trait_.is_some() { // Anchors are only used on trait impls. - write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id); + write!(w, "<a href=\"#{}\" class=\"anchor\">§</a>", id); } w.write_str("<h4 class=\"code-header\">"); assoc_const( @@ -1587,7 +1587,7 @@ fn render_impl( write!(w, "<section id=\"{}\" class=\"{}{}\">", id, item_type, in_trait_class); if trait_.is_some() { // Anchors are only used on trait impls. - write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id); + write!(w, "<a href=\"#{}\" class=\"anchor\">§</a>", id); } w.write_str("<h4 class=\"code-header\">"); assoc_type( @@ -1613,7 +1613,7 @@ fn render_impl( ); if trait_.is_some() { // Anchors are only used on trait impls. - write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id); + write!(w, "<a href=\"#{}\" class=\"anchor\">§</a>", id); } w.write_str("<h4 class=\"code-header\">"); assoc_type( @@ -1846,7 +1846,7 @@ pub(crate) fn render_impl_summary( }; write!(w, "<section id=\"{}\" class=\"impl has-srclink\"{}>", id, aliases); render_rightside(w, cx, &i.impl_item, containing_item, RenderMode::Normal); - write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id); + write!(w, "<a href=\"#{}\" class=\"anchor\">§</a>", id); write!(w, "<h3 class=\"code-header\">"); if let Some(use_absolute) = use_absolute { diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index a0e5309a70c..0f9b3b15c77 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -717,7 +717,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean: write!( w, "<h2 id=\"{0}\" class=\"small-section-header\">\ - {1}<a href=\"#{0}\" class=\"anchor\"></a>\ + {1}<a href=\"#{0}\" class=\"anchor\">§</a>\ </h2>{2}", id, title, extra_content ) @@ -1147,7 +1147,7 @@ fn item_union(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean: write!( w, "<h2 id=\"fields\" class=\"fields small-section-header\">\ - Fields<a href=\"#fields\" class=\"anchor\"></a>\ + Fields<a href=\"#fields\" class=\"anchor\">§</a>\ </h2>" ); for (field, ty) in fields { @@ -1156,7 +1156,7 @@ fn item_union(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean: write!( w, "<span id=\"{id}\" class=\"{shortty} small-section-header\">\ - <a href=\"#{id}\" class=\"anchor field\"></a>\ + <a href=\"#{id}\" class=\"anchor field\">§</a>\ <code>{name}: {ty}</code>\ </span>", id = id, @@ -1262,7 +1262,7 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean:: write!( w, "<h2 id=\"variants\" class=\"variants small-section-header\">\ - Variants{}<a href=\"#variants\" class=\"anchor\"></a>\ + Variants{}<a href=\"#variants\" class=\"anchor\">§</a>\ </h2>", document_non_exhaustive_header(it) ); @@ -1273,7 +1273,7 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean:: write!( w, "<section id=\"{id}\" class=\"variant\">\ - <a href=\"#{id}\" class=\"anchor\"></a>", + <a href=\"#{id}\" class=\"anchor\">§</a>", id = id, ); render_stability_since_raw_with_extra( @@ -1325,7 +1325,7 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean:: w, "<div class=\"sub-variant-field\">\ <span id=\"{id}\" class=\"small-section-header\">\ - <a href=\"#{id}\" class=\"anchor field\"></a>\ + <a href=\"#{id}\" class=\"anchor field\">§</a>\ <code>{f}: {t}</code>\ </span>", id = id, @@ -1477,7 +1477,7 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean write!( w, "<h2 id=\"fields\" class=\"fields small-section-header\">\ - {}{}<a href=\"#fields\" class=\"anchor\"></a>\ + {}{}<a href=\"#fields\" class=\"anchor\">§</a>\ </h2>", if s.ctor_kind.is_none() { "Fields" } else { "Tuple Fields" }, document_non_exhaustive_header(it) @@ -1490,7 +1490,7 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean write!( w, "<span id=\"{id}\" class=\"{item_type} small-section-header\">\ - <a href=\"#{id}\" class=\"anchor field\"></a>\ + <a href=\"#{id}\" class=\"anchor field\">§</a>\ <code>{name}: {ty}</code>\ </span>", item_type = ItemType::StructField, @@ -1908,7 +1908,7 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) { writeln!( w, "<h2 id=\"layout\" class=\"small-section-header\"> \ - Layout<a href=\"#layout\" class=\"anchor\"></a></h2>" + Layout<a href=\"#layout\" class=\"anchor\">§</a></h2>" ); writeln!(w, "<div class=\"docblock\">"); diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 63530b924c2..e0a4f2364b6 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -730,9 +730,6 @@ a { h2.small-section-header > .anchor { padding-right: 6px; } -.anchor::before { - content: '§'; -} .main-heading a:hover, .example-wrap > pre.rust a:hover, diff --git a/src/librustdoc/html/templates/page.html b/src/librustdoc/html/templates/page.html index df13e597f1f..aa3bf827db4 100644 --- a/src/librustdoc/html/templates/page.html +++ b/src/librustdoc/html/templates/page.html @@ -115,6 +115,7 @@ <input {# -#} class="search-input" {# -#} name="search" {# -#} + aria-label="Run search in the documentation" {# -#} autocomplete="off" {# -#} spellcheck="false" {# -#} placeholder="Click or press ‘S’ to search, ‘?’ for more options…" {# -#} |
