dom-combiner

Node.js DOM combiner

Usage no npm install needed!

<script type="module">
  import domCombiner from 'https://cdn.skypack.dev/dom-combiner';
</script>

README

Build Status

dom-combiner

Node.js utility that builds a single page from two or more sources by merging documents and documentFragments created with parse5 into a single object. Subsequent sources overwrites or extends previous sources.

Default behaviours:

  • Overwrite <!doctype> declaration
  • Overwrite <title>'s content
  • Overwrite <meta> tags' values
  • Append new attributes to unique elements
  • Overwrite existing attributes of unique
  • Append new elements in <head> and <body> sections to their equivalents
  • If the elements are not wrapped in <html>/<head>/<body> append them to the <body> element of the previous source
  • Treat contents of <script>, <style>, <textarea> elements as a plain text

Installation

npm install dom-combiner

Usage

combine(html_1, html_2, [..., html_n], [callback]);

Example

var combine = require('dom-combiner'),
    template = '<!doctype html><html><head><title>Foo</title></head><body></body></html>',
    html = '<body class="foo"><div id="baz">Baz</div></body>';

var output = combine(template, html);
// <!doctype html><html><head><title>Foo</title></head><body class="foo"><div id="baz">Baz</div></body></html>

Testing

npm test

License

MIT, for license details see: LICENSE.md.