From d74a53ae9e3482406fcb8cda42a3466b983b5639 Mon Sep 17 00:00:00 2001 From: Brad Cornes Date: Fri, 8 Oct 2021 17:06:10 +0100 Subject: [PATCH] update color extraction to allow parentheses (#423) --- packages/tailwindcss-language-service/src/util/color.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/tailwindcss-language-service/src/util/color.ts b/packages/tailwindcss-language-service/src/util/color.ts index 3e4cdfa..4c4ca2b 100644 --- a/packages/tailwindcss-language-service/src/util/color.ts +++ b/packages/tailwindcss-language-service/src/util/color.ts @@ -42,9 +42,9 @@ function getKeywordColor(value: unknown): KeywordColor | null { // https://github.com/khalilgharbaoui/coloregex const colorRegex = new RegExp( - `(?:^|\\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( + `(?:^|\\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( namedColors - ).join('|')})(?:$|\\s|,)`, + ).join('|')})(?:$|\\s|\\)|,)`, 'gi' ) @@ -57,7 +57,7 @@ function getColorsInString(str: string): (culori.Color | KeywordColor)[] { ?.map((color) => color .trim() - .replace(/^,|,$/g, '') + .replace(/^[,(]|[,)]$/g, '') .replace(/var\([^)]+\)/, '1') ) .map((color) => getKeywordColor(color) ?? culori.parse(color))