Extension for mdast-util-from-markdown and/or mdast-util-to-markdown to support GitHub flavored markdown (GFM) footnotes in mdast. When parsing (from-markdown), must be combined with micromark-extension-gfm-footnote.
GFM footnotes were announced September 30, 2021 but are neither specified nor supported in all their products (e.g., Gists). Their implementation on github.com is currently quite buggy. The bugs have been reported on cmark-gfm. This micromark extension matches github.com except for its bugs.
Use mdast-util-gfm if you want all of GFM. Use this otherwise.
This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.
npm:
npm install mdast-util-gfm-footnoteSay our module, example.js, looks as follows:
import {fromMarkdown} from 'mdast-util-from-markdown' import {toMarkdown} from 'mdast-util-to-markdown' import {gfmFootnote} from 'micromark-extension-gfm-footnote' import {gfmFootnoteFromMarkdown, gfmFootnoteToMarkdown} from 'mdast-util-gfm-footnote' const doc = 'Hi![^1]\n\n[^1]: big note' const tree = fromMarkdown(doc, { extensions: [gfmFootnote()], mdastExtensions: [gfmFootnoteFromMarkdown()] }) console.log(tree) const out = toMarkdown(tree, {extensions: [gfmFootnoteToMarkdown()]}) console.log(out)Now, running node example yields:
{ type: 'root', children: [ { type: 'paragraph', children: [ {type: 'text', value: 'Hi!'}, {type: 'footnoteReference', identifier: '1', label: '1'} ] }, { type: 'footnoteDefinition', identifier: '1', label: '1', children: [ {type: 'paragraph', children: [{type: 'text', value: 'big note'}]} ] } ] }Hi\![^1] [^1]: big noteSupport footnotes. The exports are functions that can be called to get extensions, respectively for mdast-util-from-markdown and mdast-util-to-markdown.
remarkjs/remark— markdown processor powered by pluginsremarkjs/remark-gfm— remark plugin to support GFMmicromark/micromark— the smallest commonmark-compliant markdown parser that existsmicromark/micromark-extension-gfm-footnote— micromark extension to parse GFM footnotessyntax-tree/mdast-util-from-markdown— mdast parser usingmicromarkto create mdast from markdownsyntax-tree/mdast-util-to-markdown— mdast serializer to create markdown from mdast
See contributing.md in syntax-tree/.github for ways to get started. See support.md for ways to get help.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.