Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
normalizedRules.forEach(rule => {
// posthtml matcher, see https://github.com/posthtml/posthtml/blob/master/docs/api.md#treematchexpression-cb--function
const matcher = !rule.selector ? { tag: /.*/ } : matchHelper(rule.selector);
const nodesToProcess = [];
match.call(nodes, matcher, node => {
nodesToProcess.push(node);
return node;
});
nodesToProcess.forEach(node => {
const { attr, value, tag } = rule;
if (tag) {
node.tag = tag;
}
if (attr && value) {
node.attrs = node.attrs || {};
node.attrs[rule.attr] = rule.value;
}
});
select(selector) {
const nodes = [];
const selectAllNodes = typeof selector === 'undefined' || selector === '*';
const matcher = selectAllNodes ? { tag: /\.*/ } : matchHelper(selector);
match.call(this, matcher, node => {
nodes.push(node);
return node;
});
return nodes;
}
match(expression, callback) {
return match.call(this, expression, callback);
}