|
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 |
| -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]. |
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-strikethrough`][extension]. |
25 | 47 |
|
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. |
28 | 51 |
|
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][]: |
30 | 56 |
|
31 | 57 | ```sh
|
32 | 58 | npm install mdast-util-gfm-strikethrough
|
33 | 59 | ```
|
34 | 60 |
|
| 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 | + |
35 | 75 | ## Use
|
36 | 76 |
|
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: |
38 | 84 |
|
39 | 85 | ```js
|
| 86 | +import fs from 'node:fs/promises' |
40 | 87 | import {fromMarkdown} from 'mdast-util-from-markdown'
|
41 | 88 | import {toMarkdown} from 'mdast-util-to-markdown'
|
42 | 89 | import {gfmStrikethrough} from 'micromark-extension-gfm-strikethrough'
|
43 | 90 | import {gfmStrikethroughFromMarkdown, gfmStrikethroughToMarkdown} from 'mdast-util-gfm-strikethrough'
|
44 | 91 |
|
45 |
| -const doc = '*Emphasis*, **importance**, and ~~strikethrough~~.' |
| 92 | +const doc = await fs.readFile('example.md') |
46 | 93 |
|
47 | 94 | const tree = fromMarkdown(doc, {
|
48 | 95 | extensions: [gfmStrikethrough()],
|
@@ -83,38 +130,94 @@ Now, running `node example` yields:
|
83 | 130 |
|
84 | 131 | ## API
|
85 | 132 |
|
86 |
| -This package exports the following identifier: `gfmStrikethroughFromMarkdown`, |
| 133 | +This package exports the identifiers `gfmStrikethroughFromMarkdown` and |
87 | 134 | `gfmStrikethroughToMarkdown`.
|
88 | 135 | There is no default export.
|
89 | 136 |
|
90 | 137 | ### `gfmStrikethroughFromMarkdown`
|
91 | 138 |
|
| 139 | +Extension for [`mdast-util-from-markdown`][mdast-util-from-markdown]. |
| 140 | + |
92 | 141 | ### `gfmStrikethroughToMarkdown`
|
93 | 142 |
|
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+. |
98 | 206 |
|
99 | 207 | ## Related
|
100 | 208 |
|
101 |
| -* [`remarkjs/remark`][remark] |
102 |
| - — markdown processor powered by plugins |
103 | 209 | * [`remarkjs/remark-gfm`][remark-gfm]
|
104 | 210 | — 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) |
107 | 214 | * [`micromark/micromark-extension-gfm-strikethrough`][extension]
|
108 | 215 | — 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 |
113 | 216 |
|
114 | 217 | ## Contribute
|
115 | 218 |
|
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. |
118 | 221 | See [`support.md`][support] for ways to get help.
|
119 | 222 |
|
120 | 223 | This project has a [code of conduct][coc].
|
@@ -155,26 +258,42 @@ abide by its terms.
|
155 | 258 |
|
156 | 259 | [npm]: https://docs.npmjs.com/cli/install
|
157 | 260 |
|
| 261 | +[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c |
| 262 | + |
| 263 | +[esmsh]: https://esm.sh |
| 264 | + |
| 265 | +[typescript]: https://www.typescriptlang.org |
| 266 | + |
158 | 267 | [license]: license
|
159 | 268 |
|
160 | 269 | [author]: https://wooorm.com
|
161 | 270 |
|
162 |
| -[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md |
| 271 | +[health]: https://github.com/syntax-tree/.github |
163 | 272 |
|
164 |
| -[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md |
| 273 | +[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md |
165 | 274 |
|
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 |
167 | 276 |
|
168 |
| -[mdast]: https://github.com/syntax-tree/mdast |
| 277 | +[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md |
169 | 278 |
|
170 |
| -[remark]: https://github.com/remarkjs/remark |
| 279 | +[gfm]: https://github.github.com/gfm/ |
171 | 280 |
|
172 | 281 | [remark-gfm]: https://github.com/remarkjs/remark-gfm
|
173 | 282 |
|
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 |
175 | 288 |
|
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 |
177 | 290 |
|
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 |
179 | 294 |
|
180 | 295 | [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