Skip to content

Commit 6e1613a

Browse files
authored
Rollup merge of rust-lang#103585 - GuillaumeGomez:source-line-css, r=notriddle
Migrate source line numbers CSS to CSS variables Part of rust-lang#98460. No UI changes. r? ``@notriddle``
2 parents cdd7afe + 71e824d commit 6e1613a

File tree

5 files changed

+60
-32
lines changed

5 files changed

+60
-32
lines changed

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

+8
Original file line numberDiff line numberDiff line change
@@ -571,10 +571,18 @@ ul.block, .block li {
571571
padding: 13px 8px;
572572
border-top-left-radius: 5px;
573573
border-bottom-left-radius: 5px;
574+
border-color: var(--example-line-numbers-border-color);
574575
}
575576

576577
.src-line-numbers span {
577578
cursor: pointer;
579+
color: var(--src-line-numbers-span-color);
580+
}
581+
.src-line-numbers .line-highlighted {
582+
background-color: var(--src-line-number-highlighted-background-color);
583+
}
584+
.src-line-numbers :target {
585+
background-color: transparent;
578586
}
579587

580588
.search-loading {

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

+3-9
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ Original by Dempfi (https://github.com/dempfi/ayu)
5555
--code-highlight-question-mark-color: #ff9011;
5656
--code-highlight-comment-color: #788797;
5757
--code-highlight-doc-comment-color: #a1ac88;
58+
--example-line-numbers-border-color: none;
59+
--src-line-numbers-span-color: #5c6773;
60+
--src-line-number-highlighted-background-color: rgba(255, 236, 164, 0.06);
5861
}
5962

6063
.slider {
@@ -112,10 +115,8 @@ pre, .rustdoc.source .example-wrap {
112115
color: #ff7733;
113116
}
114117

115-
.src-line-numbers span { color: #5c6773; }
116118
.src-line-numbers .line-highlighted {
117119
color: #708090;
118-
background-color: rgba(255, 236, 164, 0.06);
119120
padding-right: 4px;
120121
border-right: 1px solid #ffb44c;
121122
}
@@ -170,13 +171,6 @@ details.rustdoc-toggle > summary::before {
170171
color: #788797;
171172
}
172173

173-
.src-line-numbers :target { background-color: transparent; }
174-
175-
pre.example-line-numbers {
176-
color: #5c67736e;
177-
border: none;
178-
}
179-
180174
a.test-arrow {
181175
font-size: 100%;
182176
color: #788797;

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

+3-11
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
--code-highlight-question-mark-color: #ff9011;
5151
--code-highlight-comment-color: #8d8d8b;
5252
--code-highlight-doc-comment-color: #8ca375;
53+
--example-line-numbers-border-color: #4a4949;
54+
--src-line-numbers-span-color: #3b91e2;
55+
--src-line-number-highlighted-background-color: #0a042f;
5356
}
5457

5558
.slider {
@@ -69,11 +72,6 @@ input:focus + .slider {
6972
drop-shadow(0 -1px 0 #fff)
7073
}
7174

72-
.src-line-numbers span { color: #3B91E2; }
73-
.src-line-numbers .line-highlighted {
74-
background-color: #0a042f !important;
75-
}
76-
7775
.content .item-info::before { color: #ccc; }
7876

7977
body.source .example-wrap pre.rust a {
@@ -95,12 +93,6 @@ details.rustdoc-toggle > summary::before {
9593
filter: invert(69%) sepia(60%) saturate(6613%) hue-rotate(184deg) brightness(100%) contrast(91%);
9694
}
9795

98-
.src-line-numbers :target { background-color: transparent; }
99-
100-
pre.example-line-numbers {
101-
border-color: #4a4949;
102-
}
103-
10496
a.test-arrow {
10597
color: #dedede;
10698
background-color: rgba(78, 139, 202, 0.2);

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

+3-11
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
--code-highlight-question-mark-color: #ff9011;
5151
--code-highlight-comment-color: #8e908c;
5252
--code-highlight-doc-comment-color: #4d4d4c;
53+
--example-line-numbers-border-color: #c7c7c7;
54+
--src-line-numbers-span-color: #c67e2d;
55+
--src-line-number-highlighted-background-color: #fdffd3;
5356
}
5457

5558
.slider {
@@ -68,11 +71,6 @@ input:focus + .slider {
6871
*/
6972
}
7073

71-
.src-line-numbers span { color: #c67e2d; }
72-
.src-line-numbers .line-highlighted {
73-
background-color: #FDFFD3 !important;
74-
}
75-
7674
.content .item-info::before { color: #ccc; }
7775

7876
body.source .example-wrap pre.rust a {
@@ -90,12 +88,6 @@ body.source .example-wrap pre.rust a {
9088
filter: invert(44%) sepia(18%) saturate(23%) hue-rotate(317deg) brightness(96%) contrast(93%);
9189
}
9290

93-
.src-line-numbers :target { background-color: transparent; }
94-
95-
pre.example-line-numbers {
96-
border-color: #c7c7c7;
97-
}
98-
9991
a.test-arrow {
10092
color: #f5f5f5;
10193
background-color: rgba(78, 139, 202, 0.2);

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

+43-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
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"
3+
show-text: true
34
// Check that we can click on the line number.
45
click: ".src-line-numbers > span:nth-child(4)" // This is the span for line 4.
56
// Ensure that the page URL was updated.
@@ -12,6 +13,48 @@ assert-attribute: (".src-line-numbers > span:nth-child(4)", {"class": "line-high
1213
assert-attribute: (".src-line-numbers > span:nth-child(5)", {"class": "line-highlighted"})
1314
assert-attribute: (".src-line-numbers > span:nth-child(6)", {"class": "line-highlighted"})
1415
assert-attribute-false: (".src-line-numbers > span:nth-child(7)", {"class": "line-highlighted"})
16+
17+
define-function: (
18+
"check-colors",
19+
(theme, color, background_color, highlight_color, highlight_background_color),
20+
[
21+
("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}),
22+
("reload"),
23+
("assert-css", (
24+
".src-line-numbers > span:not(.line-highlighted)",
25+
{"color": |color|, "background-color": |background_color|},
26+
ALL,
27+
)),
28+
("assert-css", (
29+
".src-line-numbers > span.line-highlighted",
30+
{"color": |highlight_color|, "background-color": |highlight_background_color|},
31+
ALL,
32+
)),
33+
],
34+
)
35+
36+
call-function: ("check-colors", {
37+
"theme": "ayu",
38+
"color": "rgb(92, 103, 115)",
39+
"background_color": "rgba(0, 0, 0, 0)",
40+
"highlight_color": "rgb(112, 128, 144)",
41+
"highlight_background_color": "rgba(255, 236, 164, 0.06)",
42+
})
43+
call-function: ("check-colors", {
44+
"theme": "dark",
45+
"color": "rgb(59, 145, 226)",
46+
"background_color": "rgba(0, 0, 0, 0)",
47+
"highlight_color": "rgb(59, 145, 226)",
48+
"highlight_background_color": "rgb(10, 4, 47)",
49+
})
50+
call-function: ("check-colors", {
51+
"theme": "light",
52+
"color": "rgb(198, 126, 45)",
53+
"background_color": "rgba(0, 0, 0, 0)",
54+
"highlight_color": "rgb(198, 126, 45)",
55+
"highlight_background_color": "rgb(253, 255, 211)",
56+
})
57+
1558
// This is to ensure that the content is correctly align with the line numbers.
1659
compare-elements-position: ("//*[@id='1']", ".rust > code > span", ("y"))
1760

@@ -20,7 +63,6 @@ assert-css: (".src-line-numbers", {"text-align": "right"})
2063

2164
// Now let's check that clicking on something else than the line number doesn't
2265
// do anything (and certainly not add a `#NaN` to the URL!).
23-
show-text: true
2466
goto: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
2567
// We use this assert-position to know where we will click.
2668
assert-position: ("//*[@id='1']", {"x": 104, "y": 112})

0 commit comments

Comments
 (0)