Skip to content

Commit fcd8d99

Browse files
yoshuawuytsgoto-bus-stop
authored andcommitted
clean up readme slightly (#114)
1 parent 9edeef1 commit fcd8d99

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

README.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ $ npm install nanohtml
1111
```
1212

1313
## Usage
14+
### Browser
1415
```js
1516
var html = require('nanohtml')
1617

@@ -23,7 +24,7 @@ var el = html`
2324
document.body.appendChild(el)
2425
```
2526

26-
## Node
27+
### Node
2728
Node doesn't have a DOM available. So in order to render HTML we use string
2829
concatenation instead. This has the fun benefit of being quite efficient, which
2930
in turn means it's great for server rendering!
@@ -40,7 +41,7 @@ var el = html`
4041
console.log(el.toString())
4142
```
4243

43-
## Interpolating unescaped HTML
44+
### Interpolating unescaped HTML
4445
By default all content inside template strings is escaped. This is great for
4546
strings, but not ideal if you want to insert HTML that's been returned from
4647
another function (for example: a markdown renderer). Use `nanohtml/raw` for
@@ -60,6 +61,26 @@ var el = html`
6061
document.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
6485
Parsing HTML has significant overhead. Being able to parse HTML statically,
6586
ahead 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

Comments
 (0)