How to use the parse5/lib/tree-adapters/default.appendChild function in parse5

To help you get started, we’ve selected a few parse5 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 bazelbuild / rules_nodejs / packages / inject-html / index.js View on Github external
const testEs2015 = (noExt + '.es2015.js').toLowerCase();
        const matches = files.filter(t => {
          const lc = t.toLowerCase();
          return lc === testMjs || lc === testEs2015;
        });
        return matches.length > 0;
      }

      // Note: empty string value is equivalent to a bare attribute, according to
      // https://github.com/inikulin/parse5/issues/1
      const nomodule = hasMatchingModule(s, jsFiles) ? [{name: 'nomodule', value: ''}] : [];

      const noModuleScript = treeAdapter.createElement('script', undefined, nomodule.concat([
        {name: 'src', value: `/${relative(s)}?v=${timestamp()}`},
      ]));
      treeAdapter.appendChild(body, noModuleScript);
    }
  }

  for (const s of params.filter(s => /\.css$/.test(s))) {
    const stylesheet = treeAdapter.createElement('link', undefined, [
      {name: 'rel', value: 'stylesheet'},
      {name: 'href', value: `/${relative(s)}?v=${timestamp()}`},
    ]);
    treeAdapter.appendChild(head, stylesheet);
  }

  const content = parse5.serialize(document, {treeAdapter});
  write(outputFile, content, {encoding: 'utf-8'});
  return 0;
}
github bazelbuild / rules_nodejs / packages / inject-html / index.js View on Github external
// https://github.com/inikulin/parse5/issues/1
      const nomodule = hasMatchingModule(s, jsFiles) ? [{name: 'nomodule', value: ''}] : [];

      const noModuleScript = treeAdapter.createElement('script', undefined, nomodule.concat([
        {name: 'src', value: `/${relative(s)}?v=${timestamp()}`},
      ]));
      treeAdapter.appendChild(body, noModuleScript);
    }
  }

  for (const s of params.filter(s => /\.css$/.test(s))) {
    const stylesheet = treeAdapter.createElement('link', undefined, [
      {name: 'rel', value: 'stylesheet'},
      {name: 'href', value: `/${relative(s)}?v=${timestamp()}`},
    ]);
    treeAdapter.appendChild(head, stylesheet);
  }

  const content = parse5.serialize(document, {treeAdapter});
  write(outputFile, content, {encoding: 'utf-8'});
  return 0;
}
github bazelbuild / rules_nodejs / packages / inject-html / index.js View on Github external
return execPath;
  }

  const jsFiles = params.filter(s => /\.m?js$/i.test(s));
  for (const s of jsFiles) {
    // Differential loading: for filenames like
    //  foo.mjs
    //  bar.es2015.js
    // we use a