Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Inline SVG function [SASS]
// Replace letters
@function str-replace($string, $search, $replace: '') {
$index: str-index($string, $search);
@if $index {
@return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
}
@return $string;
}
// Encode symbols
@function url-encode($string) {
$map: (
"%": "%25",
"<": "%3C",
">": "%3E",
" ": "%20",
"!": "%21",
"*": "%2A",
"'": "%27",
'"': "%22",
"(": "%28",
")": "%29",
";": "%3B",
":": "%3A",
"@": "%40",
"&": "%26",
"=": "%3D",
"+": "%2B",
"$": "%24",
",": "%2C",
"/": "%2F",
"?": "%3F",
"#": "%23",
"[": "%5B",
"]": "%5D"
);
$new: $string;
@each $search, $replace in $map {
$new: str-replace($new, $search, $replace);
}
@return $new;
}
// Format the SVG as a URL
@function inline-svg($string) {
@return url('data:image/svg+xml,#{url-encode($string)}');
}
@bitmanic

This comment has been minimized.

Copy link

commented Mar 20, 2017

Nice work. Functions perfectly. 👍

@gemmadlou

This comment has been minimized.

Copy link

commented Oct 16, 2017

Forked! Thank you

@po5i

This comment has been minimized.

Copy link

commented Sep 5, 2018

This is awesome!

@nicarslayer

This comment has been minimized.

Copy link

commented Nov 29, 2018

write please how to use

@d3zza

This comment has been minimized.

Copy link

commented Dec 6, 2018

Nice one! Thank you.

@Michelangelo9

This comment has been minimized.

Copy link

commented Dec 11, 2018

Thanks! This saved me some time to figure out. Cheers 🍺

@diskomanuelle

This comment has been minimized.

Copy link

commented Jan 11, 2019

Hi Thanks for this function !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.