Skip to content

Commit 556110e

Browse files
committed
Fixed dark mode compatibility for old browsers.
refer to issue cotes2020#30
1 parent 06ccd94 commit 556110e

3 files changed

Lines changed: 38 additions & 57 deletions

File tree

assets/css/_dark/dark-main.scss

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -106,42 +106,39 @@
106106
} // dark-scheme
107107

108108

109-
@mixin light-mode-invisible {
110-
*[light-mode-invisible] {
111-
display: none;
109+
@mixin set-visible($light-display, $dark-display) {
110+
[light-mode-invisible] {
111+
display: $light-display;
112112
}
113-
}
114113

115-
@mixin dark-mode-invisible {
116-
*[dark-mode-invisible] {
117-
display: none;
114+
[dark-mode-invisible] {
115+
display: $dark-display;
118116
}
119117
}
120118

121-
@media (prefers-color-scheme: light) {
122-
123-
html:not([mode]), html[mode=light] {
124-
@include light-mode-invisible;
125-
}
126-
127-
html[mode=dark] {
119+
@mixin mode-toggle($dark-mode: false) {
120+
@if $dark-mode {
121+
@include set-visible(inline-block, none);
128122
@include dark-scheme;
129-
@include dark-mode-invisible;
123+
} @else {
124+
@include set-visible(none, inline-block);
130125
}
126+
}
131127

132-
} // light prefers
128+
html:not([mode]), html[mode=light] {
129+
@include mode-toggle();
130+
}
133131

132+
html[mode=dark] {
133+
@include mode-toggle(true);
134+
}
134135

135136
@media (prefers-color-scheme: dark) {
136-
137137
html:not([mode]), html[mode=dark] {
138-
@include dark-scheme;
139-
@include dark-mode-invisible;
138+
@include mode-toggle(true);
140139
}
141140

142141
html[mode=light] {
143-
@include light-mode-invisible;
142+
@include mode-toggle();
144143
}
145-
146-
} // dark prefers
147-
144+
}

assets/css/_dark/dark-syntax.scss

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
* MIT Licensed
77
*/
88

9-
@mixin dark-scheme {
9+
@mixin box-shadow($val) {
10+
-moz-box-shadow: $val;
11+
-webkit-box-shadow: $val;
12+
box-shadow: $val;
13+
}
14+
15+
@mixin dark-syntax-scheme {
1016
/* syntax highlight colors from https://raw.githubusercontent.com/jwarby/pygments-css/master/monokai.css */
1117
--highlight-pre-bg: #272822;
1218
--highlight-hll-bg: #272822;
@@ -75,6 +81,7 @@
7581
/* My styles */
7682
--highlight-lineno: #6c6c6d;
7783
--highlight-lineno-border: #3c4042;
84+
--highlighter-rouge: #de6b18;
7885

7986
pre {
8087
color: #818c96; /* override Bootstrap */
@@ -83,16 +90,9 @@
8390
kbd {
8491
background-color: black;
8592
}
86-
}
8793

88-
@media (prefers-color-scheme: dark) {
89-
html:not([mode]), html[mode=dark] {
90-
@include dark-scheme;
94+
.highlight {
95+
@include box-shadow(none);
9196
}
92-
}
9397

94-
@media (prefers-color-scheme: light) {
95-
html[mode=dark] {
96-
@include dark-scheme;
97-
}
98-
}
98+
} // mixin dark-syntax-scheme

assets/css/syntax.scss

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
.highlighter-rouge {
8989
@extend %highlight-pre-bg;
9090
@extend %code-snippet-radius;
91+
color: var(--highlighter-rouge, black);
9192
margin-bottom: 1.2em; /* Override BS Inline-code style */
9293
}
9394

@@ -100,7 +101,7 @@
100101
@extend %highlight-pre-bg;
101102
}
102103
overflow: auto;
103-
104+
@include box-shadow(inset 0 0 2px #c2c6cc);
104105
.lineno {
105106
margin: .8rem 0rem;
106107
padding: 0 .5rem;
@@ -142,11 +143,11 @@ code {
142143
-ms-hyphens: none;
143144
-moz-hyphens: none;
144145
hyphens: none;
145-
146146
&.highlighter-rouge {
147147
padding: 2px 4px;
148148
margin: 0 .3rem;
149149
border-radius: 4px;
150+
border: 1px solid var(--highlight-pre-bg, #e9ecef);
150151
}
151152
}
152153

@@ -155,7 +156,6 @@ td.rouge-code {
155156
padding-right: 1rem;
156157
}
157158

158-
159159
/* Hide line numbers for defualt, console, and terminal code snippets */
160160
div[class^='highlighter-rouge'] pre.lineno,
161161
div.language-console.highlighter-rouge pre.lineno,
@@ -169,28 +169,12 @@ div.language-terminal.highlighter-rouge td.rouge-code {
169169
padding: .8rem 1rem;
170170
}
171171

172-
@mixin light-syntax-base {
173-
.highlight {
174-
-moz-box-shadow: inset 0 0 2px #c2c6cc;
175-
-webkit-box-shadow: inset 0 0 2px #c2c6cc;
176-
box-shadow: inset 0 0 2px #c2c6cc;
177-
}
178-
.highlighter-rouge {
179-
color: black;
180-
}
181-
code.highlighter-rouge {
182-
border: 1px solid #e9ecef;
183-
}
184-
}
185-
186-
@media (prefers-color-scheme: light) {
187-
html:not([mode=dark]) {
188-
@include light-syntax-base;
189-
}
172+
html[mode=dark] {
173+
@include dark-syntax-scheme;
190174
}
191175

192176
@media (prefers-color-scheme: dark) {
193-
html[mode=light] {
194-
@include light-syntax-base;
177+
html:not([mode]), html[mode=dark] {
178+
@include dark-syntax-scheme;
195179
}
196180
}

0 commit comments

Comments
 (0)