From 234522f74bec2e9a5d677464073a549e5f343698 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Fri, 25 Oct 2019 12:09:23 +0200 Subject: [PATCH] Document nanohtml/dom --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 0132d1c..0fb7e40 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,28 @@ var el = html` console.log(el.toString()) ``` +### Node with custom DOM +Modules like [`jsdom`](https://github.com/jsdom/jdsom) implement (parts of) +the DOM in pure JavaScript. If you don't really need the performance of +string concatenation, or use nanohtml components that modify the raw DOM, use +`nanohtml/dom` to give nanohtml a custom Document. + +```js +var JSDOM = require('jsdom').JSDOM +var nanohtml = require('./dom') +var jsdom = new JSDOM() + +var html = nanohtml(jsdom.window.document) +var el = html` + +

Hello planet

+ +` +el.appendChild(html`

A paragraph

`) + +el.outerHTML === '

Hello planet

A paragraph

' +``` + ### Interpolating unescaped HTML By default all content inside template strings is escaped. This is great for strings, but not ideal if you want to insert HTML that's been returned from