Skip to content

Commit

Permalink
fix(monaco): handle colors in array
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Feb 6, 2025
1 parent 4d961f6 commit e30181b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/monaco/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,17 @@ class TokenizerState implements monacoNs.languages.IState {
}

function normalizeColor(color: undefined): undefined
function normalizeColor(color: string): string
function normalizeColor(color: string | undefined): string | undefined
function normalizeColor(color: string | undefined): string | undefined {
function normalizeColor(color: string | string[]): string
function normalizeColor(color: string | string[] | undefined): string | undefined
function normalizeColor(color: string | string[] | undefined): string | undefined {
// Some themes have an array of colors (not yet sure why), here we pick the first one
// https://github.com/shikijs/shiki/issues/894
// https://github.com/shikijs/textmate-grammars-themes/pull/117
if (Array.isArray(color))
color = color[0]

if (!color)
return color
return undefined

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

Expand Down

0 comments on commit e30181b

Please sign in to comment.