Skip to content

Commit d74a53a

Browse files
committed
update color extraction to allow parentheses (#423)
1 parent 0f4d93b commit d74a53a

File tree

1 file changed

+3
-3
lines changed
  • packages/tailwindcss-language-service/src/util

1 file changed

+3
-3
lines changed

packages/tailwindcss-language-service/src/util/color.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ function getKeywordColor(value: unknown): KeywordColor | null {
4242

4343
// https://github.com/khalilgharbaoui/coloregex
4444
const colorRegex = new RegExp(
45-
`(?:^|\\s|,)(#(?:[0-9a-f]{2}){2,4}|(#[0-9a-f]{3})|(rgb|hsl)a?\\((-?[\\d.]+%?(\\s*[,/]\\s*|\\s+)+){2,3}\\s*([\\d.]+%?|var\\([^)]+\\))?\\)|transparent|currentColor|${Object.keys(
45+
`(?:^|\\s|\\(|,)(#(?:[0-9a-f]{2}){2,4}|(#[0-9a-f]{3})|(rgb|hsl)a?\\((-?[\\d.]+%?(\\s*[,/]\\s*|\\s+)+){2,3}\\s*([\\d.]+%?|var\\([^)]+\\))?\\)|transparent|currentColor|${Object.keys(
4646
namedColors
47-
).join('|')})(?:$|\\s|,)`,
47+
).join('|')})(?:$|\\s|\\)|,)`,
4848
'gi'
4949
)
5050

@@ -57,7 +57,7 @@ function getColorsInString(str: string): (culori.Color | KeywordColor)[] {
5757
?.map((color) =>
5858
color
5959
.trim()
60-
.replace(/^,|,$/g, '')
60+
.replace(/^[,(]|[,)]$/g, '')
6161
.replace(/var\([^)]+\)/, '1')
6262
)
6363
.map((color) => getKeywordColor(color) ?? culori.parse(color))

0 commit comments

Comments
 (0)