Rollup merge of #87210 - notriddle:notriddle/rustdoc-sidebar-headers, r=GuillaumeGomez
Rustdoc accessibility: make the sidebar headers actual headers Part of #87059 Preview it at: https://notriddle.com/notriddle-rustdoc-test/rustdoc-sidebar-header/std/index.html
This commit is contained in:
commit
456ebd30d5
9 changed files with 45 additions and 41 deletions
|
@ -539,7 +539,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>\
|
||||
|
@ -567,7 +567,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.templates,
|
||||
|
|
|
@ -1654,7 +1654,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 ",
|
||||
|
@ -1718,7 +1718,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>");
|
||||
|
@ -1730,7 +1730,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.
|
||||
|
@ -1841,7 +1841,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 {
|
||||
|
@ -1906,24 +1906,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);
|
||||
}
|
||||
|
@ -1975,7 +1975,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 {}<Target={}></a>",
|
||||
"<h3 class=\"sidebar-title\"><a href=\"#deref-methods\">Methods from {}<Target={}></a></h3>",
|
||||
Escape(&format!("{:#}", impl_.inner_impl().trait_.as_ref().unwrap().print(cx))),
|
||||
Escape(&format!("{:#}", real_target.print(cx))),
|
||||
);
|
||||
|
@ -1998,7 +1998,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\">",
|
||||
);
|
||||
|
||||
|
@ -2075,8 +2075,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>",
|
||||
|
@ -2085,8 +2085,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>",
|
||||
|
@ -2095,8 +2095,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>",
|
||||
|
@ -2105,8 +2105,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>",
|
||||
|
@ -2128,8 +2128,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() {
|
||||
|
@ -2141,11 +2141,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>",
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -2188,7 +2188,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\">",
|
||||
);
|
||||
|
||||
|
@ -2220,7 +2220,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(""),
|
||||
));
|
||||
|
|
|
@ -342,6 +342,8 @@ nav.sub {
|
|||
margin: 30px 10px 20px 10px;
|
||||
text-align: center;
|
||||
word-wrap: break-word;
|
||||
font-weight: inherit;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.sidebar .version {
|
||||
|
@ -394,6 +396,8 @@ nav.sub {
|
|||
text-align: center;
|
||||
font-size: 17px;
|
||||
margin-bottom: 5px;
|
||||
font-weight: inherit;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.sidebar-links {
|
||||
|
|
|
@ -13,7 +13,7 @@ click: ".sidebar-menu"
|
|||
assert-css: (".sidebar-elems", {"display": "block", "left": "-246px"})
|
||||
// Force the sidebar open by focusing a link inside it.
|
||||
// This makes it easier for keyboard users to get to it.
|
||||
focus: ".sidebar-title"
|
||||
focus: ".sidebar-title a"
|
||||
assert-css: (".sidebar-elems", {"display": "block", "left": "0px"})
|
||||
// When we tab out of the sidebar, close it.
|
||||
focus: ".search-input"
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
// @has '-' '//*[@class="impl-items"]//*[@id="method.foo_b"]' 'pub fn foo_b(&self)'
|
||||
// @has '-' '//*[@class="impl-items"]//*[@id="method.foo_c"]' 'pub fn foo_c(&self)'
|
||||
// @has '-' '//*[@class="impl-items"]//*[@id="method.foo_j"]' 'pub fn foo_j(&self)'
|
||||
// @has '-' '//*[@class="sidebar-title"][@href="#deref-methods"]' 'Methods from Deref<Target=FooJ>'
|
||||
// @has '-' '//*[@class="sidebar-title"]/a[@href="#deref-methods"]' 'Methods from Deref<Target=FooJ>'
|
||||
// @has '-' '//*[@class="sidebar-links"]/a[@href="#method.foo_a"]' 'foo_a'
|
||||
// @has '-' '//*[@class="sidebar-links"]/a[@href="#method.foo_b"]' 'foo_b'
|
||||
// @has '-' '//*[@class="sidebar-links"]/a[@href="#method.foo_c"]' 'foo_c'
|
||||
|
|
|
@ -4,6 +4,6 @@
|
|||
pub struct Foo;
|
||||
|
||||
// @has foo/struct.Foo.html
|
||||
// @has - '//*[@class="sidebar-title"][@href="#trait-implementations"]' 'Trait Implementations'
|
||||
// @has - '//*[@class="sidebar-title"]/a[@href="#trait-implementations"]' 'Trait Implementations'
|
||||
// @has - '//*[@class="sidebar-links"]/a' '!Sync'
|
||||
impl !Sync for Foo {}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#![crate_name = "foo"]
|
||||
|
||||
// @has foo/trait.Foo.html
|
||||
// @has - '//*[@class="sidebar-title"][@href="#required-methods"]' 'Required Methods'
|
||||
// @has - '//*[@class="sidebar-title"]/a[@href="#required-methods"]' 'Required Methods'
|
||||
// @has - '//*[@class="sidebar-links"]/a' 'bar'
|
||||
// @has - '//*[@class="sidebar-title"][@href="#provided-methods"]' 'Provided Methods'
|
||||
// @has - '//*[@class="sidebar-title"]/a[@href="#provided-methods"]' 'Provided Methods'
|
||||
// @has - '//*[@class="sidebar-links"]/a' 'foo'
|
||||
// @has - '//*[@class="sidebar-title"][@href="#associated-const"]' 'Associated Constants'
|
||||
// @has - '//*[@class="sidebar-title"]/a[@href="#associated-const"]' 'Associated Constants'
|
||||
// @has - '//*[@class="sidebar-links"]/a' 'BAR'
|
||||
// @has - '//*[@class="sidebar-title"][@href="#associated-types"]' 'Associated Types'
|
||||
// @has - '//*[@class="sidebar-title"]/a[@href="#associated-types"]' 'Associated Types'
|
||||
// @has - '//*[@class="sidebar-links"]/a' 'Output'
|
||||
pub trait Foo {
|
||||
const BAR: u32 = 0;
|
||||
|
@ -18,7 +18,7 @@ pub trait Foo {
|
|||
}
|
||||
|
||||
// @has foo/struct.Bar.html
|
||||
// @has - '//*[@class="sidebar-title"][@href="#fields"]' 'Fields'
|
||||
// @has - '//*[@class="sidebar-title"]/a[@href="#fields"]' 'Fields'
|
||||
// @has - '//*[@class="sidebar-links"]/a[@href="#structfield.f"]' 'f'
|
||||
// @has - '//*[@class="sidebar-links"]/a[@href="#structfield.u"]' 'u'
|
||||
// @!has - '//*[@class="sidebar-links"]/a' 'waza'
|
||||
|
@ -29,7 +29,7 @@ pub struct Bar {
|
|||
}
|
||||
|
||||
// @has foo/enum.En.html
|
||||
// @has - '//*[@class="sidebar-title"][@href="#variants"]' 'Variants'
|
||||
// @has - '//*[@class="sidebar-title"]/a[@href="#variants"]' 'Variants'
|
||||
// @has - '//*[@class="sidebar-links"]/a' 'foo'
|
||||
// @has - '//*[@class="sidebar-links"]/a' 'bar'
|
||||
pub enum En {
|
||||
|
@ -38,7 +38,7 @@ pub enum En {
|
|||
}
|
||||
|
||||
// @has foo/union.MyUnion.html
|
||||
// @has - '//*[@class="sidebar-title"][@href="#fields"]' 'Fields'
|
||||
// @has - '//*[@class="sidebar-title"]/a[@href="#fields"]' 'Fields'
|
||||
// @has - '//*[@class="sidebar-links"]/a[@href="#structfield.f1"]' 'f1'
|
||||
// @has - '//*[@class="sidebar-links"]/a[@href="#structfield.f2"]' 'f2'
|
||||
// @!has - '//*[@class="sidebar-links"]/a' 'waza'
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#![crate_name = "foo"]
|
||||
|
||||
// @has foo/trait.Foo.html
|
||||
// @has - '//*[@class="sidebar-title"][@href="#foreign-impls"]' 'Implementations on Foreign Types'
|
||||
// @has - '//*[@class="sidebar-title"]/a[@href="#foreign-impls"]' 'Implementations on Foreign Types'
|
||||
// @has - '//h2[@id="foreign-impls"]' 'Implementations on Foreign Types'
|
||||
// @has - '//*[@class="sidebar-links"]/a[@href="#impl-Foo-for-u32"]' 'u32'
|
||||
// @has - '//div[@id="impl-Foo-for-u32"]//code' 'impl Foo for u32'
|
||||
|
|
|
@ -12,7 +12,7 @@ impl MyStruct {
|
|||
// @has - '//*[@class="impl has-srclink"]//code' 'impl MyAlias'
|
||||
// @has - '//*[@class="impl has-srclink"]//code' 'impl MyTrait for MyAlias'
|
||||
// @has - 'Alias docstring'
|
||||
// @has - '//*[@class="sidebar"]//p[@class="location"]' 'Type Definition MyAlias'
|
||||
// @has - '//*[@class="sidebar"]//*[@class="location"]' 'Type Definition MyAlias'
|
||||
// @has - '//*[@class="sidebar"]//a[@href="#implementations"]' 'Methods'
|
||||
// @has - '//*[@class="sidebar"]//a[@href="#trait-implementations"]' 'Trait Implementations'
|
||||
/// Alias docstring
|
||||
|
|
Loading…
Add table
Reference in a new issue