Skip to content

Commit 330a558

Browse files
authored
Rollup merge of #91223 - GuillaumeGomez:headings-indent, r=jsha
Fix headings indent Fixes #91200. Screenshots with the fix: ![Screenshot from 2021-11-25 15-32-35](https://user-images.githubusercontent.com/3050060/143462481-f7e9ea13-72d5-46fe-90e0-9527e74599e3.png) ![Screenshot from 2021-11-25 15-32-49](https://user-images.githubusercontent.com/3050060/143462485-c010716a-0276-421b-a777-afff19c81c96.png) If the first element of a top docblock is a heading, we still need to keep the indent, but only on this one (I added a test to check it). We need it because otherwise the anchor will go over the `[-]` toggle. cc `@camelid` r? `@jsha`
2 parents fcbbdaf + 2342756 commit 330a558

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

src/librustdoc/html/static/css/rustdoc.css

+6-4
Original file line numberDiff line numberDiff line change
@@ -1129,15 +1129,17 @@ h3.variant {
11291129
margin-top: 3px;
11301130
}
11311131

1132-
.docblock > .section-header:first-child {
1132+
.top-doc .docblock > .section-header:first-child {
11331133
margin-left: 15px;
1134-
margin-top: 0;
11351134
}
1136-
1137-
.docblock > .section-header:first-child:hover > a:before {
1135+
.top-doc .docblock > .section-header:first-child:hover > a:before {
11381136
left: -10px;
11391137
}
11401138

1139+
.docblock > .section-header:first-child {
1140+
margin-top: 0;
1141+
}
1142+
11411143
:target > code, :target > .code-header {
11421144
opacity: 1;
11431145
}

src/test/rustdoc-gui/anchors.goml

+45-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This test is to ensure that the anchors (`§`) have the expected color.
1+
// This test is to ensure that the anchors (`§`) have the expected color and position.
22
goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html
33
show-text: true
44

@@ -28,3 +28,47 @@ assert-css: ("h2#implementations a.anchor", {"color": "rgb(0, 0, 0)"})
2828
// Same thing with the impl block title.
2929
move-cursor-to: "#impl"
3030
assert-css: ("#impl a.anchor", {"color": "rgb(0, 0, 0)"})
31+
32+
// Now we check the positions: only the first heading of the top doc comment should
33+
// have a different position.
34+
move-cursor-to: ".top-doc .docblock .section-header:first-child"
35+
assert-css: (
36+
".top-doc .docblock .section-header:first-child > a::before",
37+
{"left": "-10px", "padding-right": "10px"}
38+
)
39+
// We also check that the heading itself has a different indent.
40+
assert-css: (".top-doc .docblock .section-header:first-child", {"margin-left": "15px"})
41+
42+
move-cursor-to: ".top-doc .docblock .section-header:not(:first-child)"
43+
assert-css: (
44+
".top-doc .docblock .section-header:not(:first-child) > a::before",
45+
{"left": "-25px", "padding-right": "10px"}
46+
)
47+
assert-css: (".top-doc .docblock .section-header:not(:first-child)", {"margin-left": "0px"})
48+
49+
// Now let's check some other docblock headings...
50+
// First the impl block docs.
51+
move-cursor-to: "#title-for-struct-impl-doc"
52+
assert-css: (
53+
"#title-for-struct-impl-doc > a::before",
54+
{"left": "-25px", "padding-right": "10px"}
55+
)
56+
assert-css: ("#title-for-struct-impl-doc", {"margin-left": "0px"})
57+
// Now a method docs.
58+
move-cursor-to: "#title-for-struct-impl-item-doc"
59+
assert-css: (
60+
"#title-for-struct-impl-item-doc > a::before",
61+
{"left": "-25px", "padding-right": "10px"}
62+
)
63+
assert-css: ("#title-for-struct-impl-item-doc", {"margin-left": "0px"})
64+
65+
// Finally, we want to ensure that if the first element of the doc block isn't a heading,
66+
// if there is a heading afterwards, it won't have the indent.
67+
goto: file://|DOC_PATH|/test_docs/enum.WhoLetTheDogOut.html
68+
69+
move-cursor-to: ".top-doc .docblock .section-header"
70+
assert-css: (
71+
".top-doc .docblock .section-header > a::before",
72+
{"left": "-25px", "padding-right": "10px"}
73+
)
74+
assert-css: (".top-doc .docblock .section-header", {"margin-left": "0px"})

src/test/rustdoc-gui/src/test_docs/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ impl AsRef<str> for Foo {
4747
}
4848

4949
/// Just a normal enum.
50+
///
51+
/// # title!
5052
#[doc(alias = "ThisIsAnAlias")]
5153
pub enum WhoLetTheDogOut {
5254
/// Woof!

0 commit comments

Comments
 (0)