Skip to content

Commit

Permalink
Replace h3 and h4 containing invalid DOM
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jun 1, 2021
1 parent 4231250 commit 9077d54
Show file tree
Hide file tree
Showing 28 changed files with 190 additions and 130 deletions.
42 changes: 30 additions & 12 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,11 @@ fn render_impl(
})
})
.map(|item| format!("{}.{}", item.type_(), name));
write!(w, "<h4 id=\"{}\" class=\"{}{}\">", id, item_type, in_trait_class,);
write!(
w,
"<div id=\"{}\" class=\"{}{}\" role=\"heading\" aria-level=\"4\">",
id, item_type, in_trait_class,
);
w.write_str("<code>");
render_assoc_item(
w,
Expand All @@ -1388,13 +1392,17 @@ fn render_impl(
);
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
write_srclink(cx, item, w);
w.write_str("</h4>");
w.write_str("</div>");
}
}
clean::TypedefItem(ref tydef, _) => {
let source_id = format!("{}.{}", ItemType::AssocType, name);
let id = cx.derive_id(source_id.clone());
write!(w, "<h4 id=\"{}\" class=\"{}{}\"><code>", id, item_type, in_trait_class);
write!(
w,
"<div id=\"{}\" class=\"{}{}\" role=\"heading\" aria-level=\"4\"><code>",
id, item_type, in_trait_class
);
assoc_type(
w,
item,
Expand All @@ -1406,12 +1414,16 @@ fn render_impl(
);
w.write_str("</code>");
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
w.write_str("</h4>");
w.write_str("</div>");
}
clean::AssocConstItem(ref ty, ref default) => {
let source_id = format!("{}.{}", item_type, name);
let id = cx.derive_id(source_id.clone());
write!(w, "<h4 id=\"{}\" class=\"{}{}\"><code>", id, item_type, in_trait_class);
write!(
w,
"<div id=\"{}\" class=\"{}{}\" role=\"heading\" aria-level=\"4\"><code>",
id, item_type, in_trait_class
);
assoc_const(
w,
item,
Expand All @@ -1431,12 +1443,16 @@ fn render_impl(
);
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
write_srclink(cx, item, w);
w.write_str("</h4>");
w.write_str("</div>");
}
clean::AssocTypeItem(ref bounds, ref default) => {
let source_id = format!("{}.{}", item_type, name);
let id = cx.derive_id(source_id.clone());
write!(w, "<h4 id=\"{}\" class=\"{}{}\"><code>", id, item_type, in_trait_class);
write!(
w,
"<div id=\"{}\" class=\"{}{}\" role=\"heading\" aria-level=\"4\"><code>",
id, item_type, in_trait_class,
);
assoc_type(
w,
item,
Expand All @@ -1448,7 +1464,7 @@ fn render_impl(
);
w.write_str("</code>");
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
w.write_str("</h4>");
w.write_str("</div>");
}
clean::StrippedItem(..) => return,
_ => panic!("can't make docs for trait item with name {:?}", item.name),
Expand Down Expand Up @@ -1577,7 +1593,8 @@ fn render_impl(
if let Some(use_absolute) = use_absolute {
write!(
w,
"{}<h3 id=\"{}\" class=\"impl\"{}><code class=\"in-band\">",
"{}<div id=\"{}\" class=\"impl\"{} role=\"heading\" aria-level=\"3\">\
<code class=\"in-band\">",
open_details(&mut close_tags, is_implementing_trait),
id,
aliases
Expand All @@ -1604,7 +1621,8 @@ fn render_impl(
} else {
write!(
w,
"{}<h3 id=\"{}\" class=\"impl\"{}><code class=\"in-band\">{}</code>",
"{}<div id=\"{}\" class=\"impl\"{} role=\"heading\" aria-level=\"3\">\
<code class=\"in-band\">{}</code>",
open_details(&mut close_tags, is_implementing_trait),
id,
aliases,
Expand All @@ -1621,9 +1639,9 @@ fn render_impl(
);
write_srclink(cx, &i.impl_item, w);
if !toggled {
w.write_str("</h3>");
w.write_str("</div>");
} else {
w.write_str("</h3></summary>");
w.write_str("</div></summary>");
}

if trait_.is_some() {
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,12 +585,12 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
if toggled {
write!(w, "<details class=\"rustdoc-toggle\" open><summary>");
}
write!(w, "<h3 id=\"{id}\" class=\"method\"><code>", id = id);
write!(w, "<div id=\"{}\" class=\"method\" role=\"heading\" aria-level=\"3\"><code>", id);
render_assoc_item(w, m, AssocItemLink::Anchor(Some(&id)), ItemType::Impl, cx);
w.write_str("</code>");
render_stability_since(w, m, t, cx.tcx());
write_srclink(cx, m, w);
w.write_str("</h3>");
w.write_str("</div>");
if toggled {
write!(w, "</summary>");
w.push_buffer(content);
Expand Down
90 changes: 68 additions & 22 deletions src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ h2 {
h3 {
font-size: 1.3em;
}
h1, h2, h3:not(.impl):not(.method):not(.type):not(.tymethod):not(.notable),
h4:not(.method):not(.type):not(.tymethod):not(.associatedconstant):not(.associatedtype) {
h1, h2, h3:not(.notable), h4 {
font-weight: 500;
margin: 20px 0 15px 0;
padding-bottom: 6px;
Expand All @@ -135,30 +134,38 @@ h1.fqn {
h1.fqn > .in-band > a:hover {
text-decoration: underline;
}
h2, h3:not(.impl):not(.method):not(.type):not(.tymethod),
h4:not(.method):not(.type):not(.tymethod):not(.associatedconstant):not(.associatedtype) {
h2, h3, h4 {
border-bottom: 1px solid;
}
h3.impl, h3.method, h4.method, h3.type, h4.type, h4.associatedconstant, h4.associatedtype {
div[aria-level="3"].impl, div[aria-level="3"].method, div[aria-level="4"].method,
div[aria-level="3"].type, div[aria-level="4"].type, div[aria-level="4"].associatedconstant,
div[aria-level="4"].associatedtype {
flex-basis: 100%;
font-weight: 600;
margin-top: 16px;
margin-bottom: 10px;
position: relative;
}
h3.impl, h3.method, h4.method.trait-impl, h3.type,
h4.type.trait-impl, h4.associatedconstant.trait-impl, h4.associatedtype.trait-impl {
div[aria-level="3"].impl, div[aria-level="3"].method, div[aria-level="4"].method.trait-impl,
div[aria-level="3"].type, div[aria-level="4"].type.trait-impl,
div[aria-level="4"].associatedconstant.trait-impl,
div[aria-level="4"].associatedtype.trait-impl {
padding-left: 15px;
}

div.impl-items > div {
padding-left: 0;
}

h1, h2, h3, h4,
.sidebar, a.source, .search-input, .search-results .result-name,
.content table td:first-child > a,
div.item-list .out-of-band,
.collapse-toggle, div.item-list .out-of-band, span.since,
#source-sidebar, #sidebar-toggle,
details.rustdoc-toggle > summary::before,
details.undocumented > summary::before,
.content ul.crate a.crate,
div.impl-items > div:not(.docblock):not(.item-info),
.content ul.crate a.crate, a.srclink,
/* This selector is for the items listed in the "all items" page. */
#main > ul.docblock > li > a {
font-family: "Fira Sans", Arial, sans-serif;
Expand Down Expand Up @@ -313,8 +320,6 @@ nav.sub {
margin-bottom: 14px;
}
.block h2, .block h3 {
margin-top: 0;
margin-bottom: 8px;
text-align: center;
}
.block ul, .block li {
Expand Down Expand Up @@ -462,15 +467,15 @@ nav.sub {
font-weight: normal;
}

h3.impl > .out-of-band {
div[aria-level="3"].impl > .out-of-band {
font-size: 21px;
}

h4.method > .out-of-band {
div[aria-level="4"].method > .out-of-band {
font-size: 19px;
}

h4 > code, h3 > code, .invisible > code {
div[aria-level="3"] > code, div[aria-level="4"] > code, .invisible > code {
max-width: calc(100% - 41px);
display: block;
}
Expand Down Expand Up @@ -543,7 +548,7 @@ h4 > code, h3 > code, .invisible > code {
}
.content .multi-column li { width: 100%; display: inline-block; }

.content .method {
.content > div.methods > div.method {
font-size: 1em;
position: relative;
}
Expand All @@ -555,7 +560,7 @@ h4 > code, h3 > code, .invisible > code {
font-size: 0.8em;
}

.content .methods > div:not(.notable-traits):not(.methods) {
.content .methods > div:not(.notable-traits):not(.method) {
margin-left: 40px;
margin-bottom: 15px;
}
Expand All @@ -564,7 +569,7 @@ h4 > code, h3 > code, .invisible > code {
margin-left: 20px;
margin-top: -34px;
}
.content .docblock > .impl-items > h4 {
.content .docblock > .impl-items > div[aria-level="4"] {
border-bottom: 0;
}
.content .docblock >.impl-items .table-display {
Expand Down Expand Up @@ -688,7 +693,8 @@ a {
text-decoration: underline;
}

.invisible > .srclink, h4 > code + .srclink, h3 > code + .srclink {
.invisible > .srclink,
div[aria-level="3"] > code + .srclink, div[aria-level="4"] > code + .srclink {
position: absolute;
top: 0;
right: 0;
Expand Down Expand Up @@ -923,7 +929,8 @@ body.blur > :not(#help) {
flex-grow: 1;
}

.impl-items h4, h4.impl, h3.impl, .methods h3 {
.impl-items div[aria-level="4"], div[aria-level="4"].impl, div[aria-level="3"].impl,
.methods div[aria-level="3"] {
display: flex;
flex-basis: 100%;
font-size: 16px;
Expand Down Expand Up @@ -985,6 +992,45 @@ a.test-arrow:hover{
font-weight: 300;
}

.collapse-toggle {
font-weight: 300;
position: absolute;
left: -23px;
top: 0;
}

div[aria-level="3"] > .collapse-toggle, div[aria-level="4"] > .collapse-toggle {
font-size: 0.8em;
top: 5px;
}

.toggle-wrapper > .collapse-toggle {
left: -24px;
margin-top: 0px;
}

.toggle-wrapper {
position: relative;
margin-top: 0;
}

.toggle-wrapper.collapsed {
height: 25px;
transition: height .2s;
margin-bottom: .6em;
}

.collapse-toggle > .inner {
display: inline-block;
width: 1.2ch;
text-align: center;
}

.collapse-toggle.hidden-default {
position: relative;
margin-left: 20px;
}

.since + .srclink {
display: table-cell;
padding-left: 10px;
Expand Down Expand Up @@ -1197,7 +1243,7 @@ pre.rust {
margin-left: 5px;
}

h4 > .notable-traits {
div[aria-level="4"] > .notable-traits {
position: absolute;
left: -44px;
top: 2px;
Expand Down Expand Up @@ -1615,7 +1661,7 @@ details.undocumented[open] > summary::before {
padding: 0;
}

.content h4 > .out-of-band {
.content div[aria-level="4"] > .out-of-band {
position: inherit;
}

Expand All @@ -1638,7 +1684,7 @@ details.undocumented[open] > summary::before {
z-index: 1;
}

h4 > .notable-traits {
div[aria-level="4"] > .notable-traits {
position: absolute;
left: -22px;
top: 24px;
Expand Down
7 changes: 3 additions & 4 deletions src/librustdoc/html/static/themes/ayu.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ body {
color: #c5c5c5;
}

h1, h2, h3:not(.impl):not(.method):not(.type):not(.tymethod),
h4:not(.method):not(.type):not(.tymethod) {
h1, h2, h3:not(.notable), h4 {
color: white;
}
h1.fqn {
Expand All @@ -20,10 +19,10 @@ h1.fqn {
h1.fqn a {
color: #fff;
}
h2, h3:not(.impl):not(.method):not(.type):not(.tymethod) {
h2, h3, h4 {
border-bottom-color: #5c6773;
}
h4:not(.method):not(.type):not(.tymethod):not(.associatedconstant) {
h4 {
border: none;
}

Expand Down
6 changes: 2 additions & 4 deletions src/librustdoc/html/static/themes/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ body {
color: #ddd;
}

h1, h2, h3:not(.impl):not(.method):not(.type):not(.tymethod),
h4:not(.method):not(.type):not(.tymethod) {
h1, h2, h3:not(.notable), h4 {
color: #ddd;
}
h1.fqn {
border-bottom-color: #d2d2d2;
}
h2, h3:not(.impl):not(.method):not(.type):not(.tymethod),
h4:not(.method):not(.type):not(.tymethod) {
h2, h3, h4 {
border-bottom-color: #d2d2d2;
}

Expand Down
6 changes: 2 additions & 4 deletions src/librustdoc/html/static/themes/light.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ body {
color: black;
}

h1, h2, h3:not(.impl):not(.method):not(.type):not(.tymethod),
h4:not(.method):not(.type):not(.tymethod) {
h1, h2, h3:not(.notable), h4 {
color: black;
}
h1.fqn {
border-bottom-color: #D5D5D5;
}
h2, h3:not(.impl):not(.method):not(.type):not(.tymethod),
h4:not(.method):not(.type):not(.tymethod) {
h2, h3, h4 {
border-bottom-color: #DDDDDD;
}

Expand Down
Loading

0 comments on commit 9077d54

Please sign in to comment.