Skip to content

Commit 4587306

Browse files
authored
Add a light code theme for light mode (#235)
1 parent 1431d24 commit 4587306

4 files changed

Lines changed: 18 additions & 6 deletions

File tree

app/assets/main.css

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ button {
157157
top: 0;
158158
}
159159

160+
/* Shiki theme colors */
161+
html.light .shiki,
162+
html.light .shiki span {
163+
color: var(--shiki-light) !important;
164+
background-color: var(--shiki-light-bg) !important;
165+
font-style: var(--shiki-light-font-style) !important;
166+
font-weight: var(--shiki-light-font-weight) !important;
167+
text-decoration: var(--shiki-light-text-decoration) !important;
168+
}
169+
160170
/* README prose styling */
161171
.readme-content {
162172
color: var(--fg-muted);
@@ -238,7 +248,7 @@ button {
238248
.readme-content pre,
239249
.readme-content .shiki {
240250
background: oklch(0.145 0 0) !important;
241-
border: 1px solid oklch(0.2686 0 0);
251+
border: 1px solid var(--border);
242252
border-radius: 8px;
243253
padding: 1rem;
244254
overflow-x: auto;

server/utils/code-highlight.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ export async function highlightCode(
265265
try {
266266
let html = shiki.codeToHtml(code, {
267267
lang: language,
268-
theme: 'github-dark',
268+
themes: { light: 'github-light', dark: 'github-dark' },
269+
defaultColor: 'dark',
269270
})
270271

271272
// Shiki doesn't encode > in text content (e.g., arrow functions)

server/utils/shiki.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ let highlighter: HighlighterCore | null = null
66
export async function getShikiHighlighter(): Promise<HighlighterCore> {
77
if (!highlighter) {
88
highlighter = await createHighlighterCore({
9-
themes: [import('@shikijs/themes/github-dark')],
9+
themes: [import('@shikijs/themes/github-dark'), import('@shikijs/themes/github-light')],
1010
langs: [
1111
// Core web languages
1212
import('@shikijs/langs/javascript'),
@@ -66,7 +66,8 @@ export function highlightCodeSync(shiki: HighlighterCore, code: string, language
6666
try {
6767
let html = shiki.codeToHtml(code, {
6868
lang: language,
69-
theme: 'github-dark',
69+
themes: { light: 'github-light', dark: 'github-dark' },
70+
defaultColor: 'dark',
7071
})
7172
// Remove inline style from <pre> tag so CSS can control appearance
7273
html = html.replace(/<pre([^>]*)\s+style="[^"]*"/, '<pre$1')

test/unit/docs-text.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ describe('renderMarkdown', () => {
242242
const input = '```ts\nconst a = 1\n```\n\nSome text\n\n```js\nconst b = 2\n```'
243243
const result = await renderMarkdown(input, emptyLookup)
244244
expect(result).toContain('Some text')
245-
// Both code blocks should be highlighted
246-
expect((result.match(/shiki/g) || []).length).toBe(2)
245+
// Both code blocks should be highlighted, search for `shiki` class
246+
expect((result.match(/["\s]shiki["\s]/g) || []).length).toBe(2)
247247
})
248248

249249
it('should not confuse inline code with fenced code blocks', async () => {

0 commit comments

Comments
 (0)