Skip to content

Commit

Permalink
Document nanohtml/dom
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Oct 25, 2019
1 parent bfb3aef commit 234522f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
<body>
<h1>Hello planet</h1>
</body>
`
el.appendChild(html`<p>A paragraph</p>`)

el.outerHTML === '<body><h1>Hello planet</h1><p>A paragraph</p></body>'
```

### 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
Expand Down

0 comments on commit 234522f

Please sign in to comment.