Fixed dark mode compatibility for old browsers.

refer to issue #30
This commit is contained in:
Cotes Chung 2020-02-25 20:18:11 +08:00
parent 73d1027acc
commit d6586ec2e6
3 changed files with 40 additions and 59 deletions

View file

@ -106,42 +106,39 @@
} // dark-scheme } // dark-scheme
@mixin light-mode-invisible { @mixin set-visible($light-display, $dark-display) {
*[light-mode-invisible] { [light-mode-invisible] {
display: none; display: $light-display;
}
[dark-mode-invisible] {
display: $dark-display;
} }
} }
@mixin dark-mode-invisible { @mixin mode-toggle($dark-mode: false) {
*[dark-mode-invisible] { @if $dark-mode {
display: none; @include set-visible(inline-block, none);
@include dark-scheme;
} @else {
@include set-visible(none, inline-block);
} }
} }
@media (prefers-color-scheme: light) {
html:not([mode]), html[mode=light] { html:not([mode]), html[mode=light] {
@include light-mode-invisible; @include mode-toggle();
} }
html[mode=dark] { html[mode=dark] {
@include dark-scheme; @include mode-toggle(true);
@include dark-mode-invisible;
} }
} // light prefers
@media (prefers-color-scheme: dark) { @media (prefers-color-scheme: dark) {
html:not([mode]), html[mode=dark] { html:not([mode]), html[mode=dark] {
@include dark-scheme; @include mode-toggle(true);
@include dark-mode-invisible;
} }
html[mode=light] { html[mode=light] {
@include light-mode-invisible; @include mode-toggle();
}
} }
} // dark prefers

View file

@ -6,7 +6,13 @@
* MIT Licensed * MIT Licensed
*/ */
@mixin dark-scheme { @mixin box-shadow($val) {
-moz-box-shadow: $val;
-webkit-box-shadow: $val;
box-shadow: $val;
}
@mixin dark-syntax-scheme {
/* syntax highlight colors from https://raw.githubusercontent.com/jwarby/pygments-css/master/monokai.css */ /* syntax highlight colors from https://raw.githubusercontent.com/jwarby/pygments-css/master/monokai.css */
--highlight-pre-bg: #272822; --highlight-pre-bg: #272822;
--highlight-hll-bg: #272822; --highlight-hll-bg: #272822;
@ -75,6 +81,7 @@
/* My styles */ /* My styles */
--highlight-lineno: #6c6c6d; --highlight-lineno: #6c6c6d;
--highlight-lineno-border: #3c4042; --highlight-lineno-border: #3c4042;
--highlighter-rouge: #de6b18;
pre { pre {
color: #818c96; /* override Bootstrap */ color: #818c96; /* override Bootstrap */
@ -83,16 +90,9 @@
kbd { kbd {
background-color: black; background-color: black;
} }
.highlight {
@include box-shadow(none);
} }
@media (prefers-color-scheme: dark) { } // mixin dark-syntax-scheme
html:not([mode]), html[mode=dark] {
@include dark-scheme;
}
}
@media (prefers-color-scheme: light) {
html[mode=dark] {
@include dark-scheme;
}
}

View file

@ -88,6 +88,7 @@
.highlighter-rouge { .highlighter-rouge {
@extend %highlight-pre-bg; @extend %highlight-pre-bg;
@extend %code-snippet-radius; @extend %code-snippet-radius;
color: var(--highlighter-rouge, black);
margin-bottom: 1.2em; /* Override BS Inline-code style */ margin-bottom: 1.2em; /* Override BS Inline-code style */
} }
@ -100,7 +101,7 @@
@extend %highlight-pre-bg; @extend %highlight-pre-bg;
} }
overflow: auto; overflow: auto;
@include box-shadow(inset 0 0 2px #c2c6cc);
.lineno { .lineno {
margin: .8rem 0rem; margin: .8rem 0rem;
padding: 0 .5rem; padding: 0 .5rem;
@ -142,11 +143,11 @@ code {
-ms-hyphens: none; -ms-hyphens: none;
-moz-hyphens: none; -moz-hyphens: none;
hyphens: none; hyphens: none;
&.highlighter-rouge { &.highlighter-rouge {
padding: 2px 4px; padding: 2px 4px;
margin: 0 .3rem; margin: 0 .3rem;
border-radius: 4px; border-radius: 4px;
border: 1px solid var(--highlight-pre-bg, #e9ecef);
} }
} }
@ -155,7 +156,6 @@ td.rouge-code {
padding-right: 1rem; padding-right: 1rem;
} }
/* Hide line numbers for defualt, console, and terminal code snippets */ /* Hide line numbers for defualt, console, and terminal code snippets */
div[class^='highlighter-rouge'] pre.lineno, div[class^='highlighter-rouge'] pre.lineno,
div.language-console.highlighter-rouge pre.lineno, div.language-console.highlighter-rouge pre.lineno,
@ -169,28 +169,12 @@ div.language-terminal.highlighter-rouge td.rouge-code {
padding: .8rem 1rem; padding: .8rem 1rem;
} }
@mixin light-syntax-base { html[mode=dark] {
.highlight { @include dark-syntax-scheme;
-moz-box-shadow: inset 0 0 2px #c2c6cc;
-webkit-box-shadow: inset 0 0 2px #c2c6cc;
box-shadow: inset 0 0 2px #c2c6cc;
}
.highlighter-rouge {
color: black;
}
code.highlighter-rouge {
border: 1px solid #e9ecef;
}
}
@media (prefers-color-scheme: light) {
html:not([mode=dark]) {
@include light-syntax-base;
}
} }
@media (prefers-color-scheme: dark) { @media (prefers-color-scheme: dark) {
html[mode=light] { html:not([mode]), html[mode=dark] {
@include light-syntax-base; @include dark-syntax-scheme;
} }
} }