1717* [ Install] ( #install )
1818* [ Use] ( #use )
1919* [ API] ( #api )
20- * [ ` toText(node, options?) ` ] ( #totextnode-options )
20+ * [ ` toText(tree[, options]) ` ] ( #totexttree-options )
21+ * [ ` Options ` ] ( #options )
22+ * [ ` Whitespace ` ] ( #whitespace )
2123* [ Types] ( #types )
2224* [ Compatibility] ( #compatibility )
2325* [ Security] ( #security )
@@ -52,7 +54,7 @@ turning line endings into `<br>`s
5254## Install
5355
5456This package is [ ESM only] [ esm ] .
55- In Node.js (version 12.20+, 14.14+, 16.0+, 18 .0+), install with [ npm] [ ] :
57+ In Node.js (version 14.14+ or 16 .0+), install with [ npm] [ ] :
5658
5759``` sh
5860npm install hast-util-to-text
@@ -100,53 +102,77 @@ Delta echo foxtrot.
100102
101103## API
102104
103- This package exports the identifier ` toText ` .
105+ This package exports the identifier [ ` toText ` ] [ totext ] .
104106There is no default export.
105107
106- ### ` toText(node , options? ) `
108+ ### ` toText(tree[ , options] ) `
107109
108110Get the plain-text value of a node.
109111
110- * if ` node ` is a [ comment] [ ] , returns its ` value `
111- * if ` node ` is a [ text] [ ] , applies normal white-space collapsing to its
112- ` value ` , as defined by the [ CSS Text] [ css ] spec
113- * if ` node ` is a [ root] [ ] or [ element] [ ] , applies an algorithm similar to the
114- ` innerText ` getter as defined by [ HTML] [ ]
115-
116- ##### ` options `
112+ ###### Parameters
117113
118- Configuration (optional).
114+ * ` tree ` ([ ` Node ` ] [ node ] )
115+ — tree to turn into text
116+ * ` options ` ([ ` Options ` ] [ options ] , optional)
117+ — configuration
119118
120- ###### ` options.whitespace `
119+ ###### Returns
121120
122- Default whitespace setting to use ( ` 'normal' ` or ` 'pre' ` , default: ` 'normal' ` ).
121+ Serialized ` tree ` ( ` string ` ).
123122
124- ###### Returns
123+ ###### Algorithm
125124
126- Serialized ` node ` (` string ` ).
125+ * if ` tree ` is a [ comment] [ ] , returns its ` value `
126+ * if ` tree ` is a [ text] [ ] , applies normal whitespace collapsing to its
127+ ` value ` , as defined by the [ CSS Text] [ css ] spec
128+ * if ` tree ` is a [ root] [ ] or [ element] [ ] , applies an algorithm similar to the
129+ ` innerText ` getter as defined by [ HTML] [ ]
127130
128131###### Notes
129132
130- * if ` node ` is an element that is not displayed (such as a ` head ` ), we’ll
133+ > 👉 ** Note** : the algorithm acts as if ` tree ` is being rendered, and as if
134+ > we’re a CSS-supporting user agent, with scripting enabled.
135+
136+ * if ` tree ` is an element that is not displayed (such as a ` head ` ), we’ll
131137 still use the ` innerText ` algorithm instead of switching to ` textContent `
132- * if descendants of ` node ` are elements that are not displayed, they are
138+ * if descendants of ` tree ` are elements that are not displayed, they are
133139 ignored
134140* CSS is not considered, except for the default user agent style sheet
135141* a line feed is collapsed instead of ignored in cases where Fullwidth, Wide,
136142 or Halfwidth East Asian Width characters are used, the same goes for a case
137143 with Chinese, Japanese, or Yi writing systems
138144* replaced elements (such as ` audio ` ) are treated like non-replaced elements
139145
146+ ### ` Options `
147+
148+ Configuration (TypeScript type).
149+
150+ ##### Fields
151+
152+ * ` whitespace ` ([ ` Whitespace ` ] [ whitespace ] , default: ` 'normal' ` )
153+ — default whitespace setting to use
154+
155+ ### ` Whitespace `
156+
157+ Valid and useful whitespace values (from [ CSS] [ ] ) (TypeScript type).
158+
159+ ##### Type
160+
161+ ``` ts
162+ type Whitespace = ' normal' | ' pre' | ' nowrap' | ' pre-wrap'
163+ ` ` `
164+
140165## Types
141166
142167This package is fully typed with [TypeScript][].
143- It exports the additional type ` Options ` .
168+ It exports the additional types [ ` Options ` ][options] and
169+ [ ` Whitespace ` ][whitespace].
144170
145171## Compatibility
146172
147173Projects maintained by the unified collective are compatible with all maintained
148174versions of Node.js.
149- As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18 .0+.
175+ As of now, that is Node.js 14.14+ and 16 .0+.
150176Our projects sometimes work with older versions, but this is not guaranteed.
151177
152178## Security
@@ -225,7 +251,7 @@ abide by its terms.
225251
226252[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
227253
228- [ html ] : https://html.spec.whatwg.org/#the-innertext-idl-attribute
254+ [html]: https://html.spec.whatwg.org/multipage/dom.html #the-innertext-idl-attribute
229255
230256[css]: https://drafts.csswg.org/css-text/#white-space-phase-1
231257
@@ -235,6 +261,8 @@ abide by its terms.
235261
236262[hast]: https://github.com/syntax-tree/hast
237263
264+ [node]: https://github.com/syntax-tree/hast#nodes
265+
238266[root]: https://github.com/syntax-tree/hast#root
239267
240268[comment]: https://github.com/syntax-tree/hast#comment
@@ -244,3 +272,9 @@ abide by its terms.
244272[element]: https://github.com/syntax-tree/hast#element
245273
246274[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
275+
276+ [totext]: #totexttree-options
277+
278+ [options]: #options
279+
280+ [whitespace]: #whitespace
0 commit comments