unified

Project: syntax-tree/mdast-util-gfm-autolink-literal

Package: mdast-util-gfm-autolink-literal@0.1.1

  1. Dependencies: 0·Dependents: 0
  2. mdast extension to parse and serialize GFM autolink literals
  1. markdown 133
  2. util 118
  3. utility 114
  4. unist 110
  5. mdast 81
  6. mdast-util 24
  7. gfm 17
  8. link 15
  9. markup 12
  10. url 11
  11. autolink 4
  12. auto 4
  13. literal 4
  14. raw 3

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.

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