Skip to content

Commit 08aa946

Browse files
committed
Update example
1 parent 0f6b445 commit 08aa946

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

readme.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,21 @@ Say our module `example.html` contains:
8888

8989
```js
9090
import fs from 'node:fs/promises'
91-
import parse5 from 'parse5'
92-
import {fromParse5} from 'hast-util-from-parse5'
91+
import {fromHtml} from 'hast-util-from-html'
9392
import {toEstree} from 'hast-util-to-estree'
94-
import recast from 'recast'
93+
import {toJs, jsx} from 'estree-util-to-js'
9594

96-
const hast = fromParse5(parse5.parse(String(await fs.readFile('example.html'))))
95+
const hast = fromHtml(await fs.readFile('example.html'))
9796

9897
const estree = toEstree(hast)
9998

100-
estree.comments = null // `recast` doesn’t like comments on the root.
101-
console.log(recast.prettyPrint(estree).code)
99+
console.log(toJs(estree, {handlers: jsx}).value)
102100
```
103101

104102
…now running `node example.js` (and prettier) yields:
105103

106104
```jsx
105+
/* Commentz */
107106
;<>
108107
<html lang="en">
109108
<head>
@@ -117,10 +116,13 @@ console.log(recast.prettyPrint(estree).code)
117116
{'\n'}
118117
<a
119118
download
120-
style={{width: '1', height: '10px'}}
119+
style={{
120+
width: '1',
121+
height: '10px'
122+
}}
121123
/>
122124
{'\n'}
123-
{/*commentz*/}
125+
{}
124126
{'\n'}
125127
<svg xmlns="http://www.w3.org/2000/svg">
126128
{'\n '}

0 commit comments

Comments
 (0)