How to use the posthtml/lib/api.match.call function in posthtml

To help you get started, we’ve selected a few posthtml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JetBrains / svg-mixer / packages / posthtml-transform / lib / plugin.js View on Github external
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;
        }
      });
github JetBrains / svg-mixer / packages / postsvg / lib / tree.js View on Github external
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;
  }
github JetBrains / svg-mixer / packages / postsvg / lib / tree.js View on Github external
match(expression, callback) {
    return match.call(this, expression, callback);
  }