@@ -11,6 +11,7 @@ $ npm install nanohtml
1111```
1212
1313## Usage
14+ ### Browser
1415``` js
1516var html = require (' nanohtml' )
1617
@@ -23,7 +24,7 @@ var el = html`
2324document .body .appendChild (el)
2425```
2526
26- ## Node
27+ ### Node
2728Node doesn't have a DOM available. So in order to render HTML we use string
2829concatenation instead. This has the fun benefit of being quite efficient, which
2930in turn means it's great for server rendering!
@@ -40,7 +41,7 @@ var el = html`
4041console .log (el .toString ())
4142```
4243
43- ## Interpolating unescaped HTML
44+ ### Interpolating unescaped HTML
4445By default all content inside template strings is escaped. This is great for
4546strings, but not ideal if you want to insert HTML that's been returned from
4647another function (for example: a markdown renderer). Use ` nanohtml/raw ` for
@@ -60,6 +61,26 @@ var el = html`
6061document .body .appendChild (el)
6162```
6263
64+ ### Attaching event listeners
65+ ``` js
66+ var html = require (' nanohtml' )
67+
68+ var string = ' <h1>This a regular string.'
69+ var el = html `
70+ <body >
71+ <button onclick =${onclick} >
72+ Click Me
73+ </button >
74+ </body >
75+ `
76+
77+ document .body .appendChild (el)
78+
79+ function onclick (e ) {
80+ console .log (` ${ e .target } was clicked` )
81+ }
82+ ```
83+
6384## Static optimizations
6485Parsing HTML has significant overhead. Being able to parse HTML statically,
6586ahead of time can speed up rendering to be about twice as fast.
@@ -128,7 +149,7 @@ With options:
128149}
129150```
130151
131- ### Options
152+ #### Options
132153
133154 - ` useImport ` - Set to true to use ` import ` statements for injected modules.
134155 By default, ` require ` is used. Enable this if you're using Rollup.
@@ -157,7 +178,7 @@ wouldn't have been possible otherwise!
157178[ 5 ] : https://travis-ci.org/choojs/nanohtml
158179[ 6 ] : https://img.shields.io/codecov/c/github/choojs/nanohtml/master.svg?style=flat-square
159180[ 7 ] : https://codecov.io/github/choojs/nanohtml
160- [ 8 ] : http://img.shields.io/npm/dm /nanohtml.svg?style=flat-square
181+ [ 8 ] : http://img.shields.io/npm/dt /nanohtml.svg?style=flat-square
161182[ 9 ] : https://npmjs.org/package/nanohtml
162183[ 10 ] : https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square
163184[ 11 ] : https://github.com/feross/standard
0 commit comments