Ninety Percent Muffin

    mdast-util-gfm-footnote
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.1 • Public • Published

    mdast-util-gfm-footnote

    Build Coverage Downloads Size Sponsors Backers Chat

    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.

    When to use this

    Use mdast-util-gfm if you want all of GFM. Use this otherwise.

    Install

    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-footnote

    Use

    Say 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 note

    API

    gfmFootnoteFromMarkdown()

    gfmFootnoteToMarkdown()

    Support footnotes. The exports are functions that can be called to get extensions, respectively for mdast-util-from-markdown and mdast-util-to-markdown.

    Related

    Contribute

    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.

    License

    MIT © Titus Wormer

    Install

    npm i mdast-util-gfm-footnote

    DownloadsWeekly Downloads

    230,555

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    14.3 kB

    Total Files

    5

    Last publish

    Collaborators

    • wooorm
    • kmck