mdast-util-gfm-autolink-literal
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.2 • Public • Published

    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.

    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

    Install

    npm i mdast-util-gfm-autolink-literal

    DownloadsWeekly Downloads

    403,838

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    16.1 kB

    Total Files

    5

    Last publish

    Collaborators

    • wooorm
    • kmck