Skip to content

Commit 66a00e7

Browse files
book2: use CSS variables for code colors to fix dark-mode contrast
Book pages used hard-coded colors for inline and block code in book2.scss, which resulted in poor contrast in dark mode. Replace those hard-coded values with CSS variables and override the variables in dark mode, allowing the existing theme mechanism to handle light and dark appearances consistently.
1 parent 0b012b1 commit 66a00e7

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

assets/sass/book2.scss

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
.edition2 {
2+
/* Book code colors (light mode defaults) */
3+
--book-code-color: #333;
4+
--book-code-bg: #eee;
5+
--book-code-border: #f5f5f5;
6+
27
* {
38
box-sizing: border-box;
49
}
@@ -474,11 +479,11 @@
474479
}
475480

476481
pre {
477-
background: #eee;
482+
background: var(--book-code-bg);
478483

479484
code {
480485
display: inline;
481-
background: #eee;
486+
background: var(--book-code-bg);
482487
border: 0;
483488
}
484489
}
@@ -488,14 +493,14 @@
488493
overflow-x: auto;
489494
font-size: 0.9em;
490495
line-height: 120%;
491-
color: #333;
496+
color: var(--book-code-color);
492497
}
493498

494499
code { /* inline code */
495500
padding: 0;
496-
color: #333;
497-
background: #eee;
498-
border: 1px solid #f5f5f5;
501+
color: var(--book-code-color);
502+
background: var(--book-code-bg);
503+
border: 1px solid var(--book-code-border);
499504
}
500505

501506
table pre { /* code blocks within tables */

assets/sass/dark-mode.scss

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,6 @@
117117
background-color: #5e5951;
118118

119119
}
120-
/* Book pages: fix code contrast in dark mode */
121-
.book code {
122-
color: var(--fixed-width-font-color);
123-
}
124-
125-
.book pre {
126-
color: var(--fixed-width-font-color);
127-
}
128120

129121
form#search {
130122
@include box-shadow(none);
@@ -149,6 +141,11 @@
149141
.cheat-sheet img {
150142
filter: invert(60%);
151143
}
144+
145+
/* Book pages: code colors */
146+
--book-code-color: #{$fixed-width-font-color};
147+
--book-code-bg: #{$no-changes-bg-color};
148+
--book-code-border: #{$pre-border};
152149
}
153150
}
154151

0 commit comments

Comments
 (0)