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
- (GFM) footnotes in ** [ mdast] [ ] ** .
14
- When parsing (` from-markdown ` ), must be combined with
15
- [ ` micromark-extension-gfm-footnote ` ] [ extension ] .
16
-
17
- GFM footnotes were [ announced September 30, 2021] [ post ] but are neither
18
- specified nor supported in all their products (e.g., Gists).
19
- Their implementation on github.com is currently quite buggy.
20
- The bugs have been reported on
21
- [ ` cmark-gfm ` ] ( https://github.com/github/cmark-gfm ) .
22
- This micromark extension matches github.com except for its bugs.
11
+ [ mdast] [ ] extensions to parse and serialize [ GFM] [ ] footnotes.
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
+ * [ ` gfmFootnoteFromMarkdown() ` ] ( #gfmfootnotefrommarkdown )
21
+ * [ ` gfmFootnoteToMarkdown() ` ] ( #gfmfootnotetomarkdown )
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 footnote syntax
34
+ enabled by GFM to [ ` mdast-util-from-markdown ` ] [ mdast-util-from-markdown ] and
35
+ [ ` mdast-util-to-markdown ` ] [ mdast-util-to-markdown ] .
36
+
37
+ GFM footnotes were [ announced September 30, 2021] [ post ] but are not specified.
38
+ Their implementation on github.com is currently buggy.
39
+ The bugs have been reported on [ ` cmark-gfm ` ] [ cmark-gfm ] .
23
40
24
41
## When to use this
25
42
26
- Use [ ` mdast-util-gfm ` ] [ mdast-util-gfm ] if you want all of GFM .
27
- Use this otherwise .
43
+ These tools are all rather low-level .
44
+ In most cases, you’d want to use [ ` remark-gfm ` ] [ remark-gfm ] with remark instead .
28
45
29
- ## Install
46
+ When you are working with syntax trees and want all of GFM, use
47
+ [ ` mdast-util-gfm ` ] [ mdast-util-gfm ] instead.
48
+
49
+ When working with ` mdast-util-from-markdown ` , you must combine this package with
50
+ [ ` micromark-extension-gfm ` ] [ extension ] .
51
+
52
+ This utility does not handle how markdown is turned to HTML.
53
+ That’s done by [ ` mdast-util-to-hast ` ] [ mdast-util-to-hast ] .
54
+ If your content is not in English, you should configure that utility.
30
55
31
- This package is [ ESM only] ( https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c ) :
32
- Node 12+ is needed to use it and it must be ` import ` ed instead of ` require ` d.
56
+ ## Install
33
57
34
- [ npm] [ ] :
58
+ This package is [ ESM only] [ esm ] .
59
+ In Node.js (version 12.20+, 14.14+, or 16.0+), install with [ npm] [ ] :
35
60
36
61
``` sh
37
62
npm install mdast-util-gfm-footnote
38
63
```
39
64
65
+ In Deno with [ ` esm.sh ` ] [ esmsh ] :
66
+
67
+ ``` js
68
+ import {gfmFootnoteFromMarkdown , gfmFootnoteToMarkdown } from ' https://esm.sh/mdast-util-gfm-footnote@1'
69
+ ```
70
+
71
+ In browsers with [ ` esm.sh ` ] [ esmsh ] :
72
+
73
+ ``` html
74
+ <script type =" module" >
75
+ import {gfmFootnoteFromMarkdown , gfmFootnoteToMarkdown } from ' https://esm.sh/mdast-util-gfm-footnote@1?bundle'
76
+ </script >
77
+ ```
78
+
40
79
## Use
41
80
42
- Say our module, ` example.js ` , looks as follows:
81
+ Say our document ` example.md ` contains:
82
+
83
+ ``` markdown
84
+ Hi![^1]
85
+
86
+ [^1]: big note
87
+ ```
88
+
89
+ …and our module ` example.js ` looks as follows:
43
90
44
91
``` js
92
+ import fs from ' node:fs/promises'
45
93
import {fromMarkdown } from ' mdast-util-from-markdown'
46
94
import {toMarkdown } from ' mdast-util-to-markdown'
47
95
import {gfmFootnote } from ' micromark-extension-gfm-footnote'
48
96
import {gfmFootnoteFromMarkdown , gfmFootnoteToMarkdown } from ' mdast-util-gfm-footnote'
49
97
50
- const doc = ' Hi![^1] \n\n [^1]: big note '
98
+ const doc = await fs . readFile ( ' example.md ' )
51
99
52
100
const tree = fromMarkdown (doc, {
53
101
extensions: [gfmFootnote ()],
@@ -61,7 +109,7 @@ const out = toMarkdown(tree, {extensions: [gfmFootnoteToMarkdown()]})
61
109
console .log (out)
62
110
```
63
111
64
- Now, running ` node example ` yields:
112
+ …now running ` node example.js ` yields (positional info removed for brevity) :
65
113
66
114
``` js
67
115
{
@@ -94,34 +142,155 @@ Hi\![^1]
94
142
95
143
## API
96
144
145
+ This package exports the identifiers ` gfmFootnoteFromMarkdown ` and
146
+ ` gfmFootnoteToMarkdown ` .
147
+ There is no default export.
148
+
97
149
### ` gfmFootnoteFromMarkdown() `
98
150
151
+ Function that can be called to get an extension for
152
+ [ ` mdast-util-from-markdown ` ] [ mdast-util-from-markdown ] .
153
+
99
154
### ` gfmFootnoteToMarkdown() `
100
155
101
- Support footnotes.
102
- The exports are functions that can be called to get extensions, respectively
103
- for [ ` mdast-util-from-markdown ` ] [ from-markdown ] and
104
- [ ` mdast-util-to-markdown ` ] [ to-markdown ] .
156
+ Function that can be called to get an extension for
157
+ [ ` mdast-util-to-markdown ` ] [ mdast-util-to-markdown ] .
158
+
159
+ ## Syntax tree
160
+
161
+ The following interfaces are added to ** [ mdast] [ ] ** by this utility.
162
+
163
+ ### Nodes
164
+
165
+ #### ` FootnoteDefinition `
166
+
167
+ ``` idl
168
+ interface FootnoteDefinition <: Parent {
169
+ type: "footnoteDefinition"
170
+ children: [FlowContent]
171
+ }
172
+
173
+ FootnoteDefinition includes Association
174
+ ```
175
+
176
+ ** FootnoteDefinition** ([ ** Parent** ] [ dfn-parent ] ) represents content relating
177
+ to the document that is outside its flow.
178
+
179
+ ** FootnoteDefinition** can be used where [ ** flow** ] [ dfn-flow-content ] content is
180
+ expected.
181
+ Its content model is also [ ** flow** ] [ dfn-flow-content ] content.
182
+
183
+ ** FootnoteDefinition** includes the mixin
184
+ [ ** Association** ] [ dfn-mxn-association ] .
185
+
186
+ ** FootnoteDefinition** should be associated with
187
+ [ ** FootnoteReferences** ] [ dfn-footnote-reference ] .
188
+
189
+ For example, the following markdown:
190
+
191
+ ``` markdown
192
+ [^alpha]: bravo and charlie.
193
+ ```
194
+
195
+ Yields:
196
+
197
+ ``` js
198
+ {
199
+ type: ' footnoteDefinition' ,
200
+ identifier: ' alpha' ,
201
+ label: ' alpha' ,
202
+ children: [{
203
+ type: ' paragraph' ,
204
+ children: [{type: ' text' , value: ' bravo and charlie.' }]
205
+ }]
206
+ }
207
+ ```
208
+
209
+ #### ` FootnoteReference `
210
+
211
+ ``` idl
212
+ interface FootnoteReference <: Node {
213
+ type: "footnoteReference"
214
+ }
215
+
216
+ FootnoteReference includes Association
217
+ ```
218
+
219
+ ** FootnoteReference** ([ ** Node** ] [ dfn-node ] ) represents a marker through
220
+ association.
221
+
222
+ ** FootnoteReference** can be used where
223
+ [ ** static phrasing** ] [ dfn-static-phrasing-content ] content is expected.
224
+ It has no content model.
225
+
226
+ ** FootnoteReference** includes the mixin [ ** Association** ] [ dfn-mxn-association ] .
227
+
228
+ ** FootnoteReference** should be associated with a
229
+ [ ** FootnoteDefinition** ] [ dfn-footnote-definition ] .
230
+
231
+ For example, the following markdown:
232
+
233
+ ``` markdown
234
+ [^alpha]
235
+ ```
236
+
237
+ Yields:
238
+
239
+ ``` js
240
+ {
241
+ type: ' footnoteReference' ,
242
+ identifier: ' alpha' ,
243
+ label: ' alpha'
244
+ }
245
+ ```
246
+
247
+ ### Content model
248
+
249
+ #### ` FlowContent ` (GFM footnotes)
250
+
251
+ ``` idl
252
+ type FlowContentGfm = FootnoteDefinition | FlowContent
253
+ ```
254
+
255
+ #### ` StaticPhrasingContent ` (GFM footnotes)
256
+
257
+ ``` idl
258
+ type StaticPhrasingContentGfm =
259
+ FootnoteReference | StaticPhrasingContent
260
+ ```
261
+
262
+ ## Types
263
+
264
+ This package is fully typed with [ TypeScript] [ ] .
265
+ It does not export additional types.
266
+
267
+ The ` FootnoteDefinition ` and ` FootnoteReference ` node types are supported in
268
+ ` @types/mdast ` by default.
269
+
270
+ ## Compatibility
271
+
272
+ Projects maintained by the unified collective are compatible with all maintained
273
+ versions of Node.js.
274
+ As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
275
+ Our projects sometimes work with older versions, but this is not guaranteed.
276
+
277
+ This plugin works with ` mdast-util-from-markdown ` version 1+ and
278
+ ` mdast-util-to-markdown ` version 1+.
105
279
106
280
## Related
107
281
108
- * [ ` remarkjs/remark ` ] [ remark ]
109
- — markdown processor powered by plugins
110
282
* [ ` remarkjs/remark-gfm ` ] [ remark-gfm ]
111
283
— remark plugin to support GFM
112
- * [ ` micromark/micromark ` ] [ micromark ]
113
- — the smallest commonmark-compliant markdown parser that exists
284
+ * [ ` syntax-tree/mdast-util-gfm ` ] [ mdast-util-gfm ]
285
+ — same but all of GFM (autolink literals, footnotes, strikethrough, tables,
286
+ tasklists)
114
287
* [ ` micromark/micromark-extension-gfm-footnote ` ] [ extension ]
115
288
— micromark extension to parse GFM footnotes
116
- * [ ` syntax-tree/mdast-util-from-markdown ` ] [ from-markdown ]
117
- — mdast parser using ` micromark ` to create mdast from markdown
118
- * [ ` syntax-tree/mdast-util-to-markdown ` ] [ to-markdown ]
119
- — mdast serializer to create markdown from mdast
120
289
121
290
## Contribute
122
291
123
- See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
124
- started.
292
+ See [ ` contributing.md ` ] [ contributing ] in [ ` syntax-tree/.github ` ] [ health ] for
293
+ ways to get started.
125
294
See [ ` support.md ` ] [ support ] for ways to get help.
126
295
127
296
This project has a [ code of conduct] [ coc ] .
@@ -162,30 +331,54 @@ abide by its terms.
162
331
163
332
[ npm ] : https://docs.npmjs.com/cli/install
164
333
334
+ [ esm ] : https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
335
+
336
+ [ esmsh ] : https://esm.sh
337
+
338
+ [ typescript ] : https://www.typescriptlang.org
339
+
165
340
[ license ] : license
166
341
167
342
[ author ] : https://wooorm.com
168
343
169
- [ contributing ] : https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
344
+ [ health ] : https://github.com/syntax-tree/.github
345
+
346
+ [ contributing ] : https://github.com/syntax-tree/.github/blob/main/contributing.md
170
347
171
- [ support ] : https://github.com/syntax-tree/.github/blob/HEAD /support.md
348
+ [ support ] : https://github.com/syntax-tree/.github/blob/main /support.md
172
349
173
- [ coc ] : https://github.com/syntax-tree/.github/blob/HEAD /code-of-conduct.md
350
+ [ coc ] : https://github.com/syntax-tree/.github/blob/main /code-of-conduct.md
174
351
175
352
[ mdast ] : https://github.com/syntax-tree/mdast
176
353
177
354
[ mdast-util-gfm ] : https://github.com/syntax-tree/mdast-util-gfm
178
355
179
- [ remark ] : https://github.com/remarkjs/remark
180
-
181
356
[ remark-gfm ] : https://github.com/remarkjs/remark-gfm
182
357
183
- [ from-markdown ] : https://github.com/syntax-tree/mdast-util-from-markdown
184
-
185
- [ to-markdown ] : https://github.com/syntax-tree/mdast-util-to-markdown
358
+ [ extension ] : https://github.com/micromark/micromark-extension-gfm-footnote
186
359
187
- [ micromark ] : https://github.com/micromark/micromark
360
+ [ gfm ] : https://github.github. com/gfm/
188
361
189
- [ extension ] : https://github.com/micromark/micromark-extension- gfm-footnote
362
+ [ cmark-gfm ] : https://github.com/github/cmark- gfm
190
363
191
364
[ post ] : https://github.blog/changelog/2021-09-30-footnotes-now-supported-in-markdown-fields/
365
+
366
+ [ mdast-util-from-markdown ] : https://github.com/syntax-tree/mdast-util-from-markdown
367
+
368
+ [ mdast-util-to-markdown ] : https://github.com/syntax-tree/mdast-util-to-markdown
369
+
370
+ [ mdast-util-to-hast ] : https://github.com/syntax-tree/mdast-util-to-hast
371
+
372
+ [ dfn-parent ] : https://github.com/syntax-tree/mdast#parent
373
+
374
+ [ dfn-mxn-association ] : https://github.com/syntax-tree/mdast#association
375
+
376
+ [ dfn-node ] : https://github.com/syntax-tree/unist#node
377
+
378
+ [ dfn-flow-content ] : #flowcontent-gfm-footnotes
379
+
380
+ [ dfn-static-phrasing-content ] : #staticphrasingcontent-gfm-footnotes
381
+
382
+ [ dfn-footnote-reference ] : #footnotereference
383
+
384
+ [ dfn-footnote-definition ] : #footnotedefinition
0 commit comments