Skip to main content
Version: 2.x.x

@yozora/tokenizer-autolink-extension

Npm VersionNpm DownloadNpm LicenseModule formats: cjs, esmNode.js VersionTested with JestCode Style: prettier

github flavor markdown spec

GFM enables the autolink extension, where autolinks will be recognised in a greater number of conditions.

Autolinks can also be constructed without requiring the use of < and to > to delimit them, although they will be recognized under a smaller set of circumstances. All such recognized autolinks can only come at the beginning of a line, after whitespace, or any of the delimiting characters *, _, ~, and (.

An extended www autolink will be recognized when the text www. is found followed by a valid domain. A valid domain consists of segments of alphanumeric characters, underscores (_) and hyphens (-) separated by periods (.). There must be at least one period, and no underscores may be present in the last two segments of the domain. We then apply extended autolink path validation as follows:

  • Trailing punctuation (specifically, ?, !, ., ,, :, *, _, and ~) will not be considered part of the autolink, though they may be included in the interior of the link.

An extended url autolink will be recognised when one of the schemes http://, or https://, followed by a valid domain, then zero or more non-space non-< characters according to extended autolink path validation.

An extended email autolink will be recognised when an email address is recognised within any text node. Email addresses are recognised according to the following rules:

  • One ore more characters which are alphanumeric, or ., -, _, or +.
  • An @ symbol.
  • One or more characters which are alphanumeric, or - or _, separated by periods (.). There must be at least one period. The last character must not be one of - or _.

Install

npm install --save @yozora/tokenizer-autolink-extension

Usage

tip

@yozora/tokenizer-autolink-extension has been integrated into @yozora/parser / @yozora/parser-gfm-ex, so you can use YozoraParser / GfmExParser directly.

import YozoraParser from '@yozora/parser'

const parser = new YozoraParser()

// parse source markdown content
parser.parse(`
foo@bar.example.com

http://foo.bar.baz

made-up-scheme://foo,bar
`)

Options

NameTypeRequiredDefault
namestringfalse"@yozora/tokenizer-autolink-extension"
prioritynumberfalseTokenizerPriority.ATOMIC
  • name: The unique name of the tokenizer, used to bind the token it generates, to determine the tokenizer that should be called in each life cycle of the token in the entire matching / parsing phase.

  • priority: Priority of the tokenizer, determine the order of processing, high priority priority execution. interruptable. In addition, in the match-block stage, a high-priority tokenizer can interrupt the matching process of a low-priority tokenizer.

    Exception: Delimiters of type full are always processed before other type delimiters.

Types

@yozora/tokenizer-autolink-extension produce Link type nodes. See @yozora/ast for full base types.

import type { Parent, Resource } from '@yozora/ast'

export const LinkType = 'link'
export type LinkType = typeof LinkType

/**
* Link represents a hyperlink.
* @see https://github.com/syntax-tree/mdast#link
* @see https://github.github.com/gfm/#inline-link
*/
export interface Link extends Parent<LinkType>, Resource {}

Live Examples

  • Extended www autolink

      
      
  • [Extended email autolink][gfm-extended-email-autolink]