Skip to content

Commit 234522f

Browse files
committed
Document nanohtml/dom
1 parent bfb3aef commit 234522f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,28 @@ var el = html`
4141
console.log(el.toString())
4242
```
4343

44+
### Node with custom DOM
45+
Modules like [`jsdom`](https://github.com/jsdom/jdsom) implement (parts of)
46+
the DOM in pure JavaScript. If you don't really need the performance of
47+
string concatenation, or use nanohtml components that modify the raw DOM, use
48+
`nanohtml/dom` to give nanohtml a custom Document.
49+
50+
```js
51+
var JSDOM = require('jsdom').JSDOM
52+
var nanohtml = require('./dom')
53+
var jsdom = new JSDOM()
54+
55+
var html = nanohtml(jsdom.window.document)
56+
var el = html`
57+
<body>
58+
<h1>Hello planet</h1>
59+
</body>
60+
`
61+
el.appendChild(html`<p>A paragraph</p>`)
62+
63+
el.outerHTML === '<body><h1>Hello planet</h1><p>A paragraph</p></body>'
64+
```
65+
4466
### Interpolating unescaped HTML
4567
By default all content inside template strings is escaped. This is great for
4668
strings, but not ideal if you want to insert HTML that's been returned from

0 commit comments

Comments
 (0)