Skip to content

Commit 24d6765

Browse files
committed
Add improved docs
1 parent 2e91ced commit 24d6765

File tree

1 file changed

+157
-38
lines changed

1 file changed

+157
-38
lines changed

readme.md

Lines changed: 157 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,88 @@
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-
strikethrough (~~like this~~) in **[mdast][]**.
14-
When parsing (`from-markdown`), must be combined with
15-
[`micromark-extension-gfm-strikethrough`][extension].
11+
[mdast][] extensions to parse and serialize [GFM][] strikethrough.
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+
* [`gfmStrikethroughFromMarkdown`](#gfmstrikethroughfrommarkdown)
21+
* [`gfmStrikethroughToMarkdown`](#gfmstrikethroughtomarkdown)
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 strikethrough 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-strikethrough`][extension].
2547

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.
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].
50+
If you want a different element, you should configure that utility.
2851

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

3157
```sh
3258
npm install mdast-util-gfm-strikethrough
3359
```
3460

61+
In Deno with [`esm.sh`][esmsh]:
62+
63+
```js
64+
import {gfmStrikethroughFromMarkdown, gfmStrikethroughToMarkdown} from 'https://esm.sh/mdast-util-gfm-strikethrough@1'
65+
```
66+
67+
In browsers with [`esm.sh`][esmsh]:
68+
69+
```html
70+
<script type="module">
71+
import {gfmStrikethroughFromMarkdown, gfmStrikethroughToMarkdown} from 'https://esm.sh/mdast-util-gfm-strikethrough@1?bundle'
72+
</script>
73+
```
74+
3575
## Use
3676

37-
Say our module, `example.js`, looks as follows:
77+
Say our document `example.md` contains:
78+
79+
```markdown
80+
*Emphasis*, **importance**, and ~~strikethrough~~.
81+
```
82+
83+
…and our module `example.js` looks as follows:
3884

3985
```js
86+
import fs from 'node:fs/promises'
4087
import {fromMarkdown} from 'mdast-util-from-markdown'
4188
import {toMarkdown} from 'mdast-util-to-markdown'
4289
import {gfmStrikethrough} from 'micromark-extension-gfm-strikethrough'
4390
import {gfmStrikethroughFromMarkdown, gfmStrikethroughToMarkdown} from 'mdast-util-gfm-strikethrough'
4491

45-
const doc = '*Emphasis*, **importance**, and ~~strikethrough~~.'
92+
const doc = await fs.readFile('example.md')
4693

4794
const tree = fromMarkdown(doc, {
4895
extensions: [gfmStrikethrough()],
@@ -83,38 +130,94 @@ Now, running `node example` yields:
83130

84131
## API
85132

86-
This package exports the following identifier: `gfmStrikethroughFromMarkdown`,
133+
This package exports the identifiers `gfmStrikethroughFromMarkdown` and
87134
`gfmStrikethroughToMarkdown`.
88135
There is no default export.
89136

90137
### `gfmStrikethroughFromMarkdown`
91138

139+
Extension for [`mdast-util-from-markdown`][mdast-util-from-markdown].
140+
92141
### `gfmStrikethroughToMarkdown`
93142

94-
Support strikethrough.
95-
The exports are extensions, respectively
96-
for [`mdast-util-from-markdown`][from-markdown] and
97-
[`mdast-util-to-markdown`][to-markdown].
143+
Extension for [`mdast-util-to-markdown`][mdast-util-to-markdown].
144+
145+
## Syntax tree
146+
147+
The following interfaces are added to **[mdast][]** by this utility.
148+
149+
### Nodes
150+
151+
#### `Delete`
152+
153+
```idl
154+
interface Delete <: Parent {
155+
type: "delete"
156+
children: [TransparentContent]
157+
}
158+
```
159+
160+
**Delete** ([**Parent**][dfn-parent]) represents contents that are no longer
161+
accurate or no longer relevant.
162+
163+
**Delete** can be used where [**static phrasing**][dfn-static-phrasing-content]
164+
content is expected.
165+
Its content model is [**transparent**][dfn-transparent-content] content.
166+
167+
For example, the following markdown:
168+
169+
```markdown
170+
~~alpha~~
171+
```
172+
173+
Yields:
174+
175+
```js
176+
{
177+
type: 'delete',
178+
children: [{type: 'text', value: 'alpha'}]
179+
}
180+
```
181+
182+
### Content model
183+
184+
#### `StaticPhrasingContent` (GFM strikethrough)
185+
186+
```idl
187+
type StaticPhrasingContentGfm = Delete | StaticPhrasingContent
188+
```
189+
190+
## Types
191+
192+
This package is fully typed with [TypeScript][].
193+
It does not export additional types.
194+
195+
The `Delete` node type is supported in `@types/mdast` by default.
196+
197+
## Compatibility
198+
199+
Projects maintained by the unified collective are compatible with all maintained
200+
versions of Node.js.
201+
As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
202+
Our projects sometimes work with older versions, but this is not guaranteed.
203+
204+
This plugin works with `mdast-util-from-markdown` version 1+ and
205+
`mdast-util-to-markdown` version 1+.
98206

99207
## Related
100208

101-
* [`remarkjs/remark`][remark]
102-
— markdown processor powered by plugins
103209
* [`remarkjs/remark-gfm`][remark-gfm]
104210
— remark plugin to support GFM
105-
* [`micromark/micromark`][micromark]
106-
— the smallest commonmark-compliant markdown parser that exists
211+
* [`syntax-tree/mdast-util-gfm`][mdast-util-gfm]
212+
— same but all of GFM (autolink literals, footnotes, strikethrough, tables,
213+
tasklists)
107214
* [`micromark/micromark-extension-gfm-strikethrough`][extension]
108215
— micromark extension to parse GFM strikethrough
109-
* [`syntax-tree/mdast-util-from-markdown`][from-markdown]
110-
— mdast parser using `micromark` to create mdast from markdown
111-
* [`syntax-tree/mdast-util-to-markdown`][to-markdown]
112-
— mdast serializer to create markdown from mdast
113216

114217
## Contribute
115218

116-
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
117-
started.
219+
See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for
220+
ways to get started.
118221
See [`support.md`][support] for ways to get help.
119222

120223
This project has a [code of conduct][coc].
@@ -155,26 +258,42 @@ abide by its terms.
155258

156259
[npm]: https://docs.npmjs.com/cli/install
157260

261+
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
262+
263+
[esmsh]: https://esm.sh
264+
265+
[typescript]: https://www.typescriptlang.org
266+
158267
[license]: license
159268

160269
[author]: https://wooorm.com
161270

162-
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
271+
[health]: https://github.com/syntax-tree/.github
163272

164-
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
273+
[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md
165274

166-
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
275+
[support]: https://github.com/syntax-tree/.github/blob/main/support.md
167276

168-
[mdast]: https://github.com/syntax-tree/mdast
277+
[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
169278

170-
[remark]: https://github.com/remarkjs/remark
279+
[gfm]: https://github.github.com/gfm/
171280

172281
[remark-gfm]: https://github.com/remarkjs/remark-gfm
173282

174-
[from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown
283+
[mdast]: https://github.com/syntax-tree/mdast
284+
285+
[dfn-transparent-content]: https://github.com/syntax-tree/mdast#transparentcontent
286+
287+
[mdast-util-from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown
175288

176-
[to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown
289+
[mdast-util-to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown
177290

178-
[micromark]: https://github.com/micromark/micromark
291+
[mdast-util-gfm]: https://github.com/syntax-tree/mdast-util-gfm
292+
293+
[mdast-util-to-hast]: https://github.com/syntax-tree/mdast-util-to-hast
179294

180295
[extension]: https://github.com/micromark/micromark-extension-gfm-strikethrough
296+
297+
[dfn-parent]: https://github.com/syntax-tree/mdast#parent
298+
299+
[dfn-static-phrasing-content]: #staticphrasingcontent-gfm-strikethrough

0 commit comments

Comments
 (0)