Skip to content

Commit

Permalink
Strip url() before matching colors
Browse files Browse the repository at this point in the history
Rel #32
  • Loading branch information
LeaVerou committed Oct 15, 2020
1 parent 8015180 commit 9439bf6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion js/32-colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function countMatches(haystack, needle) {
for (let match of haystack.matchAll(needle)) {
ret++;
}

return ret;
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9439bf6

Please sign in to comment.