-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
28 lines (23 loc) · 834 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const postcss = require('postcss');
const Entities = require('html-entities').AllHtmlEntities;
const entities = new Entities();
const isHtmlEntity = /&[aA-z]+;/g;
const getHtmlEntityCssCode = (entity) => {
const char = entities.decode(entity);
if (char === entity) return entity;
return '\\' + char.charCodeAt(0).toString(16);
};
const postcssContentEntity = () => {
return function (css) {
css.walkRules((rule) => {
rule.walkDecls((decl) => {
if (decl.prop === 'content') {
decl.value = decl.value.replace(isHtmlEntity, (entity) => {
return getHtmlEntityCssCode(entity);
});
}
});
});
};
};
module.exports = postcss.plugin('postcss-content-entity', postcssContentEntity);