Skip to content

Commit

Permalink
Rustdoc accessibility: make the sidebar headers actual headers
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle authored and pietroalbini committed Jul 26, 2021
1 parent 2818e74 commit 0a297ac
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/librustdoc/html/render/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
};
let sidebar = if let Some(ref version) = self.cache.crate_version {
format!(
"<p class=\"location\">Crate {}</p>\
"<h2 class=\"location\">Crate {}</h2>\
<div class=\"block version\">\
<p>Version {}</p>\
</div>\
Expand All @@ -554,7 +554,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
page.root_path = "./";

let mut style_files = self.shared.style_files.clone();
let sidebar = "<p class=\"location\">Settings</p><div class=\"sidebar-elems\"></div>";
let sidebar = "<h2 class=\"location\">Settings</h2><div class=\"sidebar-elems\"></div>";
style_files.push(StylePath { path: PathBuf::from("settings.css"), disabled: false });
let v = layout::render(
&self.shared.layout,
Expand Down
54 changes: 27 additions & 27 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1690,7 +1690,7 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
{
write!(
buffer,
"<p class=\"location\">{}{}</p>",
"<h2 class=\"location\">{}{}</h2>",
match *it.kind {
clean::StructItem(..) => "Struct ",
clean::TraitItem(..) => "Trait ",
Expand Down Expand Up @@ -1753,7 +1753,7 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
// to navigate the documentation (though slightly inefficiently).

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

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

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

if !concrete_format.is_empty() {
out.push_str(
"<a class=\"sidebar-title\" href=\"#trait-implementations\">\
Trait Implementations</a>",
"<h3 class=\"sidebar-title\"><a href=\"#trait-implementations\">\
Trait Implementations</a></h3>",
);
write_sidebar_links(out, concrete_format);
}

if !synthetic_format.is_empty() {
out.push_str(
"<a class=\"sidebar-title\" href=\"#synthetic-implementations\">\
Auto Trait Implementations</a>",
"<h3 class=\"sidebar-title\"><a href=\"#synthetic-implementations\">\
Auto Trait Implementations</a></h3>",
);
write_sidebar_links(out, synthetic_format);
}

if !blanket_format.is_empty() {
out.push_str(
"<a class=\"sidebar-title\" href=\"#blanket-implementations\">\
Blanket Implementations</a>",
"<h3 class=\"sidebar-title\"><a href=\"#blanket-implementations\">\
Blanket Implementations</a></h3>",
);
write_sidebar_links(out, blanket_format);
}
Expand Down Expand Up @@ -2010,7 +2010,7 @@ fn sidebar_deref_methods(cx: &Context<'_>, out: &mut Buffer, impl_: &Impl, v: &V
if !ret.is_empty() {
write!(
out,
"<a class=\"sidebar-title\" href=\"#deref-methods\">Methods from {}&lt;Target={}&gt;</a>",
"<h3 class=\"sidebar-title\"><a href=\"#deref-methods\">Methods from {}&lt;Target={}&gt;</a></h3>",
Escape(&format!("{:#}", impl_.inner_impl().trait_.as_ref().unwrap().print(cx))),
Escape(&format!("{:#}", real_target.print(cx))),
);
Expand Down Expand Up @@ -2046,7 +2046,7 @@ fn sidebar_struct(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, s: &clea
if !fields.is_empty() {
if let CtorKind::Fictive = s.struct_type {
sidebar.push_str(
"<a class=\"sidebar-title\" href=\"#fields\">Fields</a>\
"<h3 class=\"sidebar-title\"><a href=\"#fields\">Fields</a></h3>\
<div class=\"sidebar-links\">",
);

Expand Down Expand Up @@ -2123,8 +2123,8 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
print_sidebar_section(
buf,
&t.items,
"<a class=\"sidebar-title\" href=\"#associated-types\">\
Associated Types</a><div class=\"sidebar-links\">",
"<h3 class=\"sidebar-title\"><a href=\"#associated-types\">\
Associated Types</a></h3><div class=\"sidebar-links\">",
|m| m.is_associated_type(),
|out, sym| write!(out, "<a href=\"#associatedtype.{0}\">{0}</a>", sym),
"</div>",
Expand All @@ -2133,8 +2133,8 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
print_sidebar_section(
buf,
&t.items,
"<a class=\"sidebar-title\" href=\"#associated-const\">\
Associated Constants</a><div class=\"sidebar-links\">",
"<h3 class=\"sidebar-title\"><a href=\"#associated-const\">\
Associated Constants</a></h3><div class=\"sidebar-links\">",
|m| m.is_associated_const(),
|out, sym| write!(out, "<a href=\"#associatedconstant.{0}\">{0}</a>", sym),
"</div>",
Expand All @@ -2143,8 +2143,8 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
print_sidebar_section(
buf,
&t.items,
"<a class=\"sidebar-title\" href=\"#required-methods\">\
Required Methods</a><div class=\"sidebar-links\">",
"<h3 class=\"sidebar-title\"><a href=\"#required-methods\">\
Required Methods</a></h3><div class=\"sidebar-links\">",
|m| m.is_ty_method(),
|out, sym| write!(out, "<a href=\"#tymethod.{0}\">{0}</a>", sym),
"</div>",
Expand All @@ -2153,8 +2153,8 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
print_sidebar_section(
buf,
&t.items,
"<a class=\"sidebar-title\" href=\"#provided-methods\">\
Provided Methods</a><div class=\"sidebar-links\">",
"<h3 class=\"sidebar-title\"><a href=\"#provided-methods\">\
Provided Methods</a></h3><div class=\"sidebar-links\">",
|m| m.is_method(),
|out, sym| write!(out, "<a href=\"#method.{0}\">{0}</a>", sym),
"</div>",
Expand All @@ -2176,8 +2176,8 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean
if !res.is_empty() {
res.sort();
buf.push_str(
"<a class=\"sidebar-title\" href=\"#foreign-impls\">\
Implementations on Foreign Types</a>\
"<h3 class=\"sidebar-title\"><a href=\"#foreign-impls\">\
Implementations on Foreign Types</a></h3>\
<div class=\"sidebar-links\">",
);
for (name, id) in res.into_iter() {
Expand All @@ -2189,11 +2189,11 @@ fn sidebar_trait(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, t: &clean

sidebar_assoc_items(cx, buf, it);

buf.push_str("<a class=\"sidebar-title\" href=\"#implementors\">Implementors</a>");
buf.push_str("<h3 class=\"sidebar-title\"><a href=\"#implementors\">Implementors</a></h3>");
if t.is_auto {
buf.push_str(
"<a class=\"sidebar-title\" \
href=\"#synthetic-implementors\">Auto Implementors</a>",
"<h3 class=\"sidebar-title\"><a \
href=\"#synthetic-implementors\">Auto Implementors</a></h3>",
);
}

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

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

Expand Down Expand Up @@ -2268,7 +2268,7 @@ fn sidebar_enum(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, e: &clean:
if !variants.is_empty() {
variants.sort_unstable();
sidebar.push_str(&format!(
"<a class=\"sidebar-title\" href=\"#variants\">Variants</a>\
"<h3 class=\"sidebar-title\"><a href=\"#variants\">Variants</a></h3>\
<div class=\"sidebar-links\">{}</div>",
variants.join(""),
));
Expand Down
5 changes: 5 additions & 0 deletions src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,12 @@ nav.sub {
.sidebar .location {
border: 1px solid;
font-size: 17px;
font-weight: inherit;
margin: 30px 10px 20px 10px;
text-align: center;
word-wrap: break-word;
font-weight: inherit;
padding: 0;
}

.sidebar .version {
Expand Down Expand Up @@ -348,6 +351,8 @@ nav.sub {
text-align: center;
font-size: 17px;
margin-bottom: 5px;
font-weight: inherit;
padding: 0;
}

.sidebar-links {
Expand Down

0 comments on commit 0a297ac

Please sign in to comment.