update color extraction to allow parentheses (#423)
parent
0f4d93b96e
commit
d74a53ae9e
|
@ -42,9 +42,9 @@ function getKeywordColor(value: unknown): KeywordColor | null {
|
||||||
|
|
||||||
// https://github.com/khalilgharbaoui/coloregex
|
// https://github.com/khalilgharbaoui/coloregex
|
||||||
const colorRegex = new RegExp(
|
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
|
namedColors
|
||||||
).join('|')})(?:$|\\s|,)`,
|
).join('|')})(?:$|\\s|\\)|,)`,
|
||||||
'gi'
|
'gi'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ function getColorsInString(str: string): (culori.Color | KeywordColor)[] {
|
||||||
?.map((color) =>
|
?.map((color) =>
|
||||||
color
|
color
|
||||||
.trim()
|
.trim()
|
||||||
.replace(/^,|,$/g, '')
|
.replace(/^[,(]|[,)]$/g, '')
|
||||||
.replace(/var\([^)]+\)/, '1')
|
.replace(/var\([^)]+\)/, '1')
|
||||||
)
|
)
|
||||||
.map((color) => getKeywordColor(color) ?? culori.parse(color))
|
.map((color) => getKeywordColor(color) ?? culori.parse(color))
|
||||||
|
|
Loading…
Reference in New Issue