unified

Project: micromark/micromark-extension-gfm-autolink-literal

Package: micromark-extension-gfm-autolink-literal@1.0.0

  1. Dependents: 4
  2. micromark extension to support GFM autolink literals
  1. unified 173
  2. markdown 137
  3. micromark 32
  4. gfm 17
  5. link 16
  6. micromark-extension 15
  7. url 13
  8. literal 4
  9. autolink 4
  10. auto 4

micromark-extension-gfm-autolink-literal

Build Coverage Downloads Size Sponsors Backers Chat

micromark extension to support GitHub flavored markdown (GFM) literal autolinks.

This syntax extension matches the GFM spec and how literal autolinks work in several places on github.com. GitHub employs two algorithms to autolink: one at parse time and one at transform time (similar to how @mentions are done at transform time). This difference can be observed because character references and escapes are handled differently. But also because issues/PRs/comments omit (perhaps by accident?) the second algorithm for www., http://, and https:// links (but not for email links).

As this is a syntax extension, it focuses on the first algorithm. The html part of this extension does not operate on an AST and hence can’t perform the second algorithm. mdast-util-gfm-autolink-literal adds support for the second.

When to use this

You should probably use micromark-extension-gfm, which combines this package with other GFM features, instead. Alternatively, if you don’t want all of GFM, use this package.

Install

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

npm:

npm install micromark-extension-gfm-autolink-literal

Use

import {micromark} from 'micromark'
import {
  gfmAutolinkLiteral,
  gfmAutolinkLiteralHtml
} from 'micromark-extension-gfm-autolink-literal'

const output = micromark('Just a URL: www.example.com.', {
  extensions: [gfmAutolinkLiteral],
  htmlExtensions: [gfmAutolinkLiteralHtml]
})

console.log(output)

Yields:

<p>Just a URL: <a href="http://www.example.com">www.example.com</a>.</p>

API

This package exports the following identifiers: gfmAutolinkLiteral, gfmAutolinkLiteralHtml. There is no default export.

The export map supports the endorsed development condition. Run node --conditions development module.js to get instrumented dev code. Without this condition, production code is loaded.

gfmAutolinkLiteral

gfmAutolinkLiteralHtml

An extension for the micromark parser (to parse; can be passed in extensions) and one for the HTML compiler (to compile as <a> elements; can be passed in htmlExtensions).

Contribute

See contributing.md in micromark/.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