Skip to content

marcofranssen/mdast-util-gfm-autolink-literal

 
 

Repository files navigation

mdast-util-gfm-autolink-literal

Build Coverage Downloads Size Sponsors Backers Chat

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 probably shouldn’t use this package directly, but instead use 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 and mdast-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

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

About

mdast extension to parse and serialize GFM autolink literals

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%