Skip to content

Commit 9da3339

Browse files
committed
Add improved docs
1 parent ccbae89 commit 9da3339

File tree

1 file changed

+124
-39
lines changed

1 file changed

+124
-39
lines changed

readme.md

+124-39
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,72 @@
88
[![Backers][backers-badge]][collective]
99
[![Chat][chat-badge]][chat]
1010

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].
1636

1737
## When to use this
1838

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

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].
2550

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
2852

29-
[npm][]:
53+
This package is [ESM only][esm].
54+
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]:
3055

3156
```sh
3257
npm install mdast-util-gfm-task-list-item
3358
```
3459

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+
3574
## Use
3675

37-
Say we have the following file, `example.md`:
76+
Say our document `example.md` contains:
3877

3978
```markdown
4079
* [ ] To do
@@ -44,16 +83,16 @@ Say we have the following file, `example.md`:
4483
2. [x] …messages
4584
```
4685

47-
And our module, `example.js`, looks as follows:
86+
…and our module `example.js` looks as follows:
4887

4988
```js
50-
import fs from 'node:fs'
89+
import fs from 'node:fs/promises'
5190
import {fromMarkdown} from 'mdast-util-from-markdown'
5291
import {toMarkdown} from 'mdast-util-to-markdown'
5392
import {gfmTaskListItem} from 'micromark-extension-gfm-task-list-item'
5493
import {gfmTaskListItemFromMarkdown, gfmTaskListItemToMarkdown} from 'mdast-util-gfm-task-list-item'
5594

56-
const doc = fs.readFileSync('example.md')
95+
const doc = await fs.readFile('example.md')
5796

5897
const tree = fromMarkdown(doc, {
5998
extensions: [gfmTaskListItem],
@@ -67,8 +106,7 @@ const out = toMarkdown(tree, {extensions: [gfmTaskListItemToMarkdown]})
67106
console.log(out)
68107
```
69108

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):
72110

73111
```js
74112
{
@@ -136,38 +174,75 @@ brevity):
136174

137175
## API
138176

139-
This package exports the following identifier: `gfmTaskListItemFromMarkdown`,
177+
This package exports the identifiers `gfmTaskListItemFromMarkdown` and
140178
`gfmTaskListItemToMarkdown`.
141179
There is no default export.
142180

143181
### `gfmTaskListItemFromMarkdown`
144182

183+
Extension for [`mdast-util-from-markdown`][mdast-util-from-markdown].
184+
145185
### `gfmTaskListItemToMarkdown`
146186

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+.
151231

152232
## Related
153233

154-
* [`remarkjs/remark`][remark]
155-
— markdown processor powered by plugins
156234
* [`remarkjs/remark-gfm`][remark-gfm]
157235
— 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)
160239
* [`micromark/micromark-extension-gfm-task-list-item`][extension]
161240
— 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
166241

167242
## Contribute
168243

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.
171246
See [`support.md`][support] for ways to get help.
172247

173248
This project has a [code of conduct][coc].
@@ -208,10 +283,18 @@ abide by its terms.
208283

209284
[npm]: https://docs.npmjs.com/cli/install
210285

286+
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
287+
288+
[esmsh]: https://esm.sh
289+
290+
[typescript]: https://www.typescriptlang.org
291+
211292
[license]: license
212293

213294
[author]: https://wooorm.com
214295

296+
[health]: https://github.com/syntax-tree/.github
297+
215298
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
216299

217300
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
@@ -220,14 +303,16 @@ abide by its terms.
220303

221304
[mdast]: https://github.com/syntax-tree/mdast
222305

223-
[remark]: https://github.com/remarkjs/remark
224-
225306
[remark-gfm]: https://github.com/remarkjs/remark-gfm
226307

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
228309

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
230311

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
232315

233316
[extension]: https://github.com/micromark/micromark-extension-gfm-task-list-item
317+
318+
[gfm]: https://github.github.com/gfm/

0 commit comments

Comments
 (0)