libsass检查,str_索引
我有以下代码在sass 3.4.14下运行良好libsass检查,str_索引,sass,gulp-sass,libsass,Sass,Gulp Sass,Libsass,我有以下代码在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
@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/这里使用的所有字符串函数都应该得到支持。
我收到以下错误消息:
str insert($string,$insert,$index)
的参数$insert
必须是字符串
我该如何解决这个问题?由于sass编译时间的原因,我正在尝试切换到libsass 这里没有足够的代码来重现问题。我们需要能够看到您传递给此函数的内容会导致错误。很抱歉没有回答,修复了此错误,并兴奋地继续进行其他操作,结果发现inspect()不会将类型为color(如color:white;e.g.)的内容转换为字符串。通过将其他人的硬编码颜色更改为“#fff”来修复此问题。这很奇怪,这里没有足够的代码来重现问题。我们需要能够看到您传递给此函数的内容会导致错误。很抱歉没有回答,修复了此错误,并兴奋地继续进行其他操作,结果发现inspect()不会将类型为color(如color:white;e.g.)的内容转换为字符串。通过将其他人的硬编码颜色更改为“#fff”来修复此问题。这很奇怪,这里没有足够的代码来重现问题。我们需要能够看到您传递给此函数的内容会导致错误。很抱歉没有回答,修复了此错误,并兴奋地继续进行其他操作,结果发现inspect()不会将类型为color(如color:white;e.g.)的内容转换为字符串。通过将其他人的硬编码颜色更改为“#fff”来修复此问题。真奇怪。