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- (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 ] .
2340
2441## When to use this
2542
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 .
2845
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.
3055
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
3357
34- [ npm] [ ] :
58+ This package is [ ESM only] [ esm ] .
59+ In Node.js (version 12.20+, 14.14+, or 16.0+), install with [ npm] [ ] :
3560
3661``` sh
3762npm install mdast-util-gfm-footnote
3863```
3964
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+
4079## Use
4180
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:
4390
4491``` js
92+ import fs from ' node:fs/promises'
4593import {fromMarkdown } from ' mdast-util-from-markdown'
4694import {toMarkdown } from ' mdast-util-to-markdown'
4795import {gfmFootnote } from ' micromark-extension-gfm-footnote'
4896import {gfmFootnoteFromMarkdown , gfmFootnoteToMarkdown } from ' mdast-util-gfm-footnote'
4997
50- const doc = ' Hi![^1] \n\n [^1]: big note '
98+ const doc = await fs . readFile ( ' example.md ' )
5199
52100const tree = fromMarkdown (doc, {
53101 extensions: [gfmFootnote ()],
@@ -61,7 +109,7 @@ const out = toMarkdown(tree, {extensions: [gfmFootnoteToMarkdown()]})
61109console .log (out)
62110```
63111
64- Now, running ` node example ` yields:
112+ …now running ` node example.js ` yields (positional info removed for brevity) :
65113
66114``` js
67115{
@@ -94,34 +142,155 @@ Hi\![^1]
94142
95143## API
96144
145+ This package exports the identifiers ` gfmFootnoteFromMarkdown ` and
146+ ` gfmFootnoteToMarkdown ` .
147+ There is no default export.
148+
97149### ` gfmFootnoteFromMarkdown() `
98150
151+ Function that can be called to get an extension for
152+ [ ` mdast-util-from-markdown ` ] [ mdast-util-from-markdown ] .
153+
99154### ` gfmFootnoteToMarkdown() `
100155
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+.
105279
106280## Related
107281
108- * [ ` remarkjs/remark ` ] [ remark ]
109- — markdown processor powered by plugins
110282* [ ` remarkjs/remark-gfm ` ] [ remark-gfm ]
111283 — 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)
114287* [ ` micromark/micromark-extension-gfm-footnote ` ] [ extension ]
115288 — 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
120289
121290## Contribute
122291
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.
125294See [ ` support.md ` ] [ support ] for ways to get help.
126295
127296This project has a [ code of conduct] [ coc ] .
@@ -162,30 +331,54 @@ abide by its terms.
162331
163332[ npm ] : https://docs.npmjs.com/cli/install
164333
334+ [ esm ] : https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
335+
336+ [ esmsh ] : https://esm.sh
337+
338+ [ typescript ] : https://www.typescriptlang.org
339+
165340[ license ] : license
166341
167342[ author ] : https://wooorm.com
168343
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
170347
171- [ support ] : https://github.com/syntax-tree/.github/blob/HEAD /support.md
348+ [ support ] : https://github.com/syntax-tree/.github/blob/main /support.md
172349
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
174351
175352[ mdast ] : https://github.com/syntax-tree/mdast
176353
177354[ mdast-util-gfm ] : https://github.com/syntax-tree/mdast-util-gfm
178355
179- [ remark ] : https://github.com/remarkjs/remark
180-
181356[ remark-gfm ] : https://github.com/remarkjs/remark-gfm
182357
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
186359
187- [ micromark ] : https://github.com/micromark/micromark
360+ [ gfm ] : https://github.github. com/gfm/
188361
189- [ extension ] : https://github.com/micromark/micromark-extension- gfm-footnote
362+ [ cmark-gfm ] : https://github.com/github/cmark- gfm
190363
191364[ 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