Last active
September 4, 2019 08:24
-
-
Save PhilippeVay/48fcfb22b0f51786bf227eae25d73509 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Encodes SVG to suitable string for CSS inlining | |
# Usage in terminal: sed -f svg-encode-inline.sed your-minified-with-svgomg-icon.svg > your-encoded-icon.svg | |
# Then paste result in your CSS as `background-image: url("data:image/svg+xml,PASTE");` | |
# | |
# Equivalent to | |
# .replace(/"/g, '\'') | |
# .replace(/%/g, '%25') | |
# .replace(/#/g, '%23') <-- hex colors | |
# .replace(/{/g, '%7B') | |
# .replace(/}/g, '%7D') | |
# .replace(/</g, '%3C') | |
# .replace(/>/g, '%3E') | |
s/\"/\'/g | |
s/%/%25/g # substitute before others! | |
s/#/%23/g | |
s/{/%7B/g | |
s/}/%7D/g | |
s/</%3C/g | |
s/>/%3E/g |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
CSS