18
18
* [ Use] ( #use )
19
19
* [ API] ( #api )
20
20
* [ ` toNlcst(tree, file, Parser) ` ] ( #tonlcsttree-file-parser )
21
+ * [ ` ParserConstructor ` ] ( #parserconstructor )
22
+ * [ ` ParserInstance ` ] ( #parserinstance )
21
23
* [ Types] ( #types )
22
24
* [ Compatibility] ( #compatibility )
23
25
* [ Security] ( #security )
@@ -46,7 +48,7 @@ same at a higher-level (easier) abstraction.
46
48
## Install
47
49
48
50
This package is [ ESM only] [ esm ] .
49
- In Node.js (version 12.20+, 14.14+, or 16.0+), install with [ npm] [ ] :
51
+ In Node.js (version 14.14+ and or 16.0+), install with [ npm] [ ] :
50
52
51
53
``` sh
52
54
npm install hast-util-to-nlcst
@@ -119,17 +121,25 @@ RootNode[2] (1:1-6:1, 0-134)
119
121
120
122
## API
121
123
122
- This package exports the identifier ` toNlcst ` .
124
+ This package exports the identifier [ ` toNlcst ` ] [ tonlcst ] .
123
125
There is no default export.
124
126
125
127
### ` toNlcst(tree, file, Parser) `
126
128
127
- [ hast] [ ] utility to transform to [ nlcst] [ ] .
129
+ Turn a hast tree into an nlcst tree.
130
+
131
+ > 👉 ** Note** : ` tree ` must have positional info and ` file ` must be a ` VFile `
132
+ > corresponding to ` tree ` .
133
+
134
+ ##### Parameters
128
135
129
- > 👉 ** Note** : ` tree ` must have positional info, ` file ` must be a [ vfile] [ ]
130
- > corresponding to ` tree ` , and ` Parser ` must be a parser such as
131
- > [ ` parse-english ` ] [ parse-english ] , [ ` parse-dutch ` ] [ parse-dutch ] , or
132
- > [ ` parse-latin ` ] [ parse-latin ] .
136
+ * ` tree ` ([ ` HastNode ` ] [ hast-node ] )
137
+ — hast tree to transform
138
+ * ` file ` ([ ` VFile ` ] [ vfile ] )
139
+ — virtual file
140
+ * ` Parser ` ([ ` ParserConstructor ` ] [ parserconstructor ] or
141
+ [ ` ParserInstance ` ] [ parserinstance ] )
142
+ — parser to use.
133
143
134
144
##### Returns
135
145
@@ -176,16 +186,46 @@ of `source`:
176
186
<p data-nlcst =" source" >Completely marked.</p >
177
187
```
178
188
189
+ ### ` ParserConstructor `
190
+
191
+ Create a new parser (TypeScript type).
192
+
193
+ ###### Type
194
+
195
+ ``` ts
196
+ type ParserConstructor = new () => ParserInstance
197
+ ` ` `
198
+
199
+ ### ` ParserInstance `
200
+
201
+ nlcst parser (TypeScript type).
202
+
203
+ For example, [ ` parse -dutch ` ][parse-dutch], [ ` parse -english ` ][parse-english], or
204
+ [ ` parse -latin ` ][parse-latin].
205
+
206
+ ###### Type
207
+
208
+ ` ` ` ts
209
+ type ParserInstance = type ParserInstance = {
210
+ tokenizeSentencePlugins: Array <(node : NlcstSentence ) => void >
211
+ tokenizeParagraphPlugins: Array <(node : NlcstParagraph ) => void >
212
+ parse(value : string | null | undefined ): NlcstRoot
213
+ tokenizeParagraph(value : string | null | undefined ): NlcstParagraph
214
+ tokenize(value : string | null | undefined ): Array <NlcstSentenceContent >
215
+ }
216
+ ` ` `
217
+
179
218
## Types
180
219
181
220
This package is fully typed with [TypeScript][].
182
- It exports the additional types ` ParserConstructor ` and ` ParserInstance ` .
221
+ It exports the additional types [ ` ParserConstructor ` ][parserconstructor] and
222
+ [ ` ParserInstance ` ][parserinstance].
183
223
184
224
## Compatibility
185
225
186
226
Projects maintained by the unified collective are compatible with all maintained
187
227
versions of Node.js.
188
- As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
228
+ As of now, that is Node.js 14.14+ and 16.0+.
189
229
Our projects sometimes work with older versions, but this is not guaranteed.
190
230
191
231
## Security
@@ -270,6 +310,8 @@ abide by its terms.
270
310
271
311
[hast]: https://github.com/syntax-tree/hast
272
312
313
+ [hast-node]: https://github.com/syntax-tree/hast#nodes
314
+
273
315
[nlcst]: https://github.com/syntax-tree/nlcst
274
316
275
317
[nlcst-node]: https://github.com/syntax-tree/nlcst#nodes
@@ -285,3 +327,9 @@ abide by its terms.
285
327
[parse-latin]: https://github.com/wooorm/parse-latin
286
328
287
329
[parse-dutch]: https://github.com/wooorm/parse-dutch
330
+
331
+ [tonlcst]: #tonlcsttree-file-parser
332
+
333
+ [parserconstructor]: #parserconstructor
334
+
335
+ [parserinstance]: #parserinstance
0 commit comments