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
- autolink literals in ** [ mdast] [ ] ** .
14
- When parsing (` from-markdown ` ), must be combined with
15
- [ ` micromark-extension-gfm-autolink-literal ` ] [ extension ] .
11
+ [ mdast] [ ] extensions to parse and serialize [ GFM] [ ] autolinks.
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
+ * [ ` gfmAutolinkLiteralFromMarkdown ` ] ( #gfmautolinkliteralfrommarkdown )
21
+ * [ ` gfmAutolinkLiteralToMarkdown ` ] ( #gfmautolinkliteraltomarkdown )
22
+ * [ Syntax tree] ( #syntax-tree )
23
+ * [ Types] ( #types )
24
+ * [ Compatibility] ( #compatibility )
25
+ * [ Related] ( #related )
26
+ * [ Contribute] ( #contribute )
27
+ * [ License] ( #license )
28
+
29
+ ## What is this?
30
+
31
+ This package contains extensions that add support for the autolink syntax
32
+ enabled by GFM to [ ` mdast-util-from-markdown ` ] [ mdast-util-from-markdown ] and
33
+ [ ` mdast-util-to-markdown ` ] [ mdast-util-to-markdown ] .
34
+
35
+ GitHub employs different algorithms to autolink: one at parse time and one at
36
+ transform time (similar to how @mentions are done at transform time).
37
+ This difference can be observed because character references and escapes are
38
+ handled differently.
39
+ But also because issues/PRs/comments omit (perhaps by accident?) the second
40
+ algorithm for ` www. ` , ` http:// ` , and ` https:// ` links (but not for email links).
41
+
42
+ As the corresponding micromark extension
43
+ [ ` micromark-extension-gfm-autolink-literal ` ] [ extension ] is a syntax extension,
44
+ it can only perform the first algorithm.
45
+ The tree extension ` gfmAutolinkLiteralFromMarkdown ` from this package can
46
+ perform the second algorithm, and as they are combined, both are done.
16
47
17
48
## When to use this
18
49
19
- Use [ ` mdast-util-gfm ` ] [ mdast-util-gfm ] if you want all of GFM .
20
- Use this otherwise .
50
+ These tools are all rather low-level .
51
+ In most cases, you’d want to use [ ` remark-gfm ` ] [ remark-gfm ] with remark instead .
21
52
22
- ## Install
53
+ When you are working with syntax trees and want all of GFM, use
54
+ [ ` mdast-util-gfm ` ] [ mdast-util-gfm ] instead.
23
55
24
- This package is [ ESM only ] ( https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c ) :
25
- Node 12+ is needed to use it and it must be ` import ` ed instead of ` require ` d .
56
+ When working with ` mdast-util-from-markdown ` , you must combine this package with
57
+ [ ` micromark-extension-gfm-autolink-literal ` ] [ extension ] .
26
58
27
- [ npm] [ ] :
59
+ This utility does not handle how markdown is turned to HTML.
60
+ That’s done by [ ` mdast-util-to-hast ` ] [ mdast-util-to-hast ] .
61
+
62
+ ## Install
63
+
64
+ This package is [ ESM only] [ esm ] .
65
+ In Node.js (version 12.20+, 14.14+, or 16.0+), install with [ npm] [ ] :
28
66
29
67
``` sh
30
68
npm install mdast-util-gfm-autolink-literal
31
69
```
32
70
71
+ In Deno with [ ` esm.sh ` ] [ esmsh ] :
72
+
73
+ ``` js
74
+ import {gfmAutolinkLiteralFromMarkdown , gfmAutolinkLiteralToMarkdown } from ' https://esm.sh/mdast-util-gfm-autolink-literal@1'
75
+ ```
76
+
77
+ In browsers with [ ` esm.sh ` ] [ esmsh ] :
78
+
79
+ ``` html
80
+ <script type =" module" >
81
+ import {gfmAutolinkLiteralFromMarkdown , gfmAutolinkLiteralToMarkdown } from ' https://esm.sh/mdast-util-gfm-autolink-literal@1?bundle'
82
+ </script >
83
+ ```
84
+
33
85
## Use
34
86
35
- Say our module, ` example.js ` , looks as follows:
87
+ Say our document ` example.md ` contains:
88
+
89
+ ``` markdown
90
+ www.example.com, https://example.com, and
[email protected] .
91
+ ```
92
+
93
+ …and our module ` example.js ` looks as follows:
36
94
37
95
``` js
96
+ import fs from ' node:fs/promises'
38
97
import {fromMarkdown } from ' mdast-util-from-markdown'
39
98
import {toMarkdown } from ' mdast-util-to-markdown'
40
99
import {gfmAutolinkLiteral } from ' micromark-extension-gfm-autolink-literal'
41
100
import {gfmAutolinkLiteralFromMarkdown , gfmAutolinkLiteralToMarkdown } from ' mdast-util-gfm-autolink-literal'
42
101
43
- const doc = ' www.example.com, https://example.com, and contact@ example.com. '
102
+ const doc = await fs . readFile ( ' example.md ' )
44
103
45
104
const tree = fromMarkdown (doc, {
46
105
extensions: [gfmAutolinkLiteral],
@@ -54,7 +113,7 @@ const out = toMarkdown(tree, {extensions: [gfmAutolinkLiteralToMarkdown]})
54
113
console .log (out)
55
114
```
56
115
57
- Now, running ` node example ` yields:
116
+ …now running ` node example.js ` yields (positional info removed for brevity) :
58
117
59
118
``` js
60
119
{
@@ -96,34 +155,54 @@ Now, running `node example` yields:
96
155
97
156
## API
98
157
158
+ This package exports the identifiers ` gfmAutolinkLiteralFromMarkdown ` and
159
+ ` gfmAutolinkLiteralToMarkdown ` .
160
+ There is no default export.
161
+
99
162
### ` gfmAutolinkLiteralFromMarkdown `
100
163
164
+ Extension for [ ` mdast-util-from-markdown ` ] [ mdast-util-from-markdown ] .
165
+
101
166
### ` gfmAutolinkLiteralToMarkdown `
102
167
103
- Support literal autolinks.
104
- The exports are extensions, respectively
105
- for [ ` mdast-util-from-markdown ` ] [ from-markdown ] and
106
- [ ` mdast-util-to-markdown ` ] [ to-markdown ] .
168
+ Extension for [ ` mdast-util-to-markdown ` ] [ mdast-util-to-markdown ] .
169
+
170
+ ## Syntax tree
171
+
172
+ There are no interfaces added to ** [ mdast] [ ] ** by this utility, as it reuses
173
+ the existing [ ** Link** ] [ dfn-link ] interface.
174
+
175
+ ## Types
176
+
177
+ This package is fully typed with [ TypeScript] [ ] .
178
+ It does not export additional types.
179
+
180
+ The ` Link ` node type is supported in ` @types/mdast ` by default.
181
+
182
+ ## Compatibility
183
+
184
+ Projects maintained by the unified collective are compatible with all maintained
185
+ versions of Node.js.
186
+ As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
187
+ Our projects sometimes work with older versions, but this is not guaranteed.
188
+
189
+ This plugin works with ` mdast-util-from-markdown ` version 1+ and
190
+ ` mdast-util-to-markdown ` version 1+.
107
191
108
192
## Related
109
193
110
- * [ ` remarkjs/remark ` ] [ remark ]
111
- — markdown processor powered by plugins
112
194
* [ ` remarkjs/remark-gfm ` ] [ remark-gfm ]
113
195
— remark plugin to support GFM
114
- * [ ` micromark/micromark ` ] [ micromark ]
115
- — the smallest commonmark-compliant markdown parser that exists
196
+ * [ ` syntax-tree/mdast-util-gfm ` ] [ mdast-util-gfm ]
197
+ — same but all of GFM (autolink literals, footnotes, strikethrough, tables,
198
+ tasklists)
116
199
* [ ` micromark/micromark-extension-gfm-autolink-literal ` ] [ extension ]
117
200
— micromark extension to parse GFM autolink literals
118
- * [ ` syntax-tree/mdast-util-from-markdown ` ] [ from-markdown ]
119
- — mdast parser using ` micromark ` to create mdast from markdown
120
- * [ ` syntax-tree/mdast-util-to-markdown ` ] [ to-markdown ]
121
- — mdast serializer to create markdown from mdast
122
201
123
202
## Contribute
124
203
125
- See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
126
- started.
204
+ See [ ` contributing.md ` ] [ contributing ] in [ ` syntax-tree/.github ` ] [ health ] for
205
+ ways to get started.
127
206
See [ ` support.md ` ] [ support ] for ways to get help.
128
207
129
208
This project has a [ code of conduct] [ coc ] .
@@ -164,10 +243,18 @@ abide by its terms.
164
243
165
244
[ npm ] : https://docs.npmjs.com/cli/install
166
245
246
+ [ esm ] : https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
247
+
248
+ [ esmsh ] : https://esm.sh
249
+
250
+ [ typescript ] : https://www.typescriptlang.org
251
+
167
252
[ license ] : license
168
253
169
254
[ author ] : https://wooorm.com
170
255
256
+ [ health ] : https://github.com/syntax-tree/.github
257
+
171
258
[ contributing ] : https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
172
259
173
260
[ support ] : https://github.com/syntax-tree/.github/blob/HEAD/support.md
@@ -178,14 +265,16 @@ abide by its terms.
178
265
179
266
[ mdast-util-gfm ] : https://github.com/syntax-tree/mdast-util-gfm
180
267
181
- [ remark ] : https://github.com/remarkjs/remark
268
+ [ mdast-util-from-markdown ] : https://github.com/syntax-tree/mdast-util-from-markdown
182
269
183
- [ remark-gfm ] : https://github.com/remarkjs/remark-gfm
270
+ [ mdast-util-to-markdown ] : https://github.com/syntax-tree/mdast-util-to-markdown
184
271
185
- [ from-markdown ] : https://github.com/syntax-tree/mdast-util-from-markdown
272
+ [ mdast-util-to-hast ] : https://github.com/syntax-tree/mdast-util-to-hast
186
273
187
- [ to-markdown ] : https://github.com/syntax-tree/mdast-util-to-markdown
188
-
189
- [ micromark ] : https://github.com/micromark/micromark
274
+ [ remark-gfm ] : https://github.com/remarkjs/remark-gfm
190
275
191
276
[ extension ] : https://github.com/micromark/micromark-extension-gfm-autolink-literal
277
+
278
+ [ gfm ] : https://github.github.com/gfm/
279
+
280
+ [ dfn-link ] : https://github.com/syntax-tree/mdast#link
0 commit comments