@@ -14,8 +14,12 @@ task list items in **[mdast][]**.
14
14
When parsing (` from-markdown ` ), must be combined with
15
15
[ ` micromark-extension-gfm-task-list-item ` ] [ extension ] .
16
16
17
- You probably shouldn’t use this package directly, but instead use
18
- [ ` remark-gfm ` ] [ remark-gfm ] with ** [ remark] [ ] ** .
17
+ ## When to use this
18
+
19
+ Use this if you’re dealing with the AST manually.
20
+ It’s probably nicer to use [ ` remark-gfm ` ] [ remark-gfm ] with ** [ remark] [ ] ** , which
21
+ includes this but provides a nicer interface and makes it easier to combine with
22
+ hundreds of plugins.
19
23
20
24
## Install
21
25
@@ -40,25 +44,25 @@ Say we have the following file, `example.md`:
40
44
2. [x] …messages
41
45
```
42
46
43
- And our script , ` example.js ` , looks as follows:
47
+ And our module , ` example.js ` , looks as follows:
44
48
45
49
``` js
46
- var fs = require ( ' fs' )
47
- var fromMarkdown = require ( ' mdast-util-from-markdown' )
48
- var toMarkdown = require ( ' mdast-util-to-markdown' )
49
- var syntax = require ( ' micromark-extension-gfm-task-list-item' )
50
- var taskListItem = require ( ' mdast-util-gfm-task-list-item' )
50
+ import fs from ' node: fs'
51
+ import { fromMarkdown } from ' mdast-util-from-markdown'
52
+ import { toMarkdown } from ' mdast-util-to-markdown'
53
+ import { gfmTaskListItem } from ' micromark-extension-gfm-task-list-item'
54
+ import { gfmTaskListItemFromMarkdown , gfmTaskListItemToMarkdown } from ' mdast-util-gfm-task-list-item'
51
55
52
- var doc = fs .readFileSync (' example.md' )
56
+ const doc = fs .readFileSync (' example.md' )
53
57
54
- var tree = fromMarkdown (doc, {
55
- extensions: [syntax ],
56
- mdastExtensions: [taskListItem . fromMarkdown ]
58
+ const tree = fromMarkdown (doc, {
59
+ extensions: [gfmTaskListItem ],
60
+ mdastExtensions: [gfmTaskListItemFromMarkdown ]
57
61
})
58
62
59
63
console .log (tree)
60
64
61
- var out = toMarkdown (tree, {extensions: [taskListItem . toMarkdown ]})
65
+ const out = toMarkdown (tree, {extensions: [gfmTaskListItemToMarkdown ]})
62
66
63
67
console .log (out)
64
68
```
0 commit comments