{"id":29125788,"url":"https://github.com/syntax-tree/mdast-util-gfm-footnote","last_synced_at":"2025-06-29T22:03:56.940Z","repository":{"id":57293488,"uuid":"413026830","full_name":"syntax-tree/mdast-util-gfm-footnote","owner":"syntax-tree","description":"mdast extension to parse and serialize GFM footnotes","archived":false,"fork":false,"pushed_at":"2025-02-10T11:52:20.000Z","size":89,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-05-21T18:21:36.023Z","etag":null,"topics":["footnote","gfm","mdast","mdast-util"],"latest_commit_sha":null,"homepage":"https://unifiedjs.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/syntax-tree.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"unifiedjs","open_collective":"unified"}},"created_at":"2021-10-03T09:03:37.000Z","updated_at":"2025-02-10T11:52:20.000Z","dependencies_parsed_at":"2024-06-18T20:00:08.055Z","dependency_job_id":"c79cc04d-6279-4734-894f-cbab0ceb10d8","html_url":"https://github.com/syntax-tree/mdast-util-gfm-footnote","commit_stats":{"total_commits":32,"total_committers":1,"mean_commits":32.0,"dds":0.0,"last_synced_commit":"d6826c6addd639dd09abc8529fa4283f67eecc31"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/syntax-tree/mdast-util-gfm-footnote","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fmdast-util-gfm-footnote","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fmdast-util-gfm-footnote/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fmdast-util-gfm-footnote/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fmdast-util-gfm-footnote/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syntax-tree","download_url":"https://codeload.github.com/syntax-tree/mdast-util-gfm-footnote/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fmdast-util-gfm-footnote/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261492000,"owners_count":23166684,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["footnote","gfm","mdast","mdast-util"],"created_at":"2025-06-29T22:03:51.732Z","updated_at":"2025-06-29T22:03:56.918Z","avatar_url":"https://github.com/syntax-tree.png","language":"JavaScript","funding_links":["https://github.com/sponsors/unifiedjs","https://opencollective.com/unified"],"categories":[],"sub_categories":[],"readme":"# mdast-util-gfm-footnote\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n[![Sponsors][sponsors-badge]][collective]\n[![Backers][backers-badge]][collective]\n[![Chat][chat-badge]][chat]\n\n[mdast][] extensions to parse and serialize [GFM][] footnotes.\n\n## Contents\n\n* [What is this?](#what-is-this)\n* [When to use this](#when-to-use-this)\n* [Install](#install)\n* [Use](#use)\n* [API](#api)\n  * [`gfmFootnoteFromMarkdown()`](#gfmfootnotefrommarkdown)\n  * [`gfmFootnoteToMarkdown(options?)`](#gfmfootnotetomarkdownoptions)\n  * [`ToMarkdownOptions`](#tomarkdownoptions)\n* [HTML](#html)\n* [Syntax](#syntax)\n* [Syntax tree](#syntax-tree)\n  * [Nodes](#nodes)\n  * [Content model](#content-model)\n* [Types](#types)\n* [Compatibility](#compatibility)\n* [Related](#related)\n* [Contribute](#contribute)\n* [License](#license)\n\n## What is this?\n\nThis package contains two extensions that add support for GFM footnote syntax\nin markdown to [mdast][].\nThese extensions plug into\n[`mdast-util-from-markdown`][mdast-util-from-markdown] (to support parsing\nfootnotes in markdown into a syntax tree) and\n[`mdast-util-to-markdown`][mdast-util-to-markdown] (to support serializing\nfootnotes in syntax trees to markdown).\n\nGFM footnotes were [announced September 30, 2021][post] but are not specified.\nTheir implementation on github.com is currently buggy.\nThe bugs have been reported on [`cmark-gfm`][cmark-gfm].\n\n## When to use this\n\nYou can use these extensions when you are working with\n`mdast-util-from-markdown` and `mdast-util-to-markdown` already.\n\nWhen working with `mdast-util-from-markdown`, you must combine this package\nwith [`micromark-extension-gfm-footnote`][micromark-extension-gfm-footnote].\n\nWhen you don’t need a syntax tree, you can use [`micromark`][micromark]\ndirectly with `micromark-extension-gfm-footnote`.\n\nWhen you are working with syntax trees and want all of GFM, use\n[`mdast-util-gfm`][mdast-util-gfm] instead.\n\nAll these packages are used [`remark-gfm`][remark-gfm], which\nfocusses on making it easier to transform content by abstracting these\ninternals away.\n\nThis utility does not handle how markdown is turned to HTML.\nThat’s done by [`mdast-util-to-hast`][mdast-util-to-hast].\nIf your content is not in English, you should configure that utility.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install mdast-util-gfm-footnote\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {gfmFootnoteFromMarkdown, gfmFootnoteToMarkdown} from 'https://esm.sh/mdast-util-gfm-footnote@2'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import {gfmFootnoteFromMarkdown, gfmFootnoteToMarkdown} from 'https://esm.sh/mdast-util-gfm-footnote@2?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\nSay our document `example.md` contains:\n\n```markdown\nIn the Solar System, Mercury[^mercury] and Venus[^venus] have very small tilts.\n\n[^mercury]:\n    **Mercury** is the first planet from the Sun and the smallest\n    in the Solar System.\n\n[^venus]:\n    **Venus** is the second planet from\n    the Sun.\n```\n\n…and our module `example.js` looks as follows:\n\n```js\nimport fs from 'node:fs/promises'\nimport {fromMarkdown} from 'mdast-util-from-markdown'\nimport {\n  gfmFootnoteFromMarkdown,\n  gfmFootnoteToMarkdown\n} from 'mdast-util-gfm-footnote'\nimport {toMarkdown} from 'mdast-util-to-markdown'\nimport {gfmFootnote} from 'micromark-extension-gfm-footnote'\n\nconst value = await fs.readFile('example.md', 'utf8')\n\nconst tree = fromMarkdown(value, {\n  extensions: [gfmFootnote()],\n  mdastExtensions: [gfmFootnoteFromMarkdown()]\n})\n\nconsole.log(tree)\n\nconst result = toMarkdown(tree, {\n  extensions: [gfmFootnoteToMarkdown({firstLineBlank: true})]\n})\n\nconsole.log(result)\n```\n\n…now running `node example.js` yields (positional info removed for brevity):\n\n```js\n{\n  type: 'root',\n  children: [\n    {\n      type: 'paragraph',\n      children: [\n        {type: 'text', value: 'In the Solar System, Mercury'},\n        {type: 'footnoteReference', identifier: 'mercury', label: 'mercury'},\n        {type: 'text', value: ' and Venus'},\n        {type: 'footnoteReference', identifier: 'venus', label: 'venus'},\n        {type: 'text', value: ' have very small tilts.'}\n      ]\n    },\n    {\n      type: 'footnoteDefinition',\n      identifier: 'mercury',\n      label: 'mercury',\n      children: [\n        {\n          type: 'paragraph',\n          children: [\n            {type: 'strong', children: [{type: 'text', value: 'Mercury'}]},\n            {\n              type: 'text',\n              value:\n                ' is the first planet from the Sun and the smallest\\n' +\n                'in the Solar System.'\n            }\n          ]\n        }\n      ]\n    },\n    {\n      type: 'footnoteDefinition',\n      identifier: 'venus',\n      label: 'venus',\n      children: [\n        {\n          type: 'paragraph',\n          children: [\n            {type: 'strong', children: [{type: 'text', value: 'Venus'}]},\n            {type: 'text', value: ' is the second planet from\\nthe Sun.'}\n          ]\n        }\n      ]\n    }\n  ]\n}\n```\n\n```markdown\nIn the Solar System, Mercury[^mercury] and Venus[^venus] have very small tilts.\n\n[^mercury]:\n    **Mercury** is the first planet from the Sun and the smallest\n    in the Solar System.\n\n[^venus]:\n    **Venus** is the second planet from\n    the Sun.\n```\n\n## API\n\nThis package exports the identifiers\n[`gfmFootnoteFromMarkdown`][api-gfmfootnotefrommarkdown] and\n[`gfmFootnoteToMarkdown`][api-gfmfootnotetomarkdown].\nThere is no default export.\nIt exports the type [`ToMarkdownOptions`][api-to-markdown-options].\n\n### `gfmFootnoteFromMarkdown()`\n\nCreate an extension for\n[`mdast-util-from-markdown`][mdast-util-from-markdown]\nto enable GFM footnotes in markdown.\n\n###### Returns\n\nExtension for `mdast-util-from-markdown`\n([`FromMarkdownExtension`][frommarkdownextension]).\n\n### `gfmFootnoteToMarkdown(options?)`\n\nCreate an extension for\n[`mdast-util-to-markdown`][mdast-util-to-markdown]\nto enable GFM footnotes in markdown.\n\n###### Parameters\n\n* `options` ([`ToMarkdownOptions`][api-to-markdown-options], optional)\n  — configuration\n\n###### Returns\n\nExtension for `mdast-util-to-markdown`\n([`ToMarkdownExtension`][tomarkdownextension]).\n\n### `ToMarkdownOptions`\n\nConfiguration (TypeScript type).\n\n###### Fields\n\n* `firstLineBlank` (`boolean`, default: `false`)\n  — use a blank line for the first line of footnote definitions\n\n## HTML\n\nThis utility does not handle how markdown is turned to HTML.\nThat’s done by [`mdast-util-to-hast`][mdast-util-to-hast].\nIf your content is not in English, you should configure that utility.\n\n## Syntax\n\nSee [Syntax in `micromark-extension-gfm-footnote`][syntax].\n\n## Syntax tree\n\nThe following interfaces are added to **[mdast][]** by this utility.\n\n### Nodes\n\n#### `FootnoteDefinition`\n\n```idl\ninterface FootnoteDefinition \u003c: Parent {\n  type: 'footnoteDefinition'\n  children: [FlowContent]\n}\n\nFootnoteDefinition includes Association\n```\n\n**FootnoteDefinition** (**[Parent][dfn-parent]**) represents content relating\nto the document that is outside its flow.\n\n**FootnoteDefinition** can be used where **[flow][dfn-flow-content]** content\nis expected.\nIts content model is also **[flow][dfn-flow-content]** content.\n\n**FootnoteDefinition** includes the mixin\n**[Association][dfn-mxn-association]**.\n\n**FootnoteDefinition** should be associated with\n**[FootnoteReferences][dfn-footnote-reference]**.\n\nFor example, the following markdown:\n\n```markdown\n[^alpha]: bravo and charlie.\n```\n\nYields:\n\n```js\n{\n  type: 'footnoteDefinition',\n  identifier: 'alpha',\n  label: 'alpha',\n  children: [{\n    type: 'paragraph',\n    children: [{type: 'text', value: 'bravo and charlie.'}]\n  }]\n}\n```\n\n#### `FootnoteReference`\n\n```idl\ninterface FootnoteReference \u003c: Node {\n  type: 'footnoteReference'\n}\n\nFootnoteReference includes Association\n```\n\n**FootnoteReference** (**[Node][dfn-node]**) represents a marker through\nassociation.\n\n**FootnoteReference** can be used where\n**[phrasing][dfn-phrasing-content]** content is expected.\nIt has no content model.\n\n**FootnoteReference** includes the mixin **[Association][dfn-mxn-association]**.\n\n**FootnoteReference** should be associated with a\n**[FootnoteDefinition][dfn-footnote-definition]**.\n\nFor example, the following markdown:\n\n```markdown\n[^alpha]\n```\n\nYields:\n\n```js\n{\n  type: 'footnoteReference',\n  identifier: 'alpha',\n  label: 'alpha'\n}\n```\n\n### Content model\n\n#### `FlowContent` (GFM footnotes)\n\n```idl\ntype FlowContentGfm = FootnoteDefinition | FlowContent\n```\n\n#### `PhrasingContent` (GFM footnotes)\n\n```idl\ntype PhrasingContentGfm = FootnoteReference | PhrasingContent\n```\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt does not export additional types.\n\nThe `FootnoteDefinition` and `FootnoteReference` types of the mdast nodes are\nexposed from `@types/mdast`.\n\n## Compatibility\n\nProjects maintained by the unified collective are compatible with maintained\nversions of Node.js.\n\nWhen we cut a new major release, we drop support for unmaintained versions of\nNode.\nThis means we try to keep the current release line,\n`mdast-util-gfm-footnote@^2`, compatible with Node.js 16.\n\n## Related\n\n* [`remark-gfm`][remark-gfm]\n  — remark plugin to support GFM\n* [`mdast-util-gfm`][mdast-util-gfm]\n  — same but all of GFM (autolink literals, footnotes, strikethrough, tables,\n  tasklists)\n* [`micromark-extension-gfm-footnote`][micromark-extension-gfm-footnote]\n  — micromark extension to parse GFM footnotes\n\n## Contribute\n\nSee [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for\nways to get started.\nSee [`support.md`][support] for ways to get help.\n\nThis project has a [code of conduct][coc].\nBy interacting with this repository, organization, or community you agree to\nabide by its terms.\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n\u003c!-- Definitions --\u003e\n\n[api-gfmfootnotefrommarkdown]: #gfmfootnotefrommarkdown\n\n[api-gfmfootnotetomarkdown]: #gfmfootnotetomarkdownoptions\n\n[api-to-markdown-options]: #tomarkdownoptions\n\n[author]: https://wooorm.com\n\n[backers-badge]: https://opencollective.com/unified/backers/badge.svg\n\n[build]: https://github.com/syntax-tree/mdast-util-gfm-footnote/actions\n\n[build-badge]: https://github.com/syntax-tree/mdast-util-gfm-footnote/workflows/main/badge.svg\n\n[chat]: https://github.com/syntax-tree/unist/discussions\n\n[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg\n\n[cmark-gfm]: https://github.com/github/cmark-gfm\n\n[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md\n\n[collective]: https://opencollective.com/unified\n\n[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md\n\n[coverage]: https://codecov.io/github/syntax-tree/mdast-util-gfm-footnote\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-gfm-footnote.svg\n\n[dfn-flow-content]: #flowcontent-gfm-footnotes\n\n[dfn-footnote-definition]: #footnotedefinition\n\n[dfn-footnote-reference]: #footnotereference\n\n[dfn-mxn-association]: https://github.com/syntax-tree/mdast#association\n\n[dfn-node]: https://github.com/syntax-tree/unist#node\n\n[dfn-parent]: https://github.com/syntax-tree/mdast#parent\n\n[dfn-phrasing-content]: #phrasingcontent-gfm-footnotes\n\n[downloads]: https://www.npmjs.com/package/mdast-util-gfm-footnote\n\n[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-gfm-footnote.svg\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[esmsh]: https://esm.sh\n\n[frommarkdownextension]: https://github.com/syntax-tree/mdast-util-from-markdown#extension\n\n[gfm]: https://github.github.com/gfm/\n\n[health]: https://github.com/syntax-tree/.github\n\n[license]: license\n\n[mdast]: https://github.com/syntax-tree/mdast\n\n[mdast-util-from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown\n\n[mdast-util-gfm]: https://github.com/syntax-tree/mdast-util-gfm\n\n[mdast-util-to-hast]: https://github.com/syntax-tree/mdast-util-to-hast\n\n[mdast-util-to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown\n\n[micromark]: https://github.com/micromark/micromark\n\n[micromark-extension-gfm-footnote]: https://github.com/micromark/micromark-extension-gfm-footnote\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[post]: https://github.blog/changelog/2021-09-30-footnotes-now-supported-in-markdown-fields/\n\n[remark-gfm]: https://github.com/remarkjs/remark-gfm\n\n[size]: https://bundlejs.com/?q=mdast-util-gfm-footnote\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size\u0026query=$.size.compressedSize\u0026url=https://deno.bundlejs.com/?q=mdast-util-gfm-footnote\n\n[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg\n\n[support]: https://github.com/syntax-tree/.github/blob/main/support.md\n\n[syntax]: https://github.com/micromark/micromark-extension-gfm-footnote#syntax\n\n[tomarkdownextension]: https://github.com/syntax-tree/mdast-util-to-markdown#options\n\n[typescript]: https://www.typescriptlang.org\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fmdast-util-gfm-footnote","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyntax-tree%2Fmdast-util-gfm-footnote","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fmdast-util-gfm-footnote/lists"}