Extension for mdast-util-from-markdown
and/or
mdast-util-to-markdown
to support GitHub flavored markdown
autolink literals in mdast.
When parsing (from-markdown
), must be combined with
micromark-extension-gfm-autolink-literal
.
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-autolink-literal
Say our module, example.js
, looks as follows:
import {fromMarkdown} from 'mdast-util-from-markdown'
import {toMarkdown} from 'mdast-util-to-markdown'
import {gfmAutolinkLiteral} from 'micromark-extension-gfm-autolink-literal'
import {gfmAutolinkLiteralFromMarkdown, gfmAutolinkLiteralToMarkdown} from 'mdast-util-gfm-autolink-literal'
const doc = 'www.example.com, https://example.com, and contact@example.com.'
const tree = fromMarkdown(doc, {
extensions: [gfmAutolinkLiteral],
mdastExtensions: [gfmAutolinkLiteralFromMarkdown]
})
console.log(tree)
const out = toMarkdown(tree, {extensions: [gfmAutolinkLiteralToMarkdown]})
console.log(out)
Now, running node example
yields:
{
type: 'root',
children: [
{
type: 'paragraph',
children: [
{
type: 'link',
title: null,
url: 'http://www.example.com',
children: [{type: 'text', value: 'www.example.com'}]
},
{type: 'text', value: ', '},
{
type: 'link',
title: null,
url: 'https://example.com',
children: [{type: 'text', value: 'https://example.com'}]
},
{type: 'text', value: ', and '},
{
type: 'link',
title: null,
url: 'mailto:contact@example.com',
children: [{type: 'text', value: 'contact@example.com'}]
},
{type: 'text', value: '.'}
]
}
]
}
[www.example.com](http://www.example.com), <https://example.com>, and <contact@example.com>.
Support literal autolinks.
The exports are 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-autolink-literal
— micromark extension to parse GFM autolink literalssyntax-tree/mdast-util-from-markdown
— mdast parser usingmicromark
to 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.