Skip to content

Commit e8cc7c6

Browse files
rustdoc: merge theme css into rustdoc.css
Based on rust-lang#115812 (comment) Having them in separate files used to make more sense, before the migration to CSS variables made the theme files as small as they are nowadays. This is already how docs.rs and mdBook do it.
1 parent d84e02e commit e8cc7c6

File tree

16 files changed

+755
-425
lines changed

16 files changed

+755
-425
lines changed

src/librustdoc/config.rs

+18-6
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,15 @@ impl Options {
402402

403403
let to_check = matches.opt_strs("check-theme");
404404
if !to_check.is_empty() {
405-
let paths = match theme::load_css_paths(
406-
std::str::from_utf8(static_files::STATIC_FILES.theme_light_css.bytes).unwrap(),
407-
) {
405+
let mut content =
406+
std::str::from_utf8(static_files::STATIC_FILES.rustdoc_css.bytes).unwrap();
407+
if let Some((_, inside)) = content.split_once("/* Begin theme: light */") {
408+
content = inside;
409+
}
410+
if let Some((inside, _)) = content.split_once("/* End theme: light */") {
411+
content = inside;
412+
}
413+
let paths = match theme::load_css_paths(content) {
408414
Ok(p) => p,
409415
Err(e) => {
410416
diag.struct_err(e).emit();
@@ -545,9 +551,15 @@ impl Options {
545551

546552
let mut themes = Vec::new();
547553
if matches.opt_present("theme") {
548-
let paths = match theme::load_css_paths(
549-
std::str::from_utf8(static_files::STATIC_FILES.theme_light_css.bytes).unwrap(),
550-
) {
554+
let mut content =
555+
std::str::from_utf8(static_files::STATIC_FILES.rustdoc_css.bytes).unwrap();
556+
if let Some((_, inside)) = content.split_once("/* Begin theme: light */") {
557+
content = inside;
558+
}
559+
if let Some((inside, _)) = content.split_once("/* End theme: light */") {
560+
content = inside;
561+
}
562+
let paths = match theme::load_css_paths(content) {
551563
Ok(p) => p,
552564
Err(e) => {
553565
diag.struct_err(e).emit();

src/librustdoc/html/render/context.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ pub(crate) struct SharedContext<'tcx> {
103103
pub(super) module_sorting: ModuleSorting,
104104
/// Additional CSS files to be added to the generated docs.
105105
pub(crate) style_files: Vec<StylePath>,
106-
/// Suffix to be added on resource files (if suffix is "-v2" then "light.css" becomes
107-
/// "light-v2.css").
106+
/// Suffix to add on resource files (if suffix is "-v2" then "search-index.js" becomes
107+
/// "search-index-v2.js").
108108
pub(crate) resource_suffix: String,
109109
/// Optional path string to be used to load static files on output pages. If not set, uses
110110
/// combinations of `../` to reach the documentation root.
@@ -652,19 +652,10 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
652652
</noscript>\
653653
<link rel=\"stylesheet\" \
654654
href=\"{static_root_path}{settings_css}\">\
655-
<script defer src=\"{static_root_path}{settings_js}\"></script>\
656-
<link rel=\"preload\" href=\"{static_root_path}{theme_light_css}\" \
657-
as=\"style\">\
658-
<link rel=\"preload\" href=\"{static_root_path}{theme_dark_css}\" \
659-
as=\"style\">\
660-
<link rel=\"preload\" href=\"{static_root_path}{theme_ayu_css}\" \
661-
as=\"style\">",
655+
<script defer src=\"{static_root_path}{settings_js}\"></script>",
662656
static_root_path = page.get_static_root_path(),
663657
settings_css = static_files::STATIC_FILES.settings_css,
664658
settings_js = static_files::STATIC_FILES.settings_js,
665-
theme_light_css = static_files::STATIC_FILES.theme_light_css,
666-
theme_dark_css = static_files::STATIC_FILES.theme_dark_css,
667-
theme_ayu_css = static_files::STATIC_FILES.theme_ayu_css,
668659
);
669660
// Pre-load all theme CSS files, so that switching feels seamless.
670661
//

src/librustdoc/html/static/css/noscript.css

+211
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,214 @@ nav.sub {
2222
.source .sidebar {
2323
display: none;
2424
}
25+
26+
/* Begin: styles for themes
27+
Keep the default light and dark themes synchronized with the ones
28+
in rustdoc.css */
29+
30+
/* Begin theme: light */
31+
:root {
32+
--main-background-color: white;
33+
--main-color: black;
34+
--settings-input-color: #2196f3;
35+
--settings-input-border-color: #717171;
36+
--settings-button-color: #000;
37+
--settings-button-border-focus: #717171;
38+
--sidebar-background-color: #F5F5F5;
39+
--sidebar-background-color-hover: #E0E0E0;
40+
--code-block-background-color: #F5F5F5;
41+
--scrollbar-track-background-color: #dcdcdc;
42+
--scrollbar-thumb-background-color: rgba(36, 37, 39, 0.6);
43+
--scrollbar-color: rgba(36, 37, 39, 0.6) #d9d9d9;
44+
--headings-border-bottom-color: #ddd;
45+
--border-color: #e0e0e0;
46+
--button-background-color: #fff;
47+
--right-side-color: grey;
48+
--code-attribute-color: #999;
49+
--toggles-color: #999;
50+
--toggle-filter: none;
51+
--search-input-focused-border-color: #66afe9;
52+
--copy-path-button-color: #999;
53+
--copy-path-img-filter: invert(50%);
54+
--copy-path-img-hover-filter: invert(35%);
55+
--codeblock-error-hover-color: rgb(255, 0, 0);
56+
--codeblock-error-color: rgba(255, 0, 0, .5);
57+
--codeblock-ignore-hover-color: rgb(255, 142, 0);
58+
--codeblock-ignore-color: rgba(255, 142, 0, .6);
59+
--type-link-color: #ad378a;
60+
--trait-link-color: #6e4fc9;
61+
--assoc-item-link-color: #3873ad;
62+
--function-link-color: #ad7c37;
63+
--macro-link-color: #068000;
64+
--keyword-link-color: #3873ad;
65+
--mod-link-color: #3873ad;
66+
--link-color: #3873ad;
67+
--sidebar-link-color: #356da4;
68+
--sidebar-current-link-background-color: #fff;
69+
--search-result-link-focus-background-color: #ccc;
70+
--search-result-border-color: #aaa3;
71+
--search-color: #000;
72+
--search-error-code-background-color: #d0cccc;
73+
--search-results-alias-color: #000;
74+
--search-results-grey-color: #999;
75+
--search-tab-title-count-color: #888;
76+
--search-tab-button-not-selected-border-top-color: #e6e6e6;
77+
--search-tab-button-not-selected-background: #e6e6e6;
78+
--search-tab-button-selected-border-top-color: #0089ff;
79+
--search-tab-button-selected-background: #ffffff;
80+
--stab-background-color: #fff5d6;
81+
--stab-code-color: #000;
82+
--code-highlight-kw-color: #8959a8;
83+
--code-highlight-kw-2-color: #4271ae;
84+
--code-highlight-lifetime-color: #b76514;
85+
--code-highlight-prelude-color: #4271ae;
86+
--code-highlight-prelude-val-color: #c82829;
87+
--code-highlight-number-color: #718c00;
88+
--code-highlight-string-color: #718c00;
89+
--code-highlight-literal-color: #c82829;
90+
--code-highlight-attribute-color: #c82829;
91+
--code-highlight-self-color: #c82829;
92+
--code-highlight-macro-color: #3e999f;
93+
--code-highlight-question-mark-color: #ff9011;
94+
--code-highlight-comment-color: #8e908c;
95+
--code-highlight-doc-comment-color: #4d4d4c;
96+
--src-line-numbers-span-color: #c67e2d;
97+
--src-line-number-highlighted-background-color: #fdffd3;
98+
--test-arrow-color: #f5f5f5;
99+
--test-arrow-background-color: rgba(78, 139, 202, 0.2);
100+
--test-arrow-hover-color: #f5f5f5;
101+
--test-arrow-hover-background-color: #4e8bca;
102+
--target-background-color: #fdffd3;
103+
--target-border-color: #ad7c37;
104+
--kbd-color: #000;
105+
--kbd-background: #fafbfc;
106+
--kbd-box-shadow-color: #c6cbd1;
107+
--rust-logo-filter: initial;
108+
/* match border-color; uses https://codepen.io/sosuke/pen/Pjoqqp */
109+
--crate-search-div-filter: invert(100%) sepia(0%) saturate(4223%) hue-rotate(289deg)
110+
brightness(114%) contrast(76%);
111+
--crate-search-div-hover-filter: invert(44%) sepia(18%) saturate(23%) hue-rotate(317deg)
112+
brightness(96%) contrast(93%);
113+
--crate-search-hover-border: #717171;
114+
--source-sidebar-background-selected: #fff;
115+
--source-sidebar-background-hover: #e0e0e0;
116+
--table-alt-row-background-color: #F5F5F5;
117+
--codeblock-link-background: #eee;
118+
--scrape-example-toggle-line-background: #ccc;
119+
--scrape-example-toggle-line-hover-background: #999;
120+
--scrape-example-code-line-highlight: #fcffd6;
121+
--scrape-example-code-line-highlight-focus: #f6fdb0;
122+
--scrape-example-help-border-color: #555;
123+
--scrape-example-help-color: #333;
124+
--scrape-example-help-hover-border-color: #000;
125+
--scrape-example-help-hover-color: #000;
126+
--scrape-example-code-wrapper-background-start: rgba(255, 255, 255, 1);
127+
--scrape-example-code-wrapper-background-end: rgba(255, 255, 255, 0);
128+
}
129+
/* End theme: light */
130+
131+
@media (prefers-color-scheme: dark) {
132+
/* Begin theme: dark */
133+
:root {
134+
--main-background-color: #353535;
135+
--main-color: #ddd;
136+
--settings-input-color: #2196f3;
137+
--settings-input-border-color: #999;
138+
--settings-button-color: #000;
139+
--settings-button-border-focus: #ffb900;
140+
--sidebar-background-color: #505050;
141+
--sidebar-background-color-hover: #676767;
142+
--code-block-background-color: #2A2A2A;
143+
--scrollbar-track-background-color: #717171;
144+
--scrollbar-thumb-background-color: rgba(32, 34, 37, .6);
145+
--scrollbar-color: rgba(32,34,37,.6) #5a5a5a;
146+
--headings-border-bottom-color: #d2d2d2;
147+
--border-color: #e0e0e0;
148+
--button-background-color: #f0f0f0;
149+
--right-side-color: grey;
150+
--code-attribute-color: #999;
151+
--toggles-color: #999;
152+
--toggle-filter: invert(100%);
153+
--search-input-focused-border-color: #008dfd;
154+
--copy-path-button-color: #999;
155+
--copy-path-img-filter: invert(50%);
156+
--copy-path-img-hover-filter: invert(65%);
157+
--codeblock-error-hover-color: rgb(255, 0, 0);
158+
--codeblock-error-color: rgba(255, 0, 0, .5);
159+
--codeblock-ignore-hover-color: rgb(255, 142, 0);
160+
--codeblock-ignore-color: rgba(255, 142, 0, .6);
161+
--type-link-color: #2dbfb8;
162+
--trait-link-color: #b78cf2;
163+
--assoc-item-link-color: #d2991d;
164+
--function-link-color: #2bab63;
165+
--macro-link-color: #09bd00;
166+
--keyword-link-color: #d2991d;
167+
--mod-link-color: #d2991d;
168+
--link-color: #d2991d;
169+
--sidebar-link-color: #fdbf35;
170+
--sidebar-current-link-background-color: #444;
171+
--search-result-link-focus-background-color: #616161;
172+
--search-result-border-color: #aaa3;
173+
--search-color: #111;
174+
--search-error-code-background-color: #484848;
175+
--search-results-alias-color: #fff;
176+
--search-results-grey-color: #ccc;
177+
--search-tab-title-count-color: #888;
178+
--search-tab-button-not-selected-border-top-color: #252525;
179+
--search-tab-button-not-selected-background: #252525;
180+
--search-tab-button-selected-border-top-color: #0089ff;
181+
--search-tab-button-selected-background: #353535;
182+
--stab-background-color: #314559;
183+
--stab-code-color: #e6e1cf;
184+
--code-highlight-kw-color: #ab8ac1;
185+
--code-highlight-kw-2-color: #769acb;
186+
--code-highlight-lifetime-color: #d97f26;
187+
--code-highlight-prelude-color: #769acb;
188+
--code-highlight-prelude-val-color: #ee6868;
189+
--code-highlight-number-color: #83a300;
190+
--code-highlight-string-color: #83a300;
191+
--code-highlight-literal-color: #ee6868;
192+
--code-highlight-attribute-color: #ee6868;
193+
--code-highlight-self-color: #ee6868;
194+
--code-highlight-macro-color: #3e999f;
195+
--code-highlight-question-mark-color: #ff9011;
196+
--code-highlight-comment-color: #8d8d8b;
197+
--code-highlight-doc-comment-color: #8ca375;
198+
--src-line-numbers-span-color: #3b91e2;
199+
--src-line-number-highlighted-background-color: #0a042f;
200+
--test-arrow-color: #dedede;
201+
--test-arrow-background-color: rgba(78, 139, 202, 0.2);
202+
--test-arrow-hover-color: #dedede;
203+
--test-arrow-hover-background-color: #4e8bca;
204+
--target-background-color: #494a3d;
205+
--target-border-color: #bb7410;
206+
--kbd-color: #000;
207+
--kbd-background: #fafbfc;
208+
--kbd-box-shadow-color: #c6cbd1;
209+
--rust-logo-filter: drop-shadow(1px 0 0px #fff)
210+
drop-shadow(0 1px 0 #fff)
211+
drop-shadow(-1px 0 0 #fff)
212+
drop-shadow(0 -1px 0 #fff);
213+
/* match border-color; uses https://codepen.io/sosuke/pen/Pjoqqp */
214+
--crate-search-div-filter: invert(94%) sepia(0%) saturate(721%) hue-rotate(255deg)
215+
brightness(90%) contrast(90%);
216+
--crate-search-div-hover-filter: invert(69%) sepia(60%) saturate(6613%) hue-rotate(184deg)
217+
brightness(100%) contrast(91%);
218+
--crate-search-hover-border: #2196f3;
219+
--source-sidebar-background-selected: #333;
220+
--source-sidebar-background-hover: #444;
221+
--table-alt-row-background-color: #2A2A2A;
222+
--codeblock-link-background: #333;
223+
--scrape-example-toggle-line-background: #999;
224+
--scrape-example-toggle-line-hover-background: #c5c5c5;
225+
--scrape-example-code-line-highlight: rgb(91, 59, 1);
226+
--scrape-example-code-line-highlight-focus: rgb(124, 75, 15);
227+
--scrape-example-help-border-color: #aaa;
228+
--scrape-example-help-color: #eee;
229+
--scrape-example-help-hover-border-color: #fff;
230+
--scrape-example-help-hover-color: #fff;
231+
--scrape-example-code-wrapper-background-start: rgba(53, 53, 53, 1);
232+
--scrape-example-code-wrapper-background-end: rgba(53, 53, 53, 0);
233+
}
234+
/* End theme: dark */
235+
}

0 commit comments

Comments
 (0)