1717* [ Install] ( #install )
1818* [ Use] ( #use )
1919* [ 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 )
2124* [ Types] ( #types )
2225* [ Compatibility] ( #compatibility )
2326* [ Security] ( #security )
@@ -47,7 +50,7 @@ utility to serialize as HTML with DOM APIs.
4750## Install
4851
4952This 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] [ ] :
5154
5255``` sh
5356npm install hast-util-to-dom
@@ -88,42 +91,62 @@ Say our page `example.html` looks as follows:
8891 </script >
8992```
9093
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.
9296
9397## API
9498
95- This package exports the identifier ` toDom ` .
99+ This package exports the identifier [ ` toDom ` ] [ to-dom ] .
96100There is no default export.
97101
98- ### ` toDom(node [, options]) `
102+ ### ` toDom(tree [, options]) `
99103
100104Turn a hast tree into a DOM tree.
101105
102- ##### ` options `
106+ ###### Parameters
103107
104- Configuration (optional).
108+ * ` tree ` ([ ` HastNode ` ] [ hast-node ] )
109+ — tree to transform
110+ * ` options ` ([ ` Options ` ] [ options ] , optional)
111+ — configuration
105112
106- ###### ` options.fragment `
113+ ###### Returns
107114
108- Return a DOM fragment (` boolean ` , default: ` false ` ).
109- Creates whole documents otherwise.
115+ DOM node ([ ` DomNode ` ] [ dom-node ] ).
110116
111- ###### ` options.document `
117+ ### ` AfterTransform `
112118
113- Document interface to use ( ` Document ` , default: ` globalThis.document ` ).
119+ Callback called when each node is transformed (TypeScript type ).
114120
115- ###### ` options.namespace `
121+ ###### Parameters
116122
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
118127
119- ###### ` options.afterTransform `
128+ ###### Returns
120129
121- Called when a hast node was transformed into a DOM node
122- (` (HastNode, Node) => void? ` , optional).
130+ Nothing.
123131
124- ##### Returns
132+ ### ` Options `
125133
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] [ ] .
127150
128151## Types
129152
@@ -134,7 +157,7 @@ It exports the additional types `AfterTransform` and `Options`.
134157
135158Projects maintained by the unified collective are compatible with all maintained
136159versions 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+.
138161Our projects sometimes work with older versions, but this is not guaranteed.
139162
140163## Security
@@ -159,7 +182,7 @@ ways to get started.
159182See [ ` support.md ` ] [ support ] for ways to get help.
160183
161184This 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
163186abide by its terms.
164187
165188## License
@@ -214,10 +237,6 @@ abide by its terms.
214237
215238[ coc ] : https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
216239
217- [ hast ] : https://github.com/syntax-tree/hast
218-
219- [ dom ] : https://developer.mozilla.org/docs/Web/API/Document_Object_Model
220-
221240[ xss ] : https://en.wikipedia.org/wiki/Cross-site_scripting
222241
223242[ hast-util-sanitize ] : https://github.com/syntax-tree/hast-util-sanitize
@@ -227,3 +246,17 @@ abide by its terms.
227246[ jsdom ] : https://github.com/jsdom/jsdom
228247
229248[ 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