我想在Pug.js过滤器中绑定一些值。但是该过滤器工作正常,值不绑定。
带过滤器的输出结果
<style>.#{cs_1}{font-family:monospace !important;color:#a1292c !important}.#{cs_1}:hover{background-color:transparent !important;text-decoration:underline !important}.#{cs_2}{position:absolute;font-size:11px;text-transform:none;left:80px;top:12px;border-left:1px solid #ccc;padding-left:6px}.#{cs_3}{white-space:nowrap}</style>
没有过滤器的输出结果
<style>
.eTWkI {
font-family: monospace !important;
color: #a1292c !important;
}
.eTWkI:hover {
background-color: transparent !important;
text-decoration: underline !important;
}
.Rzorr {
position: absolute;
font-size: 11px;
text-transform: none;
left: 80px;
top: 12px;
border-left: 1px solid #ccc;
padding-left: 6px;
}
.vMvwp {
white-space: nowrap;
}
</style>
Pug.js 代码
注意:
:minifycss
使用uglifycss模块制作的过滤器
- var length = 5
- var chars = "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz_-"
- var cs_1 = utils.randomString(length, chars)
- var cs_2 = utils.randomString(length, chars)
- var cs_3 = utils.randomString(length, chars)
style
:minifycss
.#{cs_1} {
font-family: monospace !important;
color: #a1292c !important;
}
.#{cs_1}:hover {
background-color: transparent !important;
text-decoration: underline !important;
}
.#{cs_2} {
position: absolute;
font-size: 11px;
text-transform: none;
left: 80px;
top: 12px;
border-left: 1px solid #ccc;
padding-left: 6px;
}
.#{cs_3} {
white-space: nowrap;
}
所以过滤器看起来像:
require('pug').filters = {
minifycss: (text, options) => {
if (!text) return;
return uglifycss.processString(text, options);
}
};