File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -88,22 +88,21 @@ Say our module `example.html` contains:
88
88
89
89
``` js
90
90
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'
93
92
import {toEstree } from ' hast-util-to-estree'
94
- import recast from ' recast '
93
+ import { toJs , jsx } from ' estree-util-to-js '
95
94
96
- const hast = fromParse5 ( parse5 . parse ( String ( await fs .readFile (' example.html' )) ))
95
+ const hast = fromHtml ( await fs .readFile (' example.html' ))
97
96
98
97
const estree = toEstree (hast)
99
98
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 )
102
100
```
103
101
104
102
…now running ` node example.js ` (and prettier) yields:
105
103
106
104
``` jsx
105
+ /* Commentz */
107
106
;<>
108
107
< html lang= " en" >
109
108
< head>
@@ -117,10 +116,13 @@ console.log(recast.prettyPrint(estree).code)
117
116
{' \n ' }
118
117
< a
119
118
download
120
- style= {{width: ' 1' , height: ' 10px' }}
119
+ style= {{
120
+ width: ' 1' ,
121
+ height: ' 10px'
122
+ }}
121
123
/ >
122
124
{' \n ' }
123
- {/* commentz */ }
125
+ {}
124
126
{' \n ' }
125
127
< svg xmlns= " http://www.w3.org/2000/svg" >
126
128
{' \n ' }
You can’t perform that action at this time.
0 commit comments