Skip to content

Instantly share code, notes, and snippets.

@KittyGiraudel
Created August 28, 2015 09:04
Show Gist options
  • Save KittyGiraudel/3e24a29ae48c7a61b12e to your computer and use it in GitHub Desktop.
Save KittyGiraudel/3e24a29ae48c7a61b12e to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.4.14)
// Compass (v1.0.3)
// ----
@function replace-attr($message) {
$has-attr: str-index($message, 'attr(');
$first-paren: str-index($message, ')');
@if not $has-attr {
@return $message;
}
$first-chunk: str-slice($message, 1, $has-attr - 1);
$last-chunk: str-slice($message, $first-paren + 1);
$result: ();
@if str-length($first-chunk) > 0 {
$result: append($result, $first-chunk);
}
$result: append($result, unquote(str-slice($message, $has-attr, $first-paren)));
@if str-length($last-chunk) > 0 {
$result: append($result, replace-attr($last-chunk));
}
@return $result;
}
.foo {
content: replace-attr('attr(foo) hello ba attr(bar) attr(baz) foo attr(qux)');
}
.foo {
content: attr(foo) " hello ba " attr(bar) " " attr(baz) " foo " attr(qux);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment