17
17
* [ Install] ( #install )
18
18
* [ Use] ( #use )
19
19
* [ API] ( #api )
20
- * [ ` toDom(node[, options]) ` ] ( #todomnode-options )
20
+ * [ ` toDom(tree[, options]) ` ] ( #todomtree-options )
21
+ * [ ` AfterTransform ` ] ( #aftertransform )
22
+ * [ ` Options ` ] ( #options )
23
+ * [ Syntax tree] ( #syntax-tree )
21
24
* [ Types] ( #types )
22
25
* [ Compatibility] ( #compatibility )
23
26
* [ Security] ( #security )
@@ -47,7 +50,7 @@ utility to serialize as HTML with DOM APIs.
47
50
## Install
48
51
49
52
This package is [ ESM only] [ esm ] .
50
- In Node.js (version 12.20+, 14.14+, or 16.0+), install with [ npm] [ ] :
53
+ In Node.js (version 14.14+ or 16.0+), install with [ npm] [ ] :
51
54
52
55
``` sh
53
56
npm install hast-util-to-dom
@@ -88,42 +91,62 @@ Say our page `example.html` looks as follows:
88
91
</script >
89
92
```
90
93
91
- Now running ` open example.html ` shows the equivalent HTML on the page.
94
+ Now running ` open example.html ` shows the ` main ` , ` h1 ` , and ` p ` elements on the
95
+ page.
92
96
93
97
## API
94
98
95
- This package exports the identifier ` toDom ` .
99
+ This package exports the identifier [ ` toDom ` ] [ to-dom ] .
96
100
There is no default export.
97
101
98
- ### ` toDom(node [, options]) `
102
+ ### ` toDom(tree [, options]) `
99
103
100
104
Turn a hast tree into a DOM tree.
101
105
102
- ##### ` options `
106
+ ###### Parameters
103
107
104
- Configuration (optional).
108
+ * ` tree ` ([ ` HastNode ` ] [ hast-node ] )
109
+ — tree to transform
110
+ * ` options ` ([ ` Options ` ] [ options ] , optional)
111
+ — configuration
105
112
106
- ###### ` options.fragment `
113
+ ###### Returns
107
114
108
- Return a DOM fragment (` boolean ` , default: ` false ` ).
109
- Creates whole documents otherwise.
115
+ DOM node ([ ` DomNode ` ] [ dom-node ] ).
110
116
111
- ###### ` options.document `
117
+ ### ` AfterTransform `
112
118
113
- Document interface to use ( ` Document ` , default: ` globalThis.document ` ).
119
+ Callback called when each node is transformed (TypeScript type ).
114
120
115
- ###### ` options.namespace `
121
+ ###### Parameters
116
122
117
- ` namespace ` to use to create elements (` string? ` , optional).
123
+ * ` hastNode ` ([ ` HastNode ` ] [ hast-node ] )
124
+ — hast node that was handled
125
+ * ` domNode ` ([ ` DomNode ` ] [ dom-node ] )
126
+ — corresponding DOM node
118
127
119
- ###### ` options.afterTransform `
128
+ ###### Returns
120
129
121
- Called when a hast node was transformed into a DOM node
122
- (` (HastNode, Node) => void? ` , optional).
130
+ Nothing.
123
131
124
- ##### Returns
132
+ ### ` Options `
125
133
126
- [ ` Node ` ] [ dom ] .
134
+ Configuration (TypeScript type).
135
+
136
+ ###### Fields
137
+
138
+ * ` afterTransform ` ([ ` AfterTransform ` ] [ aftertransform ] , optional)
139
+ — callback called when each node is transformed
140
+ * ` document ` (` Document ` , default: ` globalThis.document ` )
141
+ — document interface to use.
142
+ * ` fragment ` (` boolean ` , default: ` false ` )
143
+ — whether to return a DOM fragment (` true ` ) or a whole document (` false ` )
144
+ * ` namespace ` (` string ` , default: depends)
145
+ — namespace to use to create elements
146
+
147
+ ## Syntax tree
148
+
149
+ The syntax tree is [ hast] [ ] .
127
150
128
151
## Types
129
152
@@ -134,7 +157,7 @@ It exports the additional types `AfterTransform` and `Options`.
134
157
135
158
Projects maintained by the unified collective are compatible with all maintained
136
159
versions of Node.js.
137
- As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
160
+ As of now, that is Node.js 14.14+ and 16.0+.
138
161
Our projects sometimes work with older versions, but this is not guaranteed.
139
162
140
163
## Security
@@ -159,7 +182,7 @@ ways to get started.
159
182
See [ ` support.md ` ] [ support ] for ways to get help.
160
183
161
184
This project has a [ code of conduct] [ coc ] .
162
- By interacting with this repository, organisation , or community you agree to
185
+ By interacting with this repository, organization , or community you agree to
163
186
abide by its terms.
164
187
165
188
## License
@@ -214,10 +237,6 @@ abide by its terms.
214
237
215
238
[ coc ] : https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
216
239
217
- [ hast ] : https://github.com/syntax-tree/hast
218
-
219
- [ dom ] : https://developer.mozilla.org/docs/Web/API/Document_Object_Model
220
-
221
240
[ xss ] : https://en.wikipedia.org/wiki/Cross-site_scripting
222
241
223
242
[ hast-util-sanitize ] : https://github.com/syntax-tree/hast-util-sanitize
@@ -227,3 +246,17 @@ abide by its terms.
227
246
[ jsdom ] : https://github.com/jsdom/jsdom
228
247
229
248
[ rehype-dom-stringify ] : https://github.com/rehypejs/rehype-dom/tree/main/packages/rehype-dom-stringify
249
+
250
+ [ hast ] : https://github.com/syntax-tree/hast
251
+
252
+ [ hast-node ] : https://github.com/syntax-tree/hast#nodes
253
+
254
+ [ dom ] : https://developer.mozilla.org/docs/Web/API/Document_Object_Model
255
+
256
+ [ dom-node ] : https://developer.mozilla.org/docs/Web/API/Node
257
+
258
+ [ to-dom ] : #todomtree-options
259
+
260
+ [ aftertransform ] : #aftertransform
261
+
262
+ [ options ] : #options
0 commit comments