Created
June 20, 2024 03:12
-
-
Save rrrix/e40e4249e2688366ede499d7787421c2 to your computer and use it in GitHub Desktop.
Extract all CSS rules that have declarations relating to color, background, and borders
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vim: ft=awk ts=2 sts=2 sw=2 et: | |
/.*\{/ { | |
level++ | |
selectors[level]=$0; | |
counter[level]=0 | |
delete body[level] | |
} | |
/^ .*(color|background|border):.+|: *(#[0-9a-fA-F]+|rgba?\(|hsla?\()/ { | |
for (i=1; i<=level; i++) { | |
counter[i]++ | |
} | |
body[level][counter[level]]=$0; | |
} | |
/.*}/ { | |
if (counter[level] > 0) { | |
for (i=1; i <= level; i++) { | |
if (length(selectors[i]) > 0) { | |
print selectors[i] | |
delete selectors[i] | |
} | |
} | |
} | |
if (length(body[level]) > 0) { | |
for (line in body[level]) { | |
print body[level][line] | |
} | |
} | |
if (counter[level] > 0) { | |
print $0 | |
} | |
delete selectors[level] | |
delete body[level] | |
level-- | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment