mdast-util-gfm-autolink-literal
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
.
You might want to use this package through remark-gfm
with remark.
Install
npm:
npm install mdast-util-gfm-autolink-literal
Use
Say our script, example.js
, looks as follows:
var fromMarkdown = require('mdast-util-from-markdown')
var toMarkdown = require('mdast-util-to-markdown')
var syntax = require('micromark-extension-gfm-autolink-literal')
var autolinkLiteral = require('mdast-util-gfm-autolink-literal')
var doc = 'www.example.com, https://example.com, and contact@example.com.'
var tree = fromMarkdown(doc, {
extensions: [syntax],
mdastExtensions: [autolinkLiteral.fromMarkdown]
})
console.log(tree)
var out = toMarkdown(tree, {extensions: [autolinkLiteral.toMarkdown]})
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>.
API
autolinkLiteral.fromMarkdown
autolinkLiteral.toMarkdown
Note: the separate extensions are also available at
mdast-util-gfm-autolink-literal/from-markdown
andmdast-util-gfm-autolink-literal/to-markdown
.
Support literal autolinks. The exports are extensions, respectively for mdast-util-from-markdown
and mdast-util-to-markdown
.
Related
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
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.