Problem
我试图在编译我的 *.scss 文件后生成一些 unicode 字符。
作为示例,我有以下内容(SCSS):
.element:after {
content: "\a0";
}
编译文件时,会输出以下内容(CSS):
.element:after {
content: "\\a0";
}
请注意多余的反斜杠 (\)。
尝试的解决方案#1
我确实在这里尝试了解决方案:Sass:unicode 转义未保留在 .css 文件中 https://stackoverflow.com/questions/30421570,建议引入以下函数:
@function unicode($str) {
@return unquote("\"")+unquote(str-insert($str, "\\", 1))+unquote("\"")
}
像这样使用它(SCSS):
.element:after {
content: unicode("a0");
}
然而,这会产生以下(CSS)
.element:after {
content: "\\" ")+unquote(str-insert($str, " \\\\ ", 1))+unquote(" \\ "";
}
请注意,它甚至没有按预期调用该函数。这是为什么?
项目详情
我在 Maven 中使用这些库:
<dependency>
<groupId>net.jawr</groupId>
<artifactId>jawr-core</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>net.jawr.extensions</groupId>
<artifactId>jawr-spring-extension</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>com.darrinholst</groupId>
<artifactId>sass-java-gems</artifactId>
<version>3.4.20.0</version>
</dependency>
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby-core</artifactId>
<version>9.1.5.0</version>
</dependency>
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby-stdlib</artifactId>
<version>9.1.5.0</version>
</dependency>
临时解决方案
不要在 SCSS 中使用 unicode。相反,请在 HTML 中使用 Font Awesome(将 Font Awesome 保留在 CSS 文件中)。