Skip to content

Commit 9077d54

Browse files
Replace h3 and h4 containing invalid DOM
1 parent 4231250 commit 9077d54

28 files changed

+190
-130
lines changed

src/librustdoc/html/render/mod.rs

+30-12
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,11 @@ fn render_impl(
13691369
})
13701370
})
13711371
.map(|item| format!("{}.{}", item.type_(), name));
1372-
write!(w, "<h4 id=\"{}\" class=\"{}{}\">", id, item_type, in_trait_class,);
1372+
write!(
1373+
w,
1374+
"<div id=\"{}\" class=\"{}{}\" role=\"heading\" aria-level=\"4\">",
1375+
id, item_type, in_trait_class,
1376+
);
13731377
w.write_str("<code>");
13741378
render_assoc_item(
13751379
w,
@@ -1388,13 +1392,17 @@ fn render_impl(
13881392
);
13891393
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
13901394
write_srclink(cx, item, w);
1391-
w.write_str("</h4>");
1395+
w.write_str("</div>");
13921396
}
13931397
}
13941398
clean::TypedefItem(ref tydef, _) => {
13951399
let source_id = format!("{}.{}", ItemType::AssocType, name);
13961400
let id = cx.derive_id(source_id.clone());
1397-
write!(w, "<h4 id=\"{}\" class=\"{}{}\"><code>", id, item_type, in_trait_class);
1401+
write!(
1402+
w,
1403+
"<div id=\"{}\" class=\"{}{}\" role=\"heading\" aria-level=\"4\"><code>",
1404+
id, item_type, in_trait_class
1405+
);
13981406
assoc_type(
13991407
w,
14001408
item,
@@ -1406,12 +1414,16 @@ fn render_impl(
14061414
);
14071415
w.write_str("</code>");
14081416
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
1409-
w.write_str("</h4>");
1417+
w.write_str("</div>");
14101418
}
14111419
clean::AssocConstItem(ref ty, ref default) => {
14121420
let source_id = format!("{}.{}", item_type, name);
14131421
let id = cx.derive_id(source_id.clone());
1414-
write!(w, "<h4 id=\"{}\" class=\"{}{}\"><code>", id, item_type, in_trait_class);
1422+
write!(
1423+
w,
1424+
"<div id=\"{}\" class=\"{}{}\" role=\"heading\" aria-level=\"4\"><code>",
1425+
id, item_type, in_trait_class
1426+
);
14151427
assoc_const(
14161428
w,
14171429
item,
@@ -1431,12 +1443,16 @@ fn render_impl(
14311443
);
14321444
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
14331445
write_srclink(cx, item, w);
1434-
w.write_str("</h4>");
1446+
w.write_str("</div>");
14351447
}
14361448
clean::AssocTypeItem(ref bounds, ref default) => {
14371449
let source_id = format!("{}.{}", item_type, name);
14381450
let id = cx.derive_id(source_id.clone());
1439-
write!(w, "<h4 id=\"{}\" class=\"{}{}\"><code>", id, item_type, in_trait_class);
1451+
write!(
1452+
w,
1453+
"<div id=\"{}\" class=\"{}{}\" role=\"heading\" aria-level=\"4\"><code>",
1454+
id, item_type, in_trait_class,
1455+
);
14401456
assoc_type(
14411457
w,
14421458
item,
@@ -1448,7 +1464,7 @@ fn render_impl(
14481464
);
14491465
w.write_str("</code>");
14501466
write!(w, "<a href=\"#{}\" class=\"anchor\"></a>", id);
1451-
w.write_str("</h4>");
1467+
w.write_str("</div>");
14521468
}
14531469
clean::StrippedItem(..) => return,
14541470
_ => panic!("can't make docs for trait item with name {:?}", item.name),
@@ -1577,7 +1593,8 @@ fn render_impl(
15771593
if let Some(use_absolute) = use_absolute {
15781594
write!(
15791595
w,
1580-
"{}<h3 id=\"{}\" class=\"impl\"{}><code class=\"in-band\">",
1596+
"{}<div id=\"{}\" class=\"impl\"{} role=\"heading\" aria-level=\"3\">\
1597+
<code class=\"in-band\">",
15811598
open_details(&mut close_tags, is_implementing_trait),
15821599
id,
15831600
aliases
@@ -1604,7 +1621,8 @@ fn render_impl(
16041621
} else {
16051622
write!(
16061623
w,
1607-
"{}<h3 id=\"{}\" class=\"impl\"{}><code class=\"in-band\">{}</code>",
1624+
"{}<div id=\"{}\" class=\"impl\"{} role=\"heading\" aria-level=\"3\">\
1625+
<code class=\"in-band\">{}</code>",
16081626
open_details(&mut close_tags, is_implementing_trait),
16091627
id,
16101628
aliases,
@@ -1621,9 +1639,9 @@ fn render_impl(
16211639
);
16221640
write_srclink(cx, &i.impl_item, w);
16231641
if !toggled {
1624-
w.write_str("</h3>");
1642+
w.write_str("</div>");
16251643
} else {
1626-
w.write_str("</h3></summary>");
1644+
w.write_str("</div></summary>");
16271645
}
16281646

16291647
if trait_.is_some() {

src/librustdoc/html/render/print_item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -585,12 +585,12 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
585585
if toggled {
586586
write!(w, "<details class=\"rustdoc-toggle\" open><summary>");
587587
}
588-
write!(w, "<h3 id=\"{id}\" class=\"method\"><code>", id = id);
588+
write!(w, "<div id=\"{}\" class=\"method\" role=\"heading\" aria-level=\"3\"><code>", id);
589589
render_assoc_item(w, m, AssocItemLink::Anchor(Some(&id)), ItemType::Impl, cx);
590590
w.write_str("</code>");
591591
render_stability_since(w, m, t, cx.tcx());
592592
write_srclink(cx, m, w);
593-
w.write_str("</h3>");
593+
w.write_str("</div>");
594594
if toggled {
595595
write!(w, "</summary>");
596596
w.push_buffer(content);

src/librustdoc/html/static/rustdoc.css

+68-22
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ h2 {
117117
h3 {
118118
font-size: 1.3em;
119119
}
120-
h1, h2, h3:not(.impl):not(.method):not(.type):not(.tymethod):not(.notable),
121-
h4:not(.method):not(.type):not(.tymethod):not(.associatedconstant):not(.associatedtype) {
120+
h1, h2, h3:not(.notable), h4 {
122121
font-weight: 500;
123122
margin: 20px 0 15px 0;
124123
padding-bottom: 6px;
@@ -135,30 +134,38 @@ h1.fqn {
135134
h1.fqn > .in-band > a:hover {
136135
text-decoration: underline;
137136
}
138-
h2, h3:not(.impl):not(.method):not(.type):not(.tymethod),
139-
h4:not(.method):not(.type):not(.tymethod):not(.associatedconstant):not(.associatedtype) {
137+
h2, h3, h4 {
140138
border-bottom: 1px solid;
141139
}
142-
h3.impl, h3.method, h4.method, h3.type, h4.type, h4.associatedconstant, h4.associatedtype {
140+
div[aria-level="3"].impl, div[aria-level="3"].method, div[aria-level="4"].method,
141+
div[aria-level="3"].type, div[aria-level="4"].type, div[aria-level="4"].associatedconstant,
142+
div[aria-level="4"].associatedtype {
143143
flex-basis: 100%;
144144
font-weight: 600;
145145
margin-top: 16px;
146146
margin-bottom: 10px;
147147
position: relative;
148148
}
149-
h3.impl, h3.method, h4.method.trait-impl, h3.type,
150-
h4.type.trait-impl, h4.associatedconstant.trait-impl, h4.associatedtype.trait-impl {
149+
div[aria-level="3"].impl, div[aria-level="3"].method, div[aria-level="4"].method.trait-impl,
150+
div[aria-level="3"].type, div[aria-level="4"].type.trait-impl,
151+
div[aria-level="4"].associatedconstant.trait-impl,
152+
div[aria-level="4"].associatedtype.trait-impl {
151153
padding-left: 15px;
152154
}
153155

156+
div.impl-items > div {
157+
padding-left: 0;
158+
}
159+
154160
h1, h2, h3, h4,
155161
.sidebar, a.source, .search-input, .search-results .result-name,
156162
.content table td:first-child > a,
157-
div.item-list .out-of-band,
163+
.collapse-toggle, div.item-list .out-of-band, span.since,
158164
#source-sidebar, #sidebar-toggle,
159165
details.rustdoc-toggle > summary::before,
160166
details.undocumented > summary::before,
161-
.content ul.crate a.crate,
167+
div.impl-items > div:not(.docblock):not(.item-info),
168+
.content ul.crate a.crate, a.srclink,
162169
/* This selector is for the items listed in the "all items" page. */
163170
#main > ul.docblock > li > a {
164171
font-family: "Fira Sans", Arial, sans-serif;
@@ -313,8 +320,6 @@ nav.sub {
313320
margin-bottom: 14px;
314321
}
315322
.block h2, .block h3 {
316-
margin-top: 0;
317-
margin-bottom: 8px;
318323
text-align: center;
319324
}
320325
.block ul, .block li {
@@ -462,15 +467,15 @@ nav.sub {
462467
font-weight: normal;
463468
}
464469

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

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

473-
h4 > code, h3 > code, .invisible > code {
478+
div[aria-level="3"] > code, div[aria-level="4"] > code, .invisible > code {
474479
max-width: calc(100% - 41px);
475480
display: block;
476481
}
@@ -543,7 +548,7 @@ h4 > code, h3 > code, .invisible > code {
543548
}
544549
.content .multi-column li { width: 100%; display: inline-block; }
545550

546-
.content .method {
551+
.content > div.methods > div.method {
547552
font-size: 1em;
548553
position: relative;
549554
}
@@ -555,7 +560,7 @@ h4 > code, h3 > code, .invisible > code {
555560
font-size: 0.8em;
556561
}
557562

558-
.content .methods > div:not(.notable-traits):not(.methods) {
563+
.content .methods > div:not(.notable-traits):not(.method) {
559564
margin-left: 40px;
560565
margin-bottom: 15px;
561566
}
@@ -564,7 +569,7 @@ h4 > code, h3 > code, .invisible > code {
564569
margin-left: 20px;
565570
margin-top: -34px;
566571
}
567-
.content .docblock > .impl-items > h4 {
572+
.content .docblock > .impl-items > div[aria-level="4"] {
568573
border-bottom: 0;
569574
}
570575
.content .docblock >.impl-items .table-display {
@@ -688,7 +693,8 @@ a {
688693
text-decoration: underline;
689694
}
690695

691-
.invisible > .srclink, h4 > code + .srclink, h3 > code + .srclink {
696+
.invisible > .srclink,
697+
div[aria-level="3"] > code + .srclink, div[aria-level="4"] > code + .srclink {
692698
position: absolute;
693699
top: 0;
694700
right: 0;
@@ -923,7 +929,8 @@ body.blur > :not(#help) {
923929
flex-grow: 1;
924930
}
925931

926-
.impl-items h4, h4.impl, h3.impl, .methods h3 {
932+
.impl-items div[aria-level="4"], div[aria-level="4"].impl, div[aria-level="3"].impl,
933+
.methods div[aria-level="3"] {
927934
display: flex;
928935
flex-basis: 100%;
929936
font-size: 16px;
@@ -985,6 +992,45 @@ a.test-arrow:hover{
985992
font-weight: 300;
986993
}
987994

995+
.collapse-toggle {
996+
font-weight: 300;
997+
position: absolute;
998+
left: -23px;
999+
top: 0;
1000+
}
1001+
1002+
div[aria-level="3"] > .collapse-toggle, div[aria-level="4"] > .collapse-toggle {
1003+
font-size: 0.8em;
1004+
top: 5px;
1005+
}
1006+
1007+
.toggle-wrapper > .collapse-toggle {
1008+
left: -24px;
1009+
margin-top: 0px;
1010+
}
1011+
1012+
.toggle-wrapper {
1013+
position: relative;
1014+
margin-top: 0;
1015+
}
1016+
1017+
.toggle-wrapper.collapsed {
1018+
height: 25px;
1019+
transition: height .2s;
1020+
margin-bottom: .6em;
1021+
}
1022+
1023+
.collapse-toggle > .inner {
1024+
display: inline-block;
1025+
width: 1.2ch;
1026+
text-align: center;
1027+
}
1028+
1029+
.collapse-toggle.hidden-default {
1030+
position: relative;
1031+
margin-left: 20px;
1032+
}
1033+
9881034
.since + .srclink {
9891035
display: table-cell;
9901036
padding-left: 10px;
@@ -1197,7 +1243,7 @@ pre.rust {
11971243
margin-left: 5px;
11981244
}
11991245

1200-
h4 > .notable-traits {
1246+
div[aria-level="4"] > .notable-traits {
12011247
position: absolute;
12021248
left: -44px;
12031249
top: 2px;
@@ -1615,7 +1661,7 @@ details.undocumented[open] > summary::before {
16151661
padding: 0;
16161662
}
16171663

1618-
.content h4 > .out-of-band {
1664+
.content div[aria-level="4"] > .out-of-band {
16191665
position: inherit;
16201666
}
16211667

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

1641-
h4 > .notable-traits {
1687+
div[aria-level="4"] > .notable-traits {
16421688
position: absolute;
16431689
left: -22px;
16441690
top: 24px;

src/librustdoc/html/static/themes/ayu.css

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ body {
1010
color: #c5c5c5;
1111
}
1212

13-
h1, h2, h3:not(.impl):not(.method):not(.type):not(.tymethod),
14-
h4:not(.method):not(.type):not(.tymethod) {
13+
h1, h2, h3:not(.notable), h4 {
1514
color: white;
1615
}
1716
h1.fqn {
@@ -20,10 +19,10 @@ h1.fqn {
2019
h1.fqn a {
2120
color: #fff;
2221
}
23-
h2, h3:not(.impl):not(.method):not(.type):not(.tymethod) {
22+
h2, h3, h4 {
2423
border-bottom-color: #5c6773;
2524
}
26-
h4:not(.method):not(.type):not(.tymethod):not(.associatedconstant) {
25+
h4 {
2726
border: none;
2827
}
2928

src/librustdoc/html/static/themes/dark.css

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ body {
33
color: #ddd;
44
}
55

6-
h1, h2, h3:not(.impl):not(.method):not(.type):not(.tymethod),
7-
h4:not(.method):not(.type):not(.tymethod) {
6+
h1, h2, h3:not(.notable), h4 {
87
color: #ddd;
98
}
109
h1.fqn {
1110
border-bottom-color: #d2d2d2;
1211
}
13-
h2, h3:not(.impl):not(.method):not(.type):not(.tymethod),
14-
h4:not(.method):not(.type):not(.tymethod) {
12+
h2, h3, h4 {
1513
border-bottom-color: #d2d2d2;
1614
}
1715

src/librustdoc/html/static/themes/light.css

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ body {
55
color: black;
66
}
77

8-
h1, h2, h3:not(.impl):not(.method):not(.type):not(.tymethod),
9-
h4:not(.method):not(.type):not(.tymethod) {
8+
h1, h2, h3:not(.notable), h4 {
109
color: black;
1110
}
1211
h1.fqn {
1312
border-bottom-color: #D5D5D5;
1413
}
15-
h2, h3:not(.impl):not(.method):not(.type):not(.tymethod),
16-
h4:not(.method):not(.type):not(.tymethod) {
14+
h2, h3, h4 {
1715
border-bottom-color: #DDDDDD;
1816
}
1917

0 commit comments

Comments
 (0)