8
8
[ ![ Backers] [ backers-badge ]] [ collective ]
9
9
[ ![ Chat] [ chat-badge ]] [ chat ]
10
10
11
- [ ** mdast** ] [ mdast ] utility to transform to [ ** nlcst** ] [ nlcst ] .
11
+ [ mdast] [ ] utility to transform to [ nlcst] [ ] .
12
12
13
- > ** Note ** : You probably want to use [ ` remark-retext ` ] [ remark-retext ] .
13
+ ## Contents
14
14
15
- ## Install
15
+ * [ What is this?] ( #what-is-this )
16
+ * [ When should I use this?] ( #when-should-i-use-this )
17
+ * [ Install] ( #install )
18
+ * [ Use] ( #use )
19
+ * [ API] ( #api )
20
+ * [ ` toNlcst(tree, file, Parser[, options]) ` ] ( #tonlcsttree-file-parser-options )
21
+ * [ Types] ( #types )
22
+ * [ Compatibility] ( #compatibility )
23
+ * [ Security] ( #security )
24
+ * [ Related] ( #related )
25
+ * [ Contribute] ( #contribute )
26
+ * [ License] ( #license )
27
+
28
+ ## What is this?
29
+
30
+ This package is a utility that takes an [ mdast] [ ] (markdown) syntax tree as
31
+ input and turns it into [ nlcst] [ ] (natural language).
32
+
33
+ ## When should I use this?
16
34
17
- This package is [ ESM only] ( https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c ) :
18
- Node 12+ is needed to use it and it must be ` import ` ed instead of ` require ` d.
35
+ This project is useful when you want to deal with ASTs and inspect the natural
36
+ language inside markdown.
37
+ Unfortunately, there is no way yet to apply changes to the nlcst back into
38
+ mdast.
39
+
40
+ The hast utility [ ` hast-util-to-nlcst ` ] [ hast-util-to-nlcst ] does the same but
41
+ uses an HTML tree as input.
42
+
43
+ The remark plugin [ ` remark-retext ` ] [ remark-retext ] wraps this utility to do the
44
+ same at a higher-level (easier) abstraction.
45
+
46
+ ## Install
19
47
20
- [ npm] [ ] :
48
+ This package is [ ESM only] [ esm ] .
49
+ In Node.js (version 12.20+, 14.14+, or 16.0+), install with [ npm] [ ] :
21
50
22
51
``` sh
23
52
npm install mdast-util-to-nlcst
24
53
```
25
54
55
+ In Deno with [ ` esm.sh ` ] [ esmsh ] :
56
+
57
+ ``` js
58
+ import {toNlcst } from " https://esm.sh/mdast-util-to-nlcst@5"
59
+ ```
60
+
61
+ In browsers with [ ` esm.sh ` ] [ esmsh ] :
62
+
63
+ ``` html
64
+ <script type =" module" >
65
+ import {toNlcst } from " https://esm.sh/mdast-util-to-nlcst@5?bundle"
66
+ </script >
67
+ ```
68
+
26
69
## Use
27
70
71
+ Say we have the following ` example.md ` :
72
+
73
+ ``` markdown
74
+ Some *foo*sball.
75
+ ```
76
+
77
+ …and next to it a module ` example.js ` :
78
+
28
79
``` js
29
- import {VFile } from ' vfile'
80
+ import {read } from ' to- vfile'
30
81
import {ParseEnglish } from ' parse-english'
31
82
import {inspect } from ' unist-util-inspect'
32
- import fromMarkdown from ' mdast-util-from-markdown'
83
+ import { fromMarkdown } from ' mdast-util-from-markdown'
33
84
import {toNlcst } from ' mdast-util-to-nlcst'
34
85
35
- const file = new VFile ( ' Some *foo*sball. ' )
86
+ const file = await read ( ' example.md ' )
36
87
const mdast = fromMarkdown (file)
37
88
const nlcst = toNlcst (mdast, file, ParseEnglish)
38
89
@@ -56,49 +107,28 @@ RootNode[1] (1:1-1:17, 0-16)
56
107
57
108
## API
58
109
59
- This package exports the following identifiers: ` toNlcst ` .
110
+ This package exports the identifier ` toNlcst ` .
60
111
There is no default export.
61
112
62
113
### ` toNlcst(tree, file, Parser[, options]) `
63
114
64
- Transform a [ tree] [ ] in [ mdast] [ ] , with a corresponding [ virtual file] [ vfile ] ,
65
- into [ nlcst] [ ] .
66
-
67
- ##### Parameters
68
-
69
- ###### ` node `
70
-
71
- Tree in [ mdast] [ ] with positional information ([ ` MdastNode ` ] [ mdastnode ] ).
72
-
73
- ###### ` file `
115
+ [ mdast] [ ] utility to transform to [ nlcst] [ ] .
74
116
75
- Virtual file ([ ` VFile ` ] [ vfile ] ).
117
+ > 👉 ** Note** : ` tree ` must have positional info, ` file ` must be a [ vfile] [ ]
118
+ > corresponding to ` tree ` , and ` Parser ` must be a parser such as
119
+ > [ ` parse-english ` ] [ parse-english ] , [ ` parse-dutch ` ] [ parse-dutch ] , or
120
+ > [ ` parse-latin ` ] [ parse-latin ] .
76
121
77
- ###### ` parser `
122
+ ##### ` options `
78
123
79
- [ nlcst] [ ] parser (` Function ` ).
80
- For example, [ ` parse-english ` ] [ english ] , [ ` parse-dutch ` ] [ dutch ] , or
81
- [ ` parse-latin ` ] [ latin ] .
124
+ Configuration (optional).
82
125
83
126
###### ` options.ignore `
84
127
85
- List of [ types] [ type ] to ignore (` Array<string> ` ).
86
-
87
- ` 'table' ` , ` 'tableRow' ` , and ` 'tableCell' ` are always ignored.
88
-
89
- ###### ` options.source `
90
-
91
- List of [ types] [ type ] to mark as [ source] [ ] (` Array<string> ` ).
92
-
93
- ` 'inlineCode' ` is always marked as source.
94
-
95
- ##### Returns
96
-
97
- [ ` NlcstNode ` ] [ nlcstnode ] .
98
-
99
- ##### Examples
128
+ List of [ mdast] [ ] node types to ignore (` Array<string> ` , optional).
129
+ The types ` 'table' ` , ` 'tableRow' ` , and ` 'tableCell' ` are always ignored.
100
130
101
- ###### ` ignore `
131
+ < details >< summary >Show example</ summary >
102
132
103
133
Say we have the following file ` example.md ` :
104
134
@@ -123,7 +153,15 @@ RootNode[2] (1:1-3:1, 0-14)
123
153
└─1 WhiteSpaceNode "\n\n" (1:13-3:1, 12-14)
124
154
```
125
155
126
- ###### ` source `
156
+ </details >
157
+
158
+ ###### ` options.source `
159
+
160
+ List of [ mdast] [ ] node types to mark as [ nlcst] [ ] source nodes
161
+ (` Array<string> ` , optional).
162
+ The type ` 'inlineCode' ` is always marked as source.
163
+
164
+ <details ><summary >Show example</summary >
127
165
128
166
Say we have the following file ` example.md ` :
129
167
@@ -151,28 +189,46 @@ RootNode[3] (1:1-3:32, 0-45)
151
189
└─0 SourceNode "> A paragraph in a block quote." (3:1-3:32, 14-45)
152
190
```
153
191
192
+ </details >
193
+
194
+ ##### Returns
195
+
196
+ [ ` NlcstNode ` ] [ nlcst-node ] .
197
+
198
+ ## Types
199
+
200
+ This package is fully typed with [ TypeScript] [ ] .
201
+ It exports the type ` Options ` .
202
+
203
+ ## Compatibility
204
+
205
+ Projects maintained by the unified collective are compatible with all maintained
206
+ versions of Node.js.
207
+ As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
208
+ Our projects sometimes work with older versions, but this is not guaranteed.
209
+
154
210
## Security
155
211
156
212
Use of ` mdast-util-to-nlcst ` does not involve [ ** hast** ] [ hast ] so there are no
157
213
openings for [ cross-site scripting (XSS)] [ xss ] attacks.
158
214
159
215
## Related
160
216
161
- * [ ` remark-retext ` ] [ remark-retext ]
162
- — ** retext ** support for ** remark **
217
+ * [ ` mdast-util-to-hast ` ] ( https://github.com/syntax-tree/mdast-util-to-hast )
218
+ — transform mdast to hast
163
219
* [ ` hast-util-to-nlcst ` ] ( https://github.com/syntax-tree/hast-util-to-nlcst )
164
- — Transform [ hast] [ ] to [ nlcst] [ ]
220
+ — transform hast to nlcst
165
221
* [ ` hast-util-to-mdast ` ] ( https://github.com/syntax-tree/hast-util-to-mdast )
166
- — Transform [ hast] [ ] to [ mdast] [ ]
222
+ — transform hast to mdast
167
223
* [ ` hast-util-to-xast ` ] ( https://github.com/syntax-tree/hast-util-to-xast )
168
- — Transform [ hast] [ ] to [ xast] [ ]
169
- * [ ` mdast -util-to-hast ` ] ( https://github.com/syntax-tree/mdast -util-to-hast )
170
- — Transform [ mdast ] [ ] to [ hast] [ ]
224
+ — transform hast to xast
225
+ * [ ` hast -util-sanitize ` ] ( https://github.com/syntax-tree/hast -util-sanitize )
226
+ — sanitize hast nodes
171
227
172
228
## Contribute
173
229
174
- See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
175
- started.
230
+ See [ ` contributing.md ` ] [ contributing ] in [ ` syntax-tree/.github ` ] [ health ] for
231
+ ways to get started.
176
232
See [ ` support.md ` ] [ support ] for ways to get help.
177
233
178
234
This project has a [ code of conduct] [ coc ] .
@@ -213,42 +269,42 @@ abide by its terms.
213
269
214
270
[ npm ] : https://docs.npmjs.com/cli/install
215
271
272
+ [ esm ] : https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
273
+
274
+ [ esmsh ] : https://esm.sh
275
+
276
+ [ typescript ] : https://www.typescriptlang.org
277
+
216
278
[ license ] : license
217
279
218
280
[ author ] : https://wooorm.com
219
281
220
- [ contributing ] : https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
282
+ [ health ] : https://github.com/syntax-tree/.github
221
283
222
- [ support ] : https://github.com/syntax-tree/.github/blob/HEAD/support .md
284
+ [ contributing ] : https://github.com/syntax-tree/.github/blob/main/contributing .md
223
285
224
- [ coc ] : https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
286
+ [ support ] : https://github.com/syntax-tree/.github/blob/main/support.md
287
+
288
+ [ coc ] : https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
289
+
290
+ [ xss ] : https://en.wikipedia.org/wiki/Cross-site_scripting
225
291
226
292
[ mdast ] : https://github.com/syntax-tree/mdast
227
293
228
294
[ nlcst ] : https://github.com/syntax-tree/nlcst
229
295
296
+ [ nlcst-node ] : https://github.com/syntax-tree/nlcst#node
297
+
230
298
[ hast ] : https://github.com/syntax-tree/hast
231
299
232
- [ xast ] : https://github.com/syntax-tree/xast
300
+ [ hast-util-to-nlcst ] : https://github.com/syntax-tree/hast-util-to-nlcst
233
301
234
302
[ remark-retext ] : https://github.com/remarkjs/remark-retext
235
303
236
304
[ vfile ] : https://github.com/vfile/vfile
237
305
238
- [ english ] : https://github.com/wooorm/parse-english
306
+ [ parse- english] : https://github.com/wooorm/parse-english
239
307
240
- [ latin ] : https://github.com/wooorm/parse-latin
308
+ [ parse- latin] : https://github.com/wooorm/parse-latin
241
309
242
- [ dutch ] : https://github.com/wooorm/parse-dutch
243
-
244
- [ type ] : https://github.com/syntax-tree/mdast#ast
245
-
246
- [ source ] : https://github.com/syntax-tree/nlcst#source
247
-
248
- [ tree ] : https://github.com/syntax-tree/unist#tree
249
-
250
- [ mdastnode ] : https://github.com/syntax-tree/mdast#nodes
251
-
252
- [ nlcstnode ] : https://github.com/syntax-tree/nlcst#nodes
253
-
254
- [ xss ] : https://en.wikipedia.org/wiki/Cross-site_scripting
310
+ [ parse-dutch ] : https://github.com/wooorm/parse-dutch
0 commit comments