Skip to content

Commit 2997ea3

Browse files
authored
Rollup merge of #93808 - GuillaumeGomez:headings-indent, r=jsha
Remove first headings indent Fixes #92975. I removed the anchors displayed on hover because the cursor changes when you hover them in any case, removing the need for the indent altogether. [Demo](https://rustdoc.crud.net/imperio/headings-indent/std/index.html). Screenshot of the result: ![Screenshot from 2022-02-09 14-46-12](https://user-images.githubusercontent.com/3050060/153213824-74ef0b62-4f2b-4816-8912-6f2f3beacd29.png) r? `@jsha`
2 parents f3f41d7 + e8d5ae4 commit 2997ea3

File tree

6 files changed

+18
-105
lines changed

6 files changed

+18
-105
lines changed

src/librustdoc/html/markdown.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ impl<'a, 'b, 'ids, I: Iterator<Item = SpannedEvent<'a>>> Iterator
565565
self.buf.push_back((Event::Html(format!("</a></h{}>", level).into()), 0..0));
566566

567567
let start_tags = format!(
568-
"<h{level} id=\"{id}\" class=\"section-header\">\
568+
"<h{level} id=\"{id}\">\
569569
<a href=\"#{id}\">",
570570
id = id,
571571
level = level

src/librustdoc/html/markdown/tests.rs

+10-37
Original file line numberDiff line numberDiff line change
@@ -159,25 +159,22 @@ fn test_header() {
159159
assert_eq!(output, expect, "original: {}", input);
160160
}
161161

162-
t(
163-
"# Foo bar",
164-
"<h2 id=\"foo-bar\" class=\"section-header\"><a href=\"#foo-bar\">Foo bar</a></h2>",
165-
);
162+
t("# Foo bar", "<h2 id=\"foo-bar\"><a href=\"#foo-bar\">Foo bar</a></h2>");
166163
t(
167164
"## Foo-bar_baz qux",
168-
"<h3 id=\"foo-bar_baz-qux\" class=\"section-header\">\
165+
"<h3 id=\"foo-bar_baz-qux\">\
169166
<a href=\"#foo-bar_baz-qux\">Foo-bar_baz qux</a></h3>",
170167
);
171168
t(
172169
"### **Foo** *bar* baz!?!& -_qux_-%",
173-
"<h4 id=\"foo-bar-baz--qux-\" class=\"section-header\">\
170+
"<h4 id=\"foo-bar-baz--qux-\">\
174171
<a href=\"#foo-bar-baz--qux-\"><strong>Foo</strong> \
175172
<em>bar</em> baz!?!&amp; -<em>qux</em>-%</a>\
176173
</h4>",
177174
);
178175
t(
179176
"#### **Foo?** & \\*bar?!* _`baz`_ ❤ #qux",
180-
"<h5 id=\"foo--bar--baz--qux\" class=\"section-header\">\
177+
"<h5 id=\"foo--bar--baz--qux\">\
181178
<a href=\"#foo--bar--baz--qux\"><strong>Foo?</strong> &amp; *bar?!* \
182179
<em><code>baz</code></em> ❤ #qux</a>\
183180
</h5>",
@@ -201,36 +198,12 @@ fn test_header_ids_multiple_blocks() {
201198
assert_eq!(output, expect, "original: {}", input);
202199
}
203200

204-
t(
205-
&mut map,
206-
"# Example",
207-
"<h2 id=\"example\" class=\"section-header\"><a href=\"#example\">Example</a></h2>",
208-
);
209-
t(
210-
&mut map,
211-
"# Panics",
212-
"<h2 id=\"panics\" class=\"section-header\"><a href=\"#panics\">Panics</a></h2>",
213-
);
214-
t(
215-
&mut map,
216-
"# Example",
217-
"<h2 id=\"example-1\" class=\"section-header\"><a href=\"#example-1\">Example</a></h2>",
218-
);
219-
t(
220-
&mut map,
221-
"# Search",
222-
"<h2 id=\"search-1\" class=\"section-header\"><a href=\"#search-1\">Search</a></h2>",
223-
);
224-
t(
225-
&mut map,
226-
"# Example",
227-
"<h2 id=\"example-2\" class=\"section-header\"><a href=\"#example-2\">Example</a></h2>",
228-
);
229-
t(
230-
&mut map,
231-
"# Panics",
232-
"<h2 id=\"panics-1\" class=\"section-header\"><a href=\"#panics-1\">Panics</a></h2>",
233-
);
201+
t(&mut map, "# Example", "<h2 id=\"example\"><a href=\"#example\">Example</a></h2>");
202+
t(&mut map, "# Panics", "<h2 id=\"panics\"><a href=\"#panics\">Panics</a></h2>");
203+
t(&mut map, "# Example", "<h2 id=\"example-1\"><a href=\"#example-1\">Example</a></h2>");
204+
t(&mut map, "# Search", "<h2 id=\"search-1\"><a href=\"#search-1\">Search</a></h2>");
205+
t(&mut map, "# Example", "<h2 id=\"example-2\"><a href=\"#example-2\">Example</a></h2>");
206+
t(&mut map, "# Panics", "<h2 id=\"panics-1\"><a href=\"#panics-1\">Panics</a></h2>");
234207
}
235208

236209
#[test]

src/librustdoc/html/render/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2567,7 +2567,7 @@ fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item) {
25672567
w,
25682568
"<div class=\"docblock scraped-example-list\">\
25692569
<span></span>\
2570-
<h5 id=\"{id}\" class=\"section-header\">\
2570+
<h5 id=\"{id}\">\
25712571
<a href=\"#{id}\">Examples found in repository</a>\
25722572
</h5>",
25732573
id = id

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

-21
Original file line numberDiff line numberDiff line change
@@ -1141,16 +1141,6 @@ a.test-arrow {
11411141
a.test-arrow:hover{
11421142
text-decoration: none;
11431143
}
1144-
.section-header:hover a:before {
1145-
position: absolute;
1146-
left: -25px;
1147-
padding-right: 10px; /* avoid gap that causes hover to disappear */
1148-
content: '\2002\00a7\2002';
1149-
}
1150-
1151-
.section-header:hover a {
1152-
text-decoration: none;
1153-
}
11541144

11551145
.code-attribute {
11561146
font-weight: 300;
@@ -1196,17 +1186,6 @@ h3.variant {
11961186
margin-top: 3px;
11971187
}
11981188

1199-
.top-doc .docblock > .section-header:first-child {
1200-
margin-left: 15px;
1201-
}
1202-
.top-doc .docblock > .section-header:first-child:hover > a:before {
1203-
left: -10px;
1204-
}
1205-
1206-
.docblock > .section-header:first-child {
1207-
margin-top: 0;
1208-
}
1209-
12101189
:target > code, :target > .code-header {
12111190
opacity: 1;
12121191
}

src/test/rustdoc-gui/anchors.goml

-42
Original file line numberDiff line numberDiff line change
@@ -31,46 +31,4 @@ assert-css: ("h2#implementations a.anchor", {"color": "rgb(0, 0, 0)"})
3131
move-cursor-to: "#impl"
3232
assert-css: ("#impl a.anchor", {"color": "rgb(0, 0, 0)"})
3333

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

src/test/rustdoc-gui/headers-color.goml

+6-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ goto: file://|DOC_PATH|/test_docs/index.html
4040
assert-css: (".small-section-header a", {"color": "rgb(197, 197, 197)"}, ALL)
4141

4242
goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html
43-
assert-css: (".section-header a", {"color": "rgb(57, 175, 215)"}, ALL)
43+
// We select headings (h2, h3, h...).
44+
assert-css: (".docblock > :not(p) > a", {"color": "rgb(57, 175, 215)"}, ALL)
4445

4546
// Dark theme
4647
local-storage: {
@@ -78,7 +79,8 @@ goto: file://|DOC_PATH|/test_docs/index.html
7879
assert-css: (".small-section-header a", {"color": "rgb(221, 221, 221)"}, ALL)
7980

8081
goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html
81-
assert-css: (".section-header a", {"color": "rgb(210, 153, 29)"}, ALL)
82+
// We select headings (h2, h3, h...).
83+
assert-css: (".docblock > :not(p) > a", {"color": "rgb(210, 153, 29)"}, ALL)
8284

8385
// Light theme
8486
local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"}
@@ -111,4 +113,5 @@ goto: file://|DOC_PATH|/test_docs/index.html
111113
assert-css: (".small-section-header a", {"color": "rgb(0, 0, 0)"}, ALL)
112114

113115
goto: file://|DOC_PATH|/test_docs/struct.HeavilyDocumentedStruct.html
114-
assert-css: (".section-header a", {"color": "rgb(56, 115, 173)"}, ALL)
116+
// We select headings (h2, h3, h...).
117+
assert-css: (".docblock > :not(p) > a", {"color": "rgb(56, 115, 173)"}, ALL)

0 commit comments

Comments
 (0)