Skip to content

Commit e30181b

Browse files
committedFeb 6, 2025
fix(monaco): handle colors in array
fix #894 close shikijs/textmate-grammars-themes#117
1 parent 4d961f6 commit e30181b

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed
 

‎packages/monaco/src/index.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,17 @@ class TokenizerState implements monacoNs.languages.IState {
175175
}
176176

177177
function normalizeColor(color: undefined): undefined
178-
function normalizeColor(color: string): string
179-
function normalizeColor(color: string | undefined): string | undefined
180-
function normalizeColor(color: string | undefined): string | undefined {
178+
function normalizeColor(color: string | string[]): string
179+
function normalizeColor(color: string | string[] | undefined): string | undefined
180+
function normalizeColor(color: string | string[] | undefined): string | undefined {
181+
// Some themes have an array of colors (not yet sure why), here we pick the first one
182+
// https://github.com/shikijs/shiki/issues/894
183+
// https://github.com/shikijs/textmate-grammars-themes/pull/117
184+
if (Array.isArray(color))
185+
color = color[0]
186+
181187
if (!color)
182-
return color
188+
return undefined
183189

184190
color = (color.charCodeAt(0) === 35 ? color.slice(1) : color).toLowerCase()
185191

0 commit comments

Comments
 (0)
Please sign in to comment.