Skip to content

Commit b2f7d6b

Browse files
committed
Add better docs
1 parent a099abd commit b2f7d6b

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

readme.md

+17-13
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ task list items in **[mdast][]**.
1414
When parsing (`from-markdown`), must be combined with
1515
[`micromark-extension-gfm-task-list-item`][extension].
1616

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.
1923

2024
## Install
2125

@@ -40,25 +44,25 @@ Say we have the following file, `example.md`:
4044
2. [x] …messages
4145
```
4246

43-
And our script, `example.js`, looks as follows:
47+
And our module, `example.js`, looks as follows:
4448

4549
```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'
5155

52-
var doc = fs.readFileSync('example.md')
56+
const doc = fs.readFileSync('example.md')
5357

54-
var tree = fromMarkdown(doc, {
55-
extensions: [syntax],
56-
mdastExtensions: [taskListItem.fromMarkdown]
58+
const tree = fromMarkdown(doc, {
59+
extensions: [gfmTaskListItem],
60+
mdastExtensions: [gfmTaskListItemFromMarkdown]
5761
})
5862

5963
console.log(tree)
6064

61-
var out = toMarkdown(tree, {extensions: [taskListItem.toMarkdown]})
65+
const out = toMarkdown(tree, {extensions: [gfmTaskListItemToMarkdown]})
6266

6367
console.log(out)
6468
```

0 commit comments

Comments
 (0)