Skip to content

Commit 297badc

Browse files
authored
Implement dark mode for syntax highlighted code blocks (#8680)
Instead of unconditionally importing the `github.css` theme, we use a custom theme that uses the `light-dark()` fn. This custom theme is a merging the `github.css` and `github-dark.css` files into one.
1 parent 1b1c17a commit 297badc

File tree

2 files changed

+81
-9
lines changed

2 files changed

+81
-9
lines changed

app/components/text-content.module.css

+81-8
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,6 @@
3030
border-radius: var(--space-3xs);
3131
}
3232

33-
:global(.hljs) {
34-
color: unset;
35-
background: unset;
36-
display: unset;
37-
overflow-x: unset;
38-
padding: 0;
39-
}
40-
4133
p, li {
4234
code {
4335
background-color: light-dark(#f6f8fa, #383836);
@@ -92,4 +84,85 @@
9284
}
9385
}
9486
}
87+
88+
/*
89+
* This is a combination of the `github.css` and `github-dark.css` themes,
90+
* but merged together using the `light-dark` function.
91+
*
92+
* see https://github.com/highlightjs/highlight.js/blob/11.9.0/src/styles/github.css
93+
* and https://github.com/highlightjs/highlight.js/blob/11.9.0/src/styles/github-dark.css
94+
*/
95+
:global(.hljs-doctag),
96+
:global(.hljs-keyword),
97+
:global(.hljs-meta) :global(.hljs-keyword),
98+
:global(.hljs-template-tag),
99+
:global(.hljs-template-variable),
100+
:global(.hljs-type),
101+
:global(.hljs-variable.language_) {
102+
color: light-dark(#d73a49, #ff7b72);
103+
}
104+
:global(.hljs-title),
105+
:global(.hljs-title.class_),
106+
:global(.hljs-title.class_.inherited__),
107+
:global(.hljs-title.function_) {
108+
color: light-dark(#6f42c1, #d2a8ff);
109+
}
110+
:global(.hljs-attr),
111+
:global(.hljs-attribute),
112+
:global(.hljs-literal),
113+
:global(.hljs-meta),
114+
:global(.hljs-number),
115+
:global(.hljs-operator),
116+
:global(.hljs-variable),
117+
:global(.hljs-selector-attr),
118+
:global(.hljs-selector-class),
119+
:global(.hljs-selector-id) {
120+
color: light-dark(#005cc5, #79c0ff);
121+
}
122+
:global(.hljs-regex)p,
123+
:global(.hljs-strin)g,
124+
:global(.hljs-meta) :global(.hljs-string) {
125+
color: light-dark(#032f62, #a5d6ff);
126+
}
127+
:global(.hljs-built_in),
128+
:global(.hljs-symbol) {
129+
color: light-dark(#e36209, #ffa657);
130+
}
131+
:global(.hljs-comment),
132+
:global(.hljs-code),
133+
:global(.hljs-formula) {
134+
color: light-dark(#6a737d, #8b949e);
135+
}
136+
:global(.hljs-name),
137+
:global(.hljs-quote),
138+
:global(.hljs-selector-tag),
139+
:global(.hljs-selector-pseudo) {
140+
color: light-dark(#22863a, #7ee787);
141+
}
142+
:global(.hljs-subst) {
143+
color: light-dark(#24292e, #c9d1d9);
144+
}
145+
:global(.hljs-section) {
146+
color: light-dark(#005cc5, #1f6feb);
147+
font-weight: bold
148+
}
149+
:global(.hljs-bullet) {
150+
color: light-dark(#735c0f, #f2cc60);
151+
}
152+
:global(.hljs-emphasis) {
153+
color: light-dark(#24292e, #c9d1d9);
154+
font-style: italic
155+
}
156+
:global(.hljs-strong) {
157+
color: light-dark(#24292e, #c9d1d9);
158+
font-weight: bold
159+
}
160+
:global(.hljs-addition) {
161+
color: light-dark(#22863a, #aff5b4);
162+
background-color: light-dark(#f0fff4, #033a16);
163+
}
164+
:global(.hljs-deletion) {
165+
color: light-dark(#b31d28, #ffdcd7);
166+
background-color: light-dark(#ffeef0, #67060c);
167+
}
95168
}

app/modifiers/highlight-syntax.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { modifier } from 'ember-modifier';
22
import hljs from 'highlight.js/lib/core';
3-
import 'highlight.js/styles/github.css';
43
import bash from 'highlight.js/lib/languages/bash';
54
import c from 'highlight.js/lib/languages/c';
65
import cpp from 'highlight.js/lib/languages/cpp';

0 commit comments

Comments
 (0)