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 in
13
- ** [ mdast] [ ] ** .
14
- When parsing (` from-markdown ` ), must be combined with
15
- [ ` micromark-extension-gfm ` ] [ extension ] .
11
+ [ mdast] [ ] extensions to parse and serialize [ GFM] [ ] (autolink literals,
12
+ footnotes, strikethrough, tables, tasklists).
13
+
14
+ ## Contents
15
+
16
+ * [ What is this?] ( #what-is-this )
17
+ * [ When to use this] ( #when-to-use-this )
18
+ * [ Install] ( #install )
19
+ * [ Use] ( #use )
20
+ * [ API] ( #api )
21
+ * [ ` gfmFromMarkdown() ` ] ( #gfmfrommarkdown )
22
+ * [ ` gfmToMarkdown(options?) ` ] ( #gfmtomarkdownoptions )
23
+ * [ Syntax tree] ( #syntax-tree )
24
+ * [ Types] ( #types )
25
+ * [ Compatibility] ( #compatibility )
26
+ * [ Related] ( #related )
27
+ * [ Contribute] ( #contribute )
28
+ * [ License] ( #license )
29
+
30
+ ## What is this?
31
+
32
+ This package contains extensions for
33
+ [ ` mdast-util-from-markdown ` ] [ mdast-util-from-markdown ] and
34
+ [ ` mdast-util-to-markdown ` ] [ mdast-util-to-markdown ] to enable the features that
35
+ GitHub adds to markdown: autolink literals (` www.x.com ` ), footnotes (` [^1] ` ),
36
+ strikethrough (` ~~stuff~~ ` ), tables (` | cell |… ` ), and tasklists (` * [x] ` ).
16
37
17
38
## When to use this
18
39
19
- Use this if you’re dealing with the AST manually and need all of GFM.
20
- It’s probably nicer to use [ ` remark-gfm ` ] [ remark-gfm ] with
21
- ** [ remark] [ ] ** , which includes this but provides a nicer interface and
22
- makes it easier to combine with hundreds of plugins.
40
+ These tools are all rather low-level.
41
+ In many cases, you’d want to use [ ` remark-gfm ` ] [ remark-gfm ] with remark instead.
42
+
43
+ This project is useful when you want to support the same features that GitHub
44
+ does in files in a repo, Gists, and several other places.
45
+ Users frequently believe that some of these extensions, specifically autolink
46
+ literals and tables, are part of normal markdown, so using ` mdast-util-gfm ` will
47
+ help match your implementation to their understanding of markdown.
48
+ There are several edge cases where GitHub’s implementation works in unexpected
49
+ ways or even different than described in their spec, so * writing* in GFM is not
50
+ always the best choice.
23
51
24
- Alternatively, the extensions can be used separately:
52
+ Instead of this package, you can also use the extensions separately:
25
53
26
54
* [ ` syntax-tree/mdast-util-gfm-autolink-literal ` ] ( https://github.com/syntax-tree/mdast-util-gfm-autolink-literal )
27
55
— support GFM autolink literals
@@ -34,20 +62,44 @@ Alternatively, the extensions can be used separately:
34
62
* [ ` syntax-tree/mdast-util-gfm-task-list-item ` ] ( https://github.com/syntax-tree/mdast-util-gfm-task-list-item )
35
63
— support GFM tasklists
36
64
37
- ## Install
65
+ When working with ` mdast-util-from-markdown ` , you must combine this package with
66
+ [ ` micromark-extension-gfm ` ] [ extension ] .
38
67
39
- This package is [ ESM only] ( https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c ) :
40
- Node 12+ is needed to use it and it must be ` import ` ed instead of ` require ` d.
68
+ A different utility, [ ` mdast-util-frontmatter ` ] [ mdast-util-frontmatter ] , adds
69
+ support for frontmatter.
70
+ GitHub supports YAML frontmatter for files in repos and Gists but they don’t
71
+ treat it as part of GFM.
41
72
42
- [ npm] [ ] :
73
+ This utility does not handle how markdown is turned to HTML.
74
+ That’s done by [ ` mdast-util-to-hast ` ] [ mdast-util-to-hast ] .
75
+ If your content is not in English, you should configure that utility.
76
+
77
+ ## Install
78
+
79
+ This package is [ ESM only] [ esm ] .
80
+ In Node.js (version 12.20+, 14.14+, or 16.0+), install with [ npm] [ ] :
43
81
44
82
``` sh
45
83
npm install mdast-util-gfm
46
84
```
47
85
86
+ In Deno with [ ` esm.sh ` ] [ esmsh ] :
87
+
88
+ ``` js
89
+ import {gfmFromMarkdown , gfmToMarkdown } from ' https://esm.sh/mdast-util-gfm@2'
90
+ ```
91
+
92
+ In browsers with [ ` esm.sh ` ] [ esmsh ] :
93
+
94
+ ``` html
95
+ <script type =" module" >
96
+ import {gfmFromMarkdown , gfmToMarkdown } from ' https://esm.sh/mdast-util-gfm@2?bundle'
97
+ </script >
98
+ ```
99
+
48
100
## Use
49
101
50
- Say we have the following file, ` example.md ` :
102
+ Say our document ` example.md ` contains :
51
103
52
104
``` markdown
53
105
# GFM
@@ -77,16 +129,16 @@ A note[^1]
77
129
* [x] done
78
130
```
79
131
80
- And our module, ` example.js ` , looks as follows:
132
+ …and our module ` example.js ` looks as follows:
81
133
82
134
``` js
83
- import fs from ' node:fs'
135
+ import fs from ' node:fs/promises '
84
136
import {fromMarkdown } from ' mdast-util-from-markdown'
85
137
import {toMarkdown } from ' mdast-util-to-markdown'
86
138
import {gfm } from ' micromark-extension-gfm'
87
139
import {gfmFromMarkdown , gfmToMarkdown } from ' mdast-util-gfm'
88
140
89
- const doc = fs .readFileSync (' example.md' )
141
+ const doc = await fs .readFile (' example.md' )
90
142
91
143
const tree = fromMarkdown (doc, {
92
144
extensions: [gfm ()],
@@ -100,7 +152,7 @@ const out = toMarkdown(tree, {extensions: [gfmToMarkdown()]})
100
152
console .log (out)
101
153
```
102
154
103
- Now, running ` node example ` yields:
155
+ …now running ` node example.js ` yields (positional info removed for brevity) :
104
156
105
157
``` js
106
158
{
@@ -249,43 +301,71 @@ A note[^1]
249
301
250
302
## API
251
303
252
- This package exports the following identifiers: ` gfmFromMarkdown ` ,
253
- ` gfmToMarkdown ` .
304
+ This package exports the identifiers ` gfmFromMarkdown ` and ` gfmToMarkdown ` .
254
305
There is no default export.
255
306
256
307
### ` gfmFromMarkdown() `
257
308
309
+ Function that can be called to get an extension for
310
+ [ ` mdast-util-from-markdown ` ] [ mdast-util-from-markdown ] .
311
+
258
312
### ` gfmToMarkdown(options?) `
259
313
260
- Support GFM.
261
- The export of ` fromMarkdown ` is a function that can be called and returns an
262
- extension for [ ` mdast-util-from-markdown ` ] [ from-markdown ] .
263
- The export of ` toMarkdown ` is a function that can be called with options and
264
- returns an extension for [ ` mdast-util-to-markdown ` ] [ to-markdown ] .
314
+ Function that can be called to get an extension for
315
+ [ ` mdast-util-to-markdown ` ] [ mdast-util-to-markdown ] .
316
+
317
+ ##### ` options `
265
318
266
- ###### ` options `
319
+ Configuration (optional).
320
+ Currently passes through ` tableCellPadding ` , ` tablePipeAlign ` , and
321
+ ` stringLength ` to [ ` mdast-util-gfm-table ` ] [ table ] .
267
322
268
- Passed as ` options ` to [ ` mdast-util-gfm-table ` ] [ table ] .
323
+ ## Syntax tree
324
+
325
+ This utility combines several mdast utilities.
326
+ See their readmes for the node types supported in the tree:
327
+
328
+ * [ ` syntax-tree/mdast-util-gfm-autolink-literal ` ] ( https://github.com/syntax-tree/mdast-util-gfm-autolink-literal#syntax-tree )
329
+ — GFM autolink literals
330
+ * [ ` syntax-tree/mdast-util-gfm-footnote ` ] ( https://github.com/syntax-tree/mdast-util-gfm-footnote#syntax-tree )
331
+ — GFM footnotes
332
+ * [ ` syntax-tree/mdast-util-gfm-strikethrough ` ] ( https://github.com/syntax-tree/mdast-util-gfm-strikethrough#syntax-tree )
333
+ — GFM strikethrough
334
+ * [ ` syntax-tree/mdast-util-gfm-table ` ] ( https://github.com/syntax-tree/mdast-util-gfm-table#syntax-tree )
335
+ — GFM tables
336
+ * [ ` syntax-tree/mdast-util-gfm-task-list-item ` ] ( https://github.com/syntax-tree/mdast-util-gfm-task-list-item#syntax-tree )
337
+ — GFM tasklists
338
+
339
+ ## Types
340
+
341
+ This package is fully typed with [ TypeScript] [ ] .
342
+ It exports an ` Options ` type, which specifies the interface of the accepted
343
+ options.
344
+
345
+ The ` Delete ` , ` FootnoteDefinition ` , ` FootnoteReference ` , ` Table ` , ` TableCell ` ,
346
+ and ` TableRow ` node types are supported in ` @types/mdast ` by default.
347
+
348
+ ## Compatibility
349
+
350
+ Projects maintained by the unified collective are compatible with all maintained
351
+ versions of Node.js.
352
+ As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
353
+ Our projects sometimes work with older versions, but this is not guaranteed.
354
+
355
+ This plugin works with ` mdast-util-from-markdown ` version 1+ and
356
+ ` mdast-util-to-markdown ` version 1+.
269
357
270
358
## Related
271
359
272
- * [ ` remarkjs/remark ` ] [ remark ]
273
- — markdown processor powered by plugins
274
360
* [ ` remarkjs/remark-gfm ` ] [ remark-gfm ]
275
361
— remark plugin to support GFM
276
- * [ ` micromark/micromark ` ] [ micromark ]
277
- — the smallest commonmark-compliant markdown parser that exists
278
362
* [ ` micromark/micromark-extension-gfm ` ] [ extension ]
279
363
— micromark extension to parse GFM
280
- * [ ` syntax-tree/mdast-util-from-markdown ` ] [ from-markdown ]
281
- — mdast parser using ` micromark ` to create mdast from markdown
282
- * [ ` syntax-tree/mdast-util-to-markdown ` ] [ to-markdown ]
283
- — mdast serializer to create markdown from mdast
284
364
285
365
## Contribute
286
366
287
- See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
288
- started.
367
+ See [ ` contributing.md ` ] [ contributing ] in [ ` syntax-tree/.github ` ] [ health ] for
368
+ ways to get started.
289
369
See [ ` support.md ` ] [ support ] for ways to get help.
290
370
291
371
This project has a [ code of conduct] [ coc ] .
@@ -326,28 +406,38 @@ abide by its terms.
326
406
327
407
[ npm ] : https://docs.npmjs.com/cli/install
328
408
409
+ [ esm ] : https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
410
+
411
+ [ esmsh ] : https://esm.sh
412
+
413
+ [ typescript ] : https://www.typescriptlang.org
414
+
329
415
[ license ] : license
330
416
331
417
[ author ] : https://wooorm.com
332
418
333
- [ contributing ] : https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
419
+ [ health ] : https://github.com/syntax-tree/.github
334
420
335
- [ support ] : https://github.com/syntax-tree/.github/blob/HEAD/support .md
421
+ [ contributing ] : https://github.com/syntax-tree/.github/blob/main/contributing .md
336
422
337
- [ coc ] : https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct .md
423
+ [ support ] : https://github.com/syntax-tree/.github/blob/main/support .md
338
424
339
- [ mdast ] : https://github.com/syntax-tree/mdast
425
+ [ coc ] : https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
340
426
341
- [ remark ] : https://github.com/remarkjs/remark
427
+ [ mdast ] : https://github.com/syntax-tree/mdast
342
428
343
429
[ remark-gfm ] : https://github.com/remarkjs/remark-gfm
344
430
345
- [ from-markdown ] : https://github.com/syntax-tree/mdast-util-from-markdown
431
+ [ mdast-util-from-markdown ] : https://github.com/syntax-tree/mdast-util-from-markdown
432
+
433
+ [ mdast-util-to-markdown ] : https://github.com/syntax-tree/mdast-util-to-markdown
346
434
347
- [ to-markdown ] : https://github.com/syntax-tree/mdast-util-to-markdown
435
+ [ mdast-util-frontmatter ] : https://github.com/syntax-tree/mdast-util-frontmatter
348
436
349
- [ micromark ] : https://github.com/micromark/micromark
437
+ [ mdast-util-to-hast ] : https://github.com/syntax-tree/mdast-util-to-hast
350
438
351
439
[ extension ] : https://github.com/micromark/micromark-extension-gfm
352
440
353
441
[ table ] : https://github.com/syntax-tree/mdast-util-gfm-table#options
442
+
443
+ [ gfm ] : https://github.github.com/gfm/
0 commit comments