【发布时间】:2016-06-30 16:01:50
【问题描述】:
如何在 SASS mixin 中测试字符是否为 unicode?p>
我有一个 mixin,我想接受 (1) unicode 字符或 (2) 描述符字符串作为参数。如果参数是 unicode 字符,那么我只想显示它。如果参数是描述符字符串,我会查找 unicode 字符以配合它。
例如:
@include glyph('\f002');
@include glyph('search');
mixin 类似于:
@mixin glyph($glyph) {
@if type-of($glyph) == unicode {
content: '$glyph';
} @ else {
content: get_glyph_for($glyph);
}
}
type-of($glyph) 返回string,因为没有“unicode”类型。
我没有在 SASS 中找到正则表达式功能,也没有找到拆分单个 unicode 字符的方法。
有没有办法可以使用 SASS 运行正则表达式,或者将角色分开?
【问题讨论】:
-
我看不出如何使用有限数量的 Sass 函数来实现。我只能建议您更改您的 mixin 以接受第二个参数来指示第一个参数是否为 unicode。
标签: regex unicode sass string-matching