Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions packages/shiki/src/highlighter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export async function getHighlighter(options: HighlighterOptions): Promise<Highl
* Instead, we work around this by using valid hex color codes as lookups in a
* final "repair" step which translates those codes to the correct CSS variables.
*/
const COLOR_REPLACEMENTS: Record<string, string> = {
let COLOR_REPLACEMENTS: Record<string, string> = {
'#000001': 'var(--shiki-color-text)',
'#000002': 'var(--shiki-color-background)',
'#000004': 'var(--shiki-token-constant)',
Expand All @@ -77,7 +77,9 @@ export async function getHighlighter(options: HighlighterOptions): Promise<Highl
'#000011': 'var(--shiki-token-punctuation)',
'#000012': 'var(--shiki-token-link)'
}

function setColorReplacements(map: Record<string, string>) {
COLOR_REPLACEMENTS = map
}
function fixCssVariablesTheme(theme: IShikiTheme, colorMap: string[]) {
theme.bg = COLOR_REPLACEMENTS[theme.bg] || theme.bg
theme.fg = COLOR_REPLACEMENTS[theme.fg] || theme.fg
Expand All @@ -96,7 +98,7 @@ export async function getHighlighter(options: HighlighterOptions): Promise<Highl
_currentTheme = _theme
}
const _colorMap = _registry.getColorMap()
if (_theme.name === 'css-variables') {
if (_theme.type === 'css') {
fixCssVariablesTheme(_theme, _colorMap)
}
return { _theme, _colorMap }
Expand Down Expand Up @@ -200,7 +202,8 @@ export async function getHighlighter(options: HighlighterOptions): Promise<Highl
getBackgroundColor,
getForegroundColor,
getLoadedThemes,
getLoadedLanguages
getLoadedLanguages,
setColorReplacements
}
}

Expand Down
4 changes: 3 additions & 1 deletion packages/shiki/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ export interface Highlighter {
*/
getBackgroundColor(theme?: StringLiteralUnion<Theme>): string

setColorReplacements(map: Record<string, string>): void

// codeToRawHtml?(code: string): string
// getRawCSS?(): string

Expand Down Expand Up @@ -147,7 +149,7 @@ export interface IShikiTheme extends IRawTheme {
/**
* @description light/dark theme
*/
type: 'light' | 'dark'
type: 'light' | 'dark' | 'css'

/**
* @description tokenColors of the theme file
Expand Down
2 changes: 1 addition & 1 deletion packages/shiki/themes/css-variables.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "css-variables",
"type": "light",
"type": "css",
"colors": {
"editor.foreground": "#000001",
"editor.background": "#000002"
Expand Down