Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
mdast-util-gfm-footnote
Advanced tools
The mdast-util-gfm-footnote npm package is a utility to support GitHub Flavored Markdown (GFM) footnotes in mdast, which is a Markdown Abstract Syntax Tree format. It allows for parsing and serializing footnote syntax as specified in GFM, making it easier to handle footnotes in Markdown files programmatically.
Parsing GFM footnotes
This feature allows the parsing of GFM footnotes in Markdown text. The code sample demonstrates how to set up a processor with unified, using the remark-parse and remark-gfm plugins along with mdast-util-gfm-footnote to parse a Markdown string containing a footnote.
import { unified } from 'unified';
import markdown from 'remark-parse';
import gfm from 'remark-gfm';
import gfmFootnote from 'mdast-util-gfm-footnote';
const processor = unified()
.use(markdown)
.use(gfm)
.use(gfmFootnote);
const ast = processor.parse('[^1]: This is a footnote.');
console.log(ast);
Serializing GFM footnotes
This feature supports the serialization of GFM footnotes back into Markdown format. The code sample shows how to configure a unified processor to convert an AST with a footnote definition back into a Markdown string.
import { unified } from 'unified';
import markdown from 'remark-parse';
import gfm from 'remark-gfm';
import gfmFootnote from 'mdast-util-gfm-footnote';
import stringify from 'remark-stringify';
const processor = unified()
.use(markdown)
.use(gfm)
.use(gfmFootnote)
.use(stringify);
const ast = { type: 'footnoteDefinition', identifier: '1', children: [{ type: 'paragraph', children: [{ type: 'text', value: 'This is a footnote.' }] }] };
const markdownText = processor.stringify(ast);
console.log(markdownText);
remark-footnotes is a plugin for the remark Markdown processor that adds support for footnotes. It is similar to mdast-util-gfm-footnote but is specifically designed to work within the remark ecosystem. While mdast-util-gfm-footnote focuses on GFM-specific footnote syntax, remark-footnotes offers a more general approach to footnotes in Markdown.
remark-gfm is another plugin for remark that adds support for GitHub Flavored Markdown. It includes support for tables, strikethrough, task lists, and URLs directly. While it also supports footnotes as part of its GFM support, mdast-util-gfm-footnote provides more specialized and detailed handling of footnotes in the context of GFM.
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 import
ed instead of require
d.
npm:
npm install mdast-util-gfm-footnote
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
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
.
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 using micromark
to create mdast from markdownsyntax-tree/mdast-util-to-markdown
— mdast serializer to create markdown from mdastSee 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.
FAQs
mdast extension to parse and serialize GFM footnotes
The npm package mdast-util-gfm-footnote receives a total of 1,789,526 weekly downloads. As such, mdast-util-gfm-footnote popularity was classified as popular.
We found that mdast-util-gfm-footnote demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.