@@ -2,7 +2,7 @@ import { codeToTokensBase } from './code-to-tokens-base'
2
2
import { codeToTokensWithThemes } from './code-to-tokens-themes'
3
3
import { ShikiError } from './error'
4
4
import type { CodeToTokensOptions , ShikiInternal , ThemedToken , ThemedTokenWithVariants , TokensResult } from './types'
5
- import { getTokenStyleObject , stringifyTokenStyle } from './utils'
5
+ import { applyColorReplacements , getTokenStyleObject , stringifyTokenStyle } from './utils'
6
6
7
7
/**
8
8
* High-level code-to-tokens API.
@@ -24,6 +24,7 @@ export function codeToTokens(
24
24
const {
25
25
defaultColor = 'light' ,
26
26
cssVariablePrefix = '--shiki-' ,
27
+ colorReplacements,
27
28
} = options
28
29
29
30
const themes = Object . entries ( options . themes )
@@ -48,21 +49,29 @@ export function codeToTokens(
48
49
tokens = themeTokens
49
50
. map ( line => line . map ( token => mergeToken ( token , themesOrder , cssVariablePrefix , defaultColor ) ) )
50
51
51
- fg = themes . map ( ( t , idx ) => ( idx === 0 && defaultColor ? '' : `${ cssVariablePrefix + t . color } :` ) + ( themeRegs [ idx ] . fg || 'inherit' ) ) . join ( ';' )
52
- bg = themes . map ( ( t , idx ) => ( idx === 0 && defaultColor ? '' : `${ cssVariablePrefix + t . color } -bg:` ) + ( themeRegs [ idx ] . bg || 'inherit' ) ) . join ( ';' )
52
+ fg = themes . map ( ( t , idx ) => ( idx === 0 && defaultColor
53
+ ? ''
54
+ : `${ cssVariablePrefix + t . color } :` ) + ( applyColorReplacements ( themeRegs [ idx ] . fg , colorReplacements ) || 'inherit' ) ) . join ( ';' )
55
+ bg = themes . map ( ( t , idx ) => ( idx === 0 && defaultColor
56
+ ? ''
57
+ : `${ cssVariablePrefix + t . color } -bg:` ) + ( applyColorReplacements ( themeRegs [ idx ] . bg , colorReplacements ) || 'inherit' ) ) . join ( ';' )
53
58
themeName = `shiki-themes ${ themeRegs . map ( t => t . name ) . join ( ' ' ) } `
54
59
rootStyle = defaultColor ? undefined : [ fg , bg ] . join ( ';' )
55
60
}
56
61
else if ( 'theme' in options ) {
62
+ const {
63
+ colorReplacements,
64
+ } = options
65
+
57
66
tokens = codeToTokensBase (
58
67
internal ,
59
68
code ,
60
69
options ,
61
70
)
62
71
63
72
const _theme = internal . getTheme ( options . theme )
64
- bg = _theme . bg
65
- fg = _theme . fg
73
+ bg = applyColorReplacements ( _theme . bg , colorReplacements )
74
+ fg = applyColorReplacements ( _theme . fg , colorReplacements )
66
75
themeName = _theme . name
67
76
}
68
77
else {
0 commit comments