From 9439bf61fa3aa6b4edb163cc6f162949073559fa Mon Sep 17 00:00:00 2001 From: Lea Verou Date: Thu, 15 Oct 2020 20:19:32 +0300 Subject: [PATCH] Strip url() before matching colors Rel #32 --- js/32-colors.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/js/32-colors.js b/js/32-colors.js index 545639f..d377c4a 100644 --- a/js/32-colors.js +++ b/js/32-colors.js @@ -47,7 +47,7 @@ function countMatches(haystack, needle) { for (let match of haystack.matchAll(needle)) { ret++; } - + return ret; } @@ -86,6 +86,12 @@ function lin_P3_to_sRGB (linP3) { } walkDeclarations(ast, ({property, value}) => { + // First remove url() references to avoid them mucking the results + for (let f of extractFunctionCalls(value, {names: "url"})) { + let [start, end] = f.pos; + value = value.substring(0, start) + "url()" + " ".repeat(end - start - 5) + value.substring(end); + } + usage.hex[3] += countMatches(value, /#[a-f0-9]{3}\b/gi); usage.hex[4] += countMatches(value, /#[a-f0-9]{4}\b/gi); usage.hex[6] += countMatches(value, /#[a-f0-9]{6}\b/gi);