unified

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

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

  1. Dependents: 4
  2. mdast extension to parse and serialize GFM autolink literals
  1. util 137
  2. markdown 137
  3. utility 133
  4. unist 120
  5. mdast 89
  6. mdast-util 30
  7. markup 18
  8. gfm 17
  9. link 16
  10. url 13
  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.

When to use this

Use mdast-util-gfm if you want all of GFM. Use this otherwise.

Install

This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.

npm:

npm install mdast-util-gfm-autolink-literal

Use

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>.

API

gfmAutolinkLiteralFromMarkdown

gfmAutolinkLiteralToMarkdown

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