Skip to content

Commit 7c5ee29

Browse files
committed
chore: replace gh-light green and red color
1 parent fdd4c99 commit 7c5ee29

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

server/utils/shiki.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
1+
import type { ThemeRegistration } from 'shiki'
12
import { createHighlighterCore, type HighlighterCore } from 'shiki/core'
23
import { createJavaScriptRegexEngine } from 'shiki/engine/javascript'
34

45
let highlighter: HighlighterCore | null = null
56

7+
function replaceThemeColors(
8+
theme: ThemeRegistration,
9+
replacements: Record<string, string>,
10+
): ThemeRegistration {
11+
let themeString = JSON.stringify(theme)
12+
for (const [oldColor, newColor] of Object.entries(replacements)) {
13+
themeString = themeString.replaceAll(oldColor, newColor)
14+
themeString = themeString.replaceAll(oldColor.toLowerCase(), newColor)
15+
themeString = themeString.replaceAll(oldColor.toUpperCase(), newColor)
16+
}
17+
return JSON.parse(themeString)
18+
}
19+
620
export async function getShikiHighlighter(): Promise<HighlighterCore> {
721
if (!highlighter) {
822
highlighter = await createHighlighterCore({
9-
themes: [import('@shikijs/themes/github-dark'), import('@shikijs/themes/github-light')],
23+
themes: [
24+
import('@shikijs/themes/github-dark'),
25+
import('@shikijs/themes/github-light').then(t =>
26+
replaceThemeColors(t.default ?? t, {
27+
'#22863A': '#227436', // green
28+
'#B31D28': '#AC222F', // red
29+
}),
30+
),
31+
],
1032
langs: [
1133
// Core web languages
1234
import('@shikijs/langs/javascript'),

0 commit comments

Comments
 (0)