Skip to content

Commit 76b2134

Browse files
authored
Rollup merge of #102325 - notriddle:notriddle/line-number, r=GuillaumeGomez
rustdoc: give `.line-number` / `.line-numbers` meaningful names
2 parents 66bab6b + 9ca2ae3 commit 76b2134

File tree

12 files changed

+47
-47
lines changed

12 files changed

+47
-47
lines changed

src/librustdoc/html/sources.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ pub(crate) fn print_src(
274274
) {
275275
let lines = s.lines().count();
276276
let mut line_numbers = Buffer::empty_from(buf);
277-
line_numbers.write_str("<pre class=\"line-numbers\">");
277+
line_numbers.write_str("<pre class=\"src-line-numbers\">");
278278
match source_context {
279279
SourceContext::Standalone => {
280280
for line in 1..=lines {

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ h2.location a {
569569
position: relative;
570570
}
571571

572-
.example-wrap > pre.line-number {
572+
pre.example-line-numbers {
573573
overflow: initial;
574574
border: 1px solid;
575575
padding: 13px 8px;
@@ -582,15 +582,15 @@ h2.location a {
582582
text-decoration: underline;
583583
}
584584

585-
.line-numbers {
585+
.src-line-numbers {
586586
text-align: right;
587587
}
588-
.rustdoc:not(.source) .example-wrap > pre:not(.line-number) {
588+
.rustdoc:not(.source) .example-wrap > pre:not(.example-line-numbers) {
589589
width: 100%;
590590
overflow-x: auto;
591591
}
592592

593-
.rustdoc:not(.source) .example-wrap > pre.line-numbers {
593+
.rustdoc:not(.source) .example-wrap > pre.src-line-numbers {
594594
width: auto;
595595
overflow-x: visible;
596596
}
@@ -603,14 +603,14 @@ h2.location a {
603603
text-align: center;
604604
}
605605

606-
.content > .example-wrap pre.line-numbers {
606+
.content > .example-wrap pre.src-line-numbers {
607607
position: relative;
608608
-webkit-user-select: none;
609609
-moz-user-select: none;
610610
-ms-user-select: none;
611611
user-select: none;
612612
}
613-
.line-numbers span {
613+
.src-line-numbers span {
614614
cursor: pointer;
615615
}
616616

@@ -2059,7 +2059,7 @@ in storage.js plus the media query with (min-width: 701px)
20592059
padding-bottom: 0;
20602060
}
20612061

2062-
.scraped-example:not(.expanded) .code-wrapper pre.line-numbers {
2062+
.scraped-example:not(.expanded) .code-wrapper pre.src-line-numbers {
20632063
overflow-x: hidden;
20642064
}
20652065

@@ -2105,12 +2105,12 @@ in storage.js plus the media query with (min-width: 701px)
21052105
bottom: 0;
21062106
}
21072107

2108-
.scraped-example .code-wrapper .line-numbers {
2108+
.scraped-example .code-wrapper .src-line-numbers {
21092109
margin: 0;
21102110
padding: 14px 0;
21112111
}
21122112

2113-
.scraped-example .code-wrapper .line-numbers span {
2113+
.scraped-example .code-wrapper .src-line-numbers span {
21142114
padding: 0 14px;
21152115
}
21162116

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ pre, .rustdoc.source .example-wrap {
9393
color: #ff7733;
9494
}
9595

96-
.line-numbers span { color: #5c6773; }
97-
.line-numbers .line-highlighted {
96+
.src-line-numbers span { color: #5c6773; }
97+
.src-line-numbers .line-highlighted {
9898
color: #708090;
9999
background-color: rgba(255, 236, 164, 0.06);
100100
padding-right: 4px;
@@ -171,7 +171,7 @@ details.rustdoc-toggle > summary::before {
171171
color: #788797;
172172
}
173173

174-
.line-numbers :target { background-color: transparent; }
174+
.src-line-numbers :target { background-color: transparent; }
175175

176176
/* Code highlighting */
177177
pre.rust .number, pre.rust .string { color: #b8cc52; }
@@ -190,7 +190,7 @@ pre.rust .attribute {
190190
color: #e6e1cf;
191191
}
192192

193-
.example-wrap > pre.line-number {
193+
pre.example-line-numbers {
194194
color: #5c67736e;
195195
border: none;
196196
}

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ input:focus + .slider {
5454
background: #444;
5555
}
5656

57-
.line-numbers span { color: #3B91E2; }
58-
.line-numbers .line-highlighted {
57+
.src-line-numbers span { color: #3B91E2; }
58+
.src-line-numbers .line-highlighted {
5959
background-color: #0a042f !important;
6060
}
6161

@@ -141,7 +141,7 @@ details.rustdoc-toggle > summary::before {
141141
background: none;
142142
}
143143

144-
.line-numbers :target { background-color: transparent; }
144+
.src-line-numbers :target { background-color: transparent; }
145145

146146
/* Code highlighting */
147147
pre.rust .kw { color: #ab8ac1; }
@@ -155,7 +155,7 @@ pre.rust .question-mark {
155155
color: #ff9011;
156156
}
157157

158-
.example-wrap > pre.line-number {
158+
pre.example-line-numbers {
159159
border-color: #4a4949;
160160
}
161161

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ input:focus + .slider {
5353
background-color: #fff;
5454
}
5555

56-
.line-numbers span { color: #c67e2d; }
57-
.line-numbers .line-highlighted {
56+
.src-line-numbers span { color: #c67e2d; }
57+
.src-line-numbers .line-highlighted {
5858
background-color: #FDFFD3 !important;
5959
}
6060

@@ -125,7 +125,7 @@ body.source .example-wrap pre.rust a {
125125
.stab { background: #FFF5D6; border-color: #FFC600; }
126126
.stab.portability > code { background: none; }
127127

128-
.line-numbers :target { background-color: transparent; }
128+
.src-line-numbers :target { background-color: transparent; }
129129

130130
/* Code highlighting */
131131
pre.rust .kw { color: #8959A8; }
@@ -141,7 +141,7 @@ pre.rust .question-mark {
141141
color: #ff9011;
142142
}
143143

144-
.example-wrap > pre.line-number {
144+
pre.example-line-numbers {
145145
border-color: #c7c7c7;
146146
}
147147

src/librustdoc/html/static/js/main.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ function loadCss(cssFileName) {
699699
window.rustdoc_add_line_numbers_to_examples = () => {
700700
onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => {
701701
const parent = x.parentNode;
702-
const line_numbers = parent.querySelectorAll(".line-number");
702+
const line_numbers = parent.querySelectorAll(".example-line-numbers");
703703
if (line_numbers.length > 0) {
704704
return;
705705
}
@@ -709,7 +709,7 @@ function loadCss(cssFileName) {
709709
elems.push(i + 1);
710710
}
711711
const node = document.createElement("pre");
712-
addClass(node, "line-number");
712+
addClass(node, "example-line-numbers");
713713
node.innerHTML = elems.join("\n");
714714
parent.insertBefore(node, x);
715715
});
@@ -718,7 +718,7 @@ function loadCss(cssFileName) {
718718
window.rustdoc_remove_line_numbers_from_examples = () => {
719719
onEachLazy(document.getElementsByClassName("rust-example-rendered"), x => {
720720
const parent = x.parentNode;
721-
const line_numbers = parent.querySelectorAll(".line-number");
721+
const line_numbers = parent.querySelectorAll(".example-line-numbers");
722722
for (const node of line_numbers) {
723723
parent.removeChild(node);
724724
}

src/librustdoc/html/static/js/scrape-examples.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
// Scroll code block to the given code location
1010
function scrollToLoc(elt, loc) {
11-
const lines = elt.querySelector(".line-numbers");
11+
const lines = elt.querySelector(".src-line-numbers");
1212
let scrollOffset;
1313

1414
// If the block is greater than the size of the viewer,

src/librustdoc/html/static/js/source-script.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ function highlightSourceLines(match) {
183183
if (x) {
184184
x.scrollIntoView();
185185
}
186-
onEachLazy(document.getElementsByClassName("line-numbers"), e => {
186+
onEachLazy(document.getElementsByClassName("src-line-numbers"), e => {
187187
onEachLazy(e.getElementsByTagName("span"), i_e => {
188188
removeClass(i_e, "line-highlighted");
189189
});
@@ -245,7 +245,7 @@ window.addEventListener("hashchange", () => {
245245
}
246246
});
247247

248-
onEachLazy(document.getElementsByClassName("line-numbers"), el => {
248+
onEachLazy(document.getElementsByClassName("src-line-numbers"), el => {
249249
el.addEventListener("click", handleSourceHighlight);
250250
});
251251

src/test/run-make-fulldeps/rustdoc-scrape-examples-macros/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Scraped example should only include line numbers for items b and c in ex.rs
2-
// @!has foobar/fn.f.html '//*[@class="line-numbers"]' '14'
3-
// @has foobar/fn.f.html '//*[@class="line-numbers"]' '15'
4-
// @has foobar/fn.f.html '//*[@class="line-numbers"]' '21'
5-
// @!has foobar/fn.f.html '//*[@class="line-numbers"]' '22'
2+
// @!has foobar/fn.f.html '//*[@class="src-line-numbers"]' '14'
3+
// @has foobar/fn.f.html '//*[@class="src-line-numbers"]' '15'
4+
// @has foobar/fn.f.html '//*[@class="src-line-numbers"]' '21'
5+
// @!has foobar/fn.f.html '//*[@class="src-line-numbers"]' '22'
66

77
pub fn f() {}
88

src/test/rustdoc-gui/basic-code.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
goto: file://|DOC_PATH|/test_docs/index.html
22
click: ".srclink"
3-
assert-count: (".line-numbers", 1)
3+
assert-count: (".src-line-numbers", 1)

src/test/rustdoc-gui/docblock-code-block-line-number.goml

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22
goto: file://|DOC_PATH|/test_docs/fn.foo.html
33

44
// We check that without this setting, there is no line number displayed.
5-
assert-false: "pre.line-number"
5+
assert-false: "pre.example-line-numbers"
66

77
// We now set the setting to show the line numbers on code examples.
88
local-storage: {"rustdoc-line-numbers": "true" }
99
// We reload to make the line numbers appear.
1010
reload:
1111

1212
// We wait for them to be added into the DOM by the JS...
13-
wait-for: "pre.line-number"
13+
wait-for: "pre.example-line-numbers"
1414
// If the test didn't fail, it means that it was found!
1515
// Let's now check some CSS properties...
16-
assert-css: ("pre.line-number", {
16+
assert-css: ("pre.example-line-numbers", {
1717
"margin": "0px",
1818
"padding": "13px 8px",
1919
"text-align": "right",
2020
})
2121
// The first code block has two lines so let's check its `<pre>` elements lists both of them.
22-
assert-text: ("pre.line-number", "1\n2")
22+
assert-text: ("pre.example-line-numbers", "1\n2")
2323

2424
// Now, try changing the setting dynamically. We'll turn it off, using the settings menu,
2525
// and make sure it goes away.
@@ -32,8 +32,8 @@ assert-css: ("#settings", {"display": "block"})
3232
// Then, click the toggle button.
3333
click: "input#line-numbers + .slider"
3434
wait-for: 100 // wait-for-false does not exist
35-
assert-false: "pre.line-number"
35+
assert-false: "pre.example-line-numbers"
3636

3737
// Finally, turn it on again.
3838
click: "input#line-numbers + .slider"
39-
wait-for: "pre.line-number"
39+
wait-for: "pre.example-line-numbers"

src/test/rustdoc-gui/source-code-page.goml

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
// Checks that the interactions with the source code pages are working as expected.
22
goto: file://|DOC_PATH|/src/test_docs/lib.rs.html
33
// Check that we can click on the line number.
4-
click: ".line-numbers > span:nth-child(4)" // This is the span for line 4.
4+
click: ".src-line-numbers > span:nth-child(4)" // This is the span for line 4.
55
// Ensure that the page URL was updated.
66
assert-document-property: ({"URL": "lib.rs.html#4"}, ENDS_WITH)
77
assert-attribute: ("//*[@id='4']", {"class": "line-highlighted"})
88
// We now check that the good spans are highlighted
99
goto: file://|DOC_PATH|/src/test_docs/lib.rs.html#4-6
10-
assert-attribute-false: (".line-numbers > span:nth-child(3)", {"class": "line-highlighted"})
11-
assert-attribute: (".line-numbers > span:nth-child(4)", {"class": "line-highlighted"})
12-
assert-attribute: (".line-numbers > span:nth-child(5)", {"class": "line-highlighted"})
13-
assert-attribute: (".line-numbers > span:nth-child(6)", {"class": "line-highlighted"})
14-
assert-attribute-false: (".line-numbers > span:nth-child(7)", {"class": "line-highlighted"})
10+
assert-attribute-false: (".src-line-numbers > span:nth-child(3)", {"class": "line-highlighted"})
11+
assert-attribute: (".src-line-numbers > span:nth-child(4)", {"class": "line-highlighted"})
12+
assert-attribute: (".src-line-numbers > span:nth-child(5)", {"class": "line-highlighted"})
13+
assert-attribute: (".src-line-numbers > span:nth-child(6)", {"class": "line-highlighted"})
14+
assert-attribute-false: (".src-line-numbers > span:nth-child(7)", {"class": "line-highlighted"})
1515
// This is to ensure that the content is correctly align with the line numbers.
1616
compare-elements-position: ("//*[@id='1']", ".rust > code > span", ("y"))
1717

1818
// Assert that the line numbers text is aligned to the right.
19-
assert-css: (".line-numbers", {"text-align": "right"})
19+
assert-css: (".src-line-numbers", {"text-align": "right"})
2020

2121
// Now let's check that clicking on something else than the line number doesn't
2222
// do anything (and certainly not add a `#NaN` to the URL!).
2323
show-text: true
2424
goto: file://|DOC_PATH|/src/test_docs/lib.rs.html
2525
// We use this assert-position to know where we will click.
2626
assert-position: ("//*[@id='1']", {"x": 104, "y": 103})
27-
// We click on the left of the "1" span but still in the "line-number" `<pre>`.
27+
// We click on the left of the "1" span but still in the "src-line-number" `<pre>`.
2828
click: (103, 103)
2929
assert-document-property: ({"URL": "/lib.rs.html"}, ENDS_WITH)
3030

0 commit comments

Comments
 (0)