-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
38 lines (35 loc) · 1.01 KB
/
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
29
30
31
32
33
34
35
36
37
38
var postcss = require('postcss');
var defaultOpts = {
replace: [],
};
module.exports = postcss.plugin('postcss-amp-process', function(opts) {
opts = { ...defaultOpts, ...opts };
return root => {
if (opts.replace.length) {
root.walkDecls(decl => {
const inputFile =
root.source && root.source.input && root.source.input.file;
let value = decl.value;
opts.replace.map(replaceString => {
value = value.replace(replaceString[0], replaceString[1]);
});
decl.value = value;
});
}
root.walkRules((rule, ruleIndex) => {
if (ruleIndex === 0 && rule.selector.charAt(0) === '#') {
rule.selector = ' ' + rule.selector;
}
rule.walkDecls((decl, index) => {
decl.important = false;
if (index == rule.nodes.length - 1) {
let value = decl.value;
var lastChar = value[value.length - 1];
if (lastChar === '%') {
decl.value += ' ';
}
}
});
});
};
});