How to use the posthtml/lib/api.match 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 codesandbox / codesandbox-client / packages / app / src / sandbox / eval / presets / parcel / transpilers / html-worker.js View on Github external
function addSrcSetDependencies(srcset: string) {
      const newSources = [];

      srcset.split(',').forEach(source => {
        const pair = source.trim().split(' ');
        if (pair.length === 0) return;
        pair[0] = addDependency(pair[0]);
        newSources.push(pair.join(' '));
      });
      return newSources.join(',');
    }

    const res = parse(code, { lowerCaseAttributeNames: true });
    res.walk = api.walk;
    res.match = api.match;

    res.walk(node => {
      if (node == null) {
        return node;
      }

      if (node.attrs) {
        if (node.tag === 'meta') {
          if (
            !Object.keys(node.attrs).some(attr => {
              const values = META[attr];
              return values && values.includes(node.attrs[attr]);
            })
          ) {
            return node;
          }
github JetBrains / svg-mixer / packages / postsvg / lib / renderer.js View on Github external
opts.singleTags = opts.singleTags.filter((tag) => {
    let hasContent = false;

    api.match.call(tree, { tag }, (node) => {
      if (typeof node.content !== 'undefined' && !hasContent) {
        hasContent = true;
      }
      return node;
    });

    return !hasContent;
  });
github parcel-bundler / parcel / packages / core / parcel-bundler / src / assets / HTMLAsset.js View on Github external
async parse(code) {
    let res = await posthtmlTransform.parse(code, this);
    res.walk = api.walk;
    res.match = api.match;
    return res;
  }
github parcel-bundler / parcel / src / transforms / html / src / HTMLAsset.js View on Github external
async parse(code) {
    let res = await posthtmlTransform.parse(code, this);
    res.walk = api.walk;
    res.match = api.match;
    return res;
  }