diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css
index 934334e0c88bd..c1c37f5b11da2 100644
--- a/src/librustdoc/html/static/css/rustdoc.css
+++ b/src/librustdoc/html/static/css/rustdoc.css
@@ -571,10 +571,18 @@ ul.block, .block li {
padding: 13px 8px;
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
+ border-color: var(--example-line-numbers-border-color);
}
.src-line-numbers span {
cursor: pointer;
+ color: var(--src-line-numbers-span-color);
+}
+.src-line-numbers .line-highlighted {
+ background-color: var(--src-line-number-highlighted-background-color);
+}
+.src-line-numbers :target {
+ background-color: transparent;
}
.search-loading {
diff --git a/src/librustdoc/html/static/css/themes/ayu.css b/src/librustdoc/html/static/css/themes/ayu.css
index 33817c16808c6..fdfdb3e196672 100644
--- a/src/librustdoc/html/static/css/themes/ayu.css
+++ b/src/librustdoc/html/static/css/themes/ayu.css
@@ -55,6 +55,9 @@ Original by Dempfi (https://github.com/dempfi/ayu)
--code-highlight-question-mark-color: #ff9011;
--code-highlight-comment-color: #788797;
--code-highlight-doc-comment-color: #a1ac88;
+ --example-line-numbers-border-color: none;
+ --src-line-numbers-span-color: #5c6773;
+ --src-line-number-highlighted-background-color: rgba(255, 236, 164, 0.06);
}
.slider {
@@ -112,10 +115,8 @@ pre, .rustdoc.source .example-wrap {
color: #ff7733;
}
-.src-line-numbers span { color: #5c6773; }
.src-line-numbers .line-highlighted {
color: #708090;
- background-color: rgba(255, 236, 164, 0.06);
padding-right: 4px;
border-right: 1px solid #ffb44c;
}
@@ -170,13 +171,6 @@ details.rustdoc-toggle > summary::before {
color: #788797;
}
-.src-line-numbers :target { background-color: transparent; }
-
-pre.example-line-numbers {
- color: #5c67736e;
- border: none;
-}
-
a.test-arrow {
font-size: 100%;
color: #788797;
diff --git a/src/librustdoc/html/static/css/themes/dark.css b/src/librustdoc/html/static/css/themes/dark.css
index d88710288b905..361d3d4a22597 100644
--- a/src/librustdoc/html/static/css/themes/dark.css
+++ b/src/librustdoc/html/static/css/themes/dark.css
@@ -50,6 +50,9 @@
--code-highlight-question-mark-color: #ff9011;
--code-highlight-comment-color: #8d8d8b;
--code-highlight-doc-comment-color: #8ca375;
+ --example-line-numbers-border-color: #4a4949;
+ --src-line-numbers-span-color: #3b91e2;
+ --src-line-number-highlighted-background-color: #0a042f;
}
.slider {
@@ -69,11 +72,6 @@ input:focus + .slider {
drop-shadow(0 -1px 0 #fff)
}
-.src-line-numbers span { color: #3B91E2; }
-.src-line-numbers .line-highlighted {
- background-color: #0a042f !important;
-}
-
.content .item-info::before { color: #ccc; }
body.source .example-wrap pre.rust a {
@@ -95,12 +93,6 @@ details.rustdoc-toggle > summary::before {
filter: invert(69%) sepia(60%) saturate(6613%) hue-rotate(184deg) brightness(100%) contrast(91%);
}
-.src-line-numbers :target { background-color: transparent; }
-
-pre.example-line-numbers {
- border-color: #4a4949;
-}
-
a.test-arrow {
color: #dedede;
background-color: rgba(78, 139, 202, 0.2);
diff --git a/src/librustdoc/html/static/css/themes/light.css b/src/librustdoc/html/static/css/themes/light.css
index cadc71dab9591..5eb4bbcf834bb 100644
--- a/src/librustdoc/html/static/css/themes/light.css
+++ b/src/librustdoc/html/static/css/themes/light.css
@@ -50,6 +50,9 @@
--code-highlight-question-mark-color: #ff9011;
--code-highlight-comment-color: #8e908c;
--code-highlight-doc-comment-color: #4d4d4c;
+ --example-line-numbers-border-color: #c7c7c7;
+ --src-line-numbers-span-color: #c67e2d;
+ --src-line-number-highlighted-background-color: #fdffd3;
}
.slider {
@@ -68,11 +71,6 @@ input:focus + .slider {
*/
}
-.src-line-numbers span { color: #c67e2d; }
-.src-line-numbers .line-highlighted {
- background-color: #FDFFD3 !important;
-}
-
.content .item-info::before { color: #ccc; }
body.source .example-wrap pre.rust a {
@@ -90,12 +88,6 @@ body.source .example-wrap pre.rust a {
filter: invert(44%) sepia(18%) saturate(23%) hue-rotate(317deg) brightness(96%) contrast(93%);
}
-.src-line-numbers :target { background-color: transparent; }
-
-pre.example-line-numbers {
- border-color: #c7c7c7;
-}
-
a.test-arrow {
color: #f5f5f5;
background-color: rgba(78, 139, 202, 0.2);
diff --git a/src/test/rustdoc-gui/source-code-page.goml b/src/test/rustdoc-gui/source-code-page.goml
index 29d65fc7ebc7a..a2dac2aa681d5 100644
--- a/src/test/rustdoc-gui/source-code-page.goml
+++ b/src/test/rustdoc-gui/source-code-page.goml
@@ -1,5 +1,6 @@
// Checks that the interactions with the source code pages are working as expected.
goto: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
+show-text: true
// Check that we can click on the line number.
click: ".src-line-numbers > span:nth-child(4)" // This is the span for line 4.
// Ensure that the page URL was updated.
@@ -12,6 +13,48 @@ assert-attribute: (".src-line-numbers > span:nth-child(4)", {"class": "line-high
assert-attribute: (".src-line-numbers > span:nth-child(5)", {"class": "line-highlighted"})
assert-attribute: (".src-line-numbers > span:nth-child(6)", {"class": "line-highlighted"})
assert-attribute-false: (".src-line-numbers > span:nth-child(7)", {"class": "line-highlighted"})
+
+define-function: (
+ "check-colors",
+ (theme, color, background_color, highlight_color, highlight_background_color),
+ [
+ ("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}),
+ ("reload"),
+ ("assert-css", (
+ ".src-line-numbers > span:not(.line-highlighted)",
+ {"color": |color|, "background-color": |background_color|},
+ ALL,
+ )),
+ ("assert-css", (
+ ".src-line-numbers > span.line-highlighted",
+ {"color": |highlight_color|, "background-color": |highlight_background_color|},
+ ALL,
+ )),
+ ],
+)
+
+call-function: ("check-colors", {
+ "theme": "ayu",
+ "color": "rgb(92, 103, 115)",
+ "background_color": "rgba(0, 0, 0, 0)",
+ "highlight_color": "rgb(112, 128, 144)",
+ "highlight_background_color": "rgba(255, 236, 164, 0.06)",
+})
+call-function: ("check-colors", {
+ "theme": "dark",
+ "color": "rgb(59, 145, 226)",
+ "background_color": "rgba(0, 0, 0, 0)",
+ "highlight_color": "rgb(59, 145, 226)",
+ "highlight_background_color": "rgb(10, 4, 47)",
+})
+call-function: ("check-colors", {
+ "theme": "light",
+ "color": "rgb(198, 126, 45)",
+ "background_color": "rgba(0, 0, 0, 0)",
+ "highlight_color": "rgb(198, 126, 45)",
+ "highlight_background_color": "rgb(253, 255, 211)",
+})
+
// This is to ensure that the content is correctly align with the line numbers.
compare-elements-position: ("//*[@id='1']", ".rust > code > span", ("y"))
@@ -20,7 +63,6 @@ assert-css: (".src-line-numbers", {"text-align": "right"})
// Now let's check that clicking on something else than the line number doesn't
// do anything (and certainly not add a `#NaN` to the URL!).
-show-text: true
goto: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
// We use this assert-position to know where we will click.
assert-position: ("//*[@id='1']", {"x": 104, "y": 112})