8
8
[ ![ Backers] [ backers-badge ]] [ collective ]
9
9
[ ![ Chat] [ chat-badge ]] [ chat ]
10
10
11
- Extension for [ ` mdast-util-from-markdown ` ] [ from-markdown ] and/or
12
- [ ` mdast-util-to-markdown ` ] [ to-markdown ] to support GitHub flavored markdown
13
- task list items in ** [ mdast] [ ] ** .
14
- When parsing (` from-markdown ` ), must be combined with
15
- [ ` micromark-extension-gfm-task-list-item ` ] [ extension ] .
11
+ [ mdast] [ ] extensions to parse and serialize [ GFM] [ ] task list items.
12
+
13
+ ## Contents
14
+
15
+ * [ What is this?] ( #what-is-this )
16
+ * [ When to use this] ( #when-to-use-this )
17
+ * [ Install] ( #install )
18
+ * [ Use] ( #use )
19
+ * [ API] ( #api )
20
+ * [ ` gfmTaskListItemFromMarkdown ` ] ( #gfmtasklistitemfrommarkdown )
21
+ * [ ` gfmTaskListItemToMarkdown ` ] ( #gfmtasklistitemtomarkdown )
22
+ * [ Syntax tree] ( #syntax-tree )
23
+ * [ Nodes] ( #nodes )
24
+ * [ Content model] ( #content-model )
25
+ * [ Types] ( #types )
26
+ * [ Compatibility] ( #compatibility )
27
+ * [ Related] ( #related )
28
+ * [ Contribute] ( #contribute )
29
+ * [ License] ( #license )
30
+
31
+ ## What is this?
32
+
33
+ This package contains extensions that add support for the task list item syntax
34
+ enabled by GFM to [ ` mdast-util-from-markdown ` ] [ mdast-util-from-markdown ] and
35
+ [ ` mdast-util-to-markdown ` ] [ mdast-util-to-markdown ] .
16
36
17
37
## When to use this
18
38
19
- Use this if you’re dealing with the AST manually.
20
- It’s might be better to use [ ` remark-gfm ` ] [ remark-gfm ] with ** [ remark] [ ] ** ,
21
- which includes this but provides a nicer interface and makes it easier to
22
- combine with hundreds of plugins.
39
+ These tools are all rather low-level.
40
+ In most cases, you’d want to use [ ` remark-gfm ` ] [ remark-gfm ] with remark instead.
23
41
24
- ## Install
42
+ When you are working with syntax trees and want all of GFM, use
43
+ [ ` mdast-util-gfm ` ] [ mdast-util-gfm ] instead.
44
+
45
+ When working with ` mdast-util-from-markdown ` , you must combine this package with
46
+ [ ` micromark-extension-gfm-task-list-item ` ] [ extension ] .
47
+
48
+ This utility does not handle how markdown is turned to HTML.
49
+ That’s done by [ ` mdast-util-to-hast ` ] [ mdast-util-to-hast ] .
25
50
26
- This package is [ ESM only] ( https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c ) :
27
- Node 12+ is needed to use it and it must be ` import ` ed instead of ` require ` d.
51
+ ## Install
28
52
29
- [ npm] [ ] :
53
+ This package is [ ESM only] [ esm ] .
54
+ In Node.js (version 12.20+, 14.14+, or 16.0+), install with [ npm] [ ] :
30
55
31
56
``` sh
32
57
npm install mdast-util-gfm-task-list-item
33
58
```
34
59
60
+ In Deno with [ ` esm.sh ` ] [ esmsh ] :
61
+
62
+ ``` js
63
+ import {gfmTaskListItemFromMarkdown , gfmTaskListItemToMarkdown } from ' https://esm.sh/mdast-util-gfm-task-list-item@1'
64
+ ```
65
+
66
+ In browsers with [ ` esm.sh ` ] [ esmsh ] :
67
+
68
+ ``` html
69
+ <script type =" module" >
70
+ import {gfmTaskListItemFromMarkdown , gfmTaskListItemToMarkdown } from ' https://esm.sh/mdast-util-gfm-task-list-item@1?bundle'
71
+ </script >
72
+ ```
73
+
35
74
## Use
36
75
37
- Say we have the following file, ` example.md ` :
76
+ Say our document ` example.md ` contains :
38
77
39
78
``` markdown
40
79
* [ ] To do
@@ -44,16 +83,16 @@ Say we have the following file, `example.md`:
44
83
2. [x] …messages
45
84
```
46
85
47
- And our module, ` example.js ` , looks as follows:
86
+ …and our module ` example.js ` looks as follows:
48
87
49
88
``` js
50
- import fs from ' node:fs'
89
+ import fs from ' node:fs/promises '
51
90
import {fromMarkdown } from ' mdast-util-from-markdown'
52
91
import {toMarkdown } from ' mdast-util-to-markdown'
53
92
import {gfmTaskListItem } from ' micromark-extension-gfm-task-list-item'
54
93
import {gfmTaskListItemFromMarkdown , gfmTaskListItemToMarkdown } from ' mdast-util-gfm-task-list-item'
55
94
56
- const doc = fs .readFileSync (' example.md' )
95
+ const doc = await fs .readFile (' example.md' )
57
96
58
97
const tree = fromMarkdown (doc, {
59
98
extensions: [gfmTaskListItem],
@@ -67,8 +106,7 @@ const out = toMarkdown(tree, {extensions: [gfmTaskListItemToMarkdown]})
67
106
console .log (out)
68
107
```
69
108
70
- Now, running ` node example ` yields (positional info removed for the sake of
71
- brevity):
109
+ …now running ` node example.js ` yields (positional info removed for brevity):
72
110
73
111
``` js
74
112
{
@@ -136,38 +174,75 @@ brevity):
136
174
137
175
## API
138
176
139
- This package exports the following identifier: ` gfmTaskListItemFromMarkdown ` ,
177
+ This package exports the identifiers ` gfmTaskListItemFromMarkdown ` and
140
178
` gfmTaskListItemToMarkdown ` .
141
179
There is no default export.
142
180
143
181
### ` gfmTaskListItemFromMarkdown `
144
182
183
+ Extension for [ ` mdast-util-from-markdown ` ] [ mdast-util-from-markdown ] .
184
+
145
185
### ` gfmTaskListItemToMarkdown `
146
186
147
- Support task list items.
148
- The exports are extensions, respectively
149
- for [ ` mdast-util-from-markdown ` ] [ from-markdown ] and
150
- [ ` mdast-util-to-markdown ` ] [ to-markdown ] .
187
+ Extension for [ ` mdast-util-to-markdown ` ] [ mdast-util-to-markdown ] .
188
+
189
+ ## Syntax tree
190
+
191
+ The following interfaces are added to ** [ mdast] [ ] ** by this utility.
192
+
193
+ ### Nodes
194
+
195
+ #### ` ListItem ` (GFM)
196
+
197
+ ``` idl
198
+ interface ListItemGfm <: ListItem {
199
+ checked: boolean?
200
+ }
201
+ ```
202
+
203
+ In GFM, a ` checked ` field can be present.
204
+ It represents whether the item is done (when ` true ` ), not done (when ` false ` ),
205
+ or indeterminate or not applicable (when ` null ` or not present).
206
+
207
+ ### Content model
208
+
209
+ #### ` ListContent ` (GFM)
210
+
211
+ ``` idl
212
+ type ListContentGfm = ListItemGfm
213
+ ```
214
+
215
+ ## Types
216
+
217
+ This package is fully typed with [ TypeScript] [ ] .
218
+ It does not export additional types.
219
+
220
+ The ` ListItemGfm ` node type is supported in ` @types/mdast ` by default.
221
+
222
+ ## Compatibility
223
+
224
+ Projects maintained by the unified collective are compatible with all maintained
225
+ versions of Node.js.
226
+ As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
227
+ Our projects sometimes work with older versions, but this is not guaranteed.
228
+
229
+ This plugin works with ` mdast-util-from-markdown ` version 1+ and
230
+ ` mdast-util-to-markdown ` version 1+.
151
231
152
232
## Related
153
233
154
- * [ ` remarkjs/remark ` ] [ remark ]
155
- — markdown processor powered by plugins
156
234
* [ ` remarkjs/remark-gfm ` ] [ remark-gfm ]
157
235
— remark plugin to support GFM
158
- * [ ` micromark/micromark ` ] [ micromark ]
159
- — the smallest commonmark-compliant markdown parser that exists
236
+ * [ ` syntax-tree/mdast-util-gfm ` ] [ mdast-util-gfm ]
237
+ — same but all of GFM (autolink literals, footnotes, strikethrough, tables,
238
+ tasklists)
160
239
* [ ` micromark/micromark-extension-gfm-task-list-item ` ] [ extension ]
161
240
— micromark extension to parse GFM task list items
162
- * [ ` syntax-tree/mdast-util-from-markdown ` ] [ from-markdown ]
163
- — mdast parser using ` micromark ` to create mdast from markdown
164
- * [ ` syntax-tree/mdast-util-to-markdown ` ] [ to-markdown ]
165
- — mdast serializer to create markdown from mdast
166
241
167
242
## Contribute
168
243
169
- See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
170
- started.
244
+ See [ ` contributing.md ` ] [ contributing ] in [ ` syntax-tree/.github ` ] [ health ] for
245
+ ways to get started.
171
246
See [ ` support.md ` ] [ support ] for ways to get help.
172
247
173
248
This project has a [ code of conduct] [ coc ] .
@@ -208,10 +283,18 @@ abide by its terms.
208
283
209
284
[ npm ] : https://docs.npmjs.com/cli/install
210
285
286
+ [ esm ] : https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
287
+
288
+ [ esmsh ] : https://esm.sh
289
+
290
+ [ typescript ] : https://www.typescriptlang.org
291
+
211
292
[ license ] : license
212
293
213
294
[ author ] : https://wooorm.com
214
295
296
+ [ health ] : https://github.com/syntax-tree/.github
297
+
215
298
[ contributing ] : https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
216
299
217
300
[ support ] : https://github.com/syntax-tree/.github/blob/HEAD/support.md
@@ -220,14 +303,16 @@ abide by its terms.
220
303
221
304
[ mdast ] : https://github.com/syntax-tree/mdast
222
305
223
- [ remark ] : https://github.com/remarkjs/remark
224
-
225
306
[ remark-gfm ] : https://github.com/remarkjs/remark-gfm
226
307
227
- [ from-markdown ] : https://github.com/syntax-tree/mdast-util-from-markdown
308
+ [ mdast-util- from-markdown] : https://github.com/syntax-tree/mdast-util-from-markdown
228
309
229
- [ to-markdown ] : https://github.com/syntax-tree/mdast-util-to-markdown
310
+ [ mdast-util- to-markdown] : https://github.com/syntax-tree/mdast-util-to-markdown
230
311
231
- [ micromark ] : https://github.com/micromark/micromark
312
+ [ mdast-util-gfm ] : https://github.com/syntax-tree/mdast-util-gfm
313
+
314
+ [ mdast-util-to-hast ] : https://github.com/syntax-tree/mdast-util-to-hast
232
315
233
316
[ extension ] : https://github.com/micromark/micromark-extension-gfm-task-list-item
317
+
318
+ [ gfm ] : https://github.github.com/gfm/
0 commit comments