私はsass 3.4.14でうまく動作する次のコードを持っています
@function replaceAttribute($xml, $insert, $attribute) {
@if type-of($insert) != string {
$insert: inspect($insert);
}
$search_str: $attribute + '="';
//How much to add to get to where the string should be inserted
$offset: str_length($search_str);
$idx: 1;
//The next attribute to replace in string
$next: str_index($xml, $search_str);
@while $next != null {
$idx: $idx + $offset + $next - 1;
//Remove old attribute value and add new
$length_next: str_index(str_slice($xml, $idx), '"');
$xml: str_slice($xml, 0, $idx - 1) + str_slice($xml, $idx + $length_next - 1);
$xml: str_insert($xml, $insert, $idx);
//Find new next attribute to replace
$next: str_index(str_slice($xml, $idx), $search_str);
}
@return $xml;
}
libsass 3.2 を使用するとうまく動作しませんが、sass-compatibility.github.io/ によると、ここで使用されるすべての文字列関数がサポートされるはずです。次のエラー メッセージが表示されます。
の引数は文字列$insert
でstr-insert($string, $insert, $index)
なければなりません
これを修正するにはどうすればよいですか? sass コンパイル時間の理由から、libsass に切り替えようとしています。