How to use posthtml-parser - 6 common examples

To help you get started, we’ve selected a few posthtml-parser 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 parcel-bundler / parcel / packages / transformers / posthtml / src / PostHTMLTransformer.js View on Github external
async parse({asset, config}) {
    // if we don't have a config it is posthtml is not configure, don't parse
    if (!config) {
      return;
    }

    return {
      type: 'posthtml',
      version: '0.4.1',
      program: parse(await asset.getCode(), {
        lowerCaseAttributeNames: true,
      }),
    };
  },
github posthtml / posthtml-cache / test / test-plugin.js View on Github external
test('should add nano id for relative path', async t => {
  const staticID = nanoid();
  const input = ``;
  const html = (await processing(input)).html;

  const id = queryString.parse(parser(html)[0].attrs.href.split('?')[1]).v;
  const rel = parser(html)[0].attrs.rel;
  t.truthy(id);
  t.truthy(rel);
  t.is(rel, 'stylesheet');
  t.is(id, staticID);
  t.is(id.length, 21);
});
github posthtml / posthtml-cache / test / test-plugin.js View on Github external
test('should exclude tag links', async t => {
  const input = '';
  const html = (await processing(input, {tags: ['iframe'], exclude: ['link']})).html;
  const [iframe, link] = parser(html);
  const iframeID = queryString.parse(iframe.attrs.src.split('?')[1]).v;
  const linkID = queryString.parse(link.attrs.href.split('?')[1]).v;
  t.truthy(iframeID);
  t.falsy(linkID);
  t.is(iframeID.length, 21);
});
github codesandbox / codesandbox-client / packages / app / src / sandbox / eval / presets / parcel / transpilers / html-worker.js View on Github external
return false;
    }

    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]);
            })
          ) {
github pveyes / htmr / src / server.js View on Github external
function convertServer(html: string, options: Object = {}): ConvertedComponent {
  if (typeof html !== 'string') {
    throw new TypeError('Expected HTML string');
  }

  const opts = {
    transform: options.transform || {},
    preserveAttributes: options.preserveAttributes || [],
  };
  const ast = parse(html.trim());

  const components = ast
    .map((node, index) => transform(node, index.toString(), opts))
    .filter(node => node !== null);

  if (components.length > 1) {
    return components;
  }

  return components[0];
}
github parcel-bundler / parcel / packages / transformers / html / src / HTMLTransformer.js View on Github external
async parse({asset}) {
    return {
      type: 'posthtml',
      version: '0.4.1',
      program: parse(await asset.getCode(), {
        lowerCaseAttributeNames: true,
      }),
    };
  },

posthtml-parser

Parse HTML/XML to PostHTMLTree

MIT
Latest version published 3 months ago

Package Health Score

80 / 100
Full package analysis

Popular posthtml-parser functions