mdast-util-gfm-autolink-literal

mdast extension to parse and serialize GFM autolink literals

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
mdast-util-gfm-autolink-literal
301.0.2a year ago2 years agoMinified + gzip package size for mdast-util-gfm-autolink-literal in KB

Readme

mdast-util-gfm-autolink-literal
!Buildbuild-badgebuild !Coveragecoverage-badgecoverage !Downloadsdownloads-badgedownloads !Sizesize-badgesize !Sponsorssponsors-badgecollective !Backersbackers-badgecollective !Chatchat-badgechat
Extension for mdast-util-from-markdownfrom-markdown and/or mdast-util-to-markdownto-markdown to support GitHub flavored markdown autolink literals in mdast. When parsing (from-markdown), must be combined with micromark-extension-gfm-autolink-literalextension.

When to use this

Use mdast-util-gfmmdast-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 install mdast-util-gfm-autolink-literal
## Use

Say our module, `example.js`, looks as follows:

```js
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-markdownfrom-markdown and mdast-util-to-markdownto-markdown.

Related

— markdown processor powered by plugins
— remark plugin to support GFM
— the smallest commonmark-compliant markdown parser that exists
— micromark extension to parse GFM autolink literals
— mdast parser using `micromark` to create mdast from markdown
— mdast serializer to create markdown from mdast

Contribute

See contributing.md in syntax-tree/.githubcontributing for ways to get started. See support.mdsupport for ways to get help.
This project has a code of conductcoc. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MITlicense © Titus Wormerauthor