domspace

Adjust the text nodes in an HTML DOM so that the document is pretty-printed when serialized.

Usage no npm install needed!

<script type="module">
  import domspace from 'https://cdn.skypack.dev/domspace';
</script>

README

domspace

Adjust the text nodes in an HTML DOM so that the document is pretty-printed when serialized.

Note that the supplied node and its children will be altered. If you'd rather create a copy that's ready for pretty printing, you can deep-clone it first using the DOM API:

const prettyNode = domspace(node.cloneNode(true));

Installation

npm install domspace

Example

const domspace = require('domspace');
const myDiv = document.createElement('div');
myDiv.innerHTML = '<span><i>foo</i></span>';
domspace(myDiv);
console.log(myDiv.outerHTML);

Output:

<div>
  <span>
    <i>foo</i>
  </span>
</div>