@yozora/tokenizer-autolink-extension
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_
.
- See github flavor markdown spec for details.
- See Live Examples for an intuitive impression.
Install
- npm
- Yarn
- pnpm
npm install --save @yozora/tokenizer-autolink-extension
yarn add @yozora/tokenizer-autolink-extension
pnpm add @yozora/tokenizer-autolink-extension
Usage
@yozora/tokenizer-autolink-extension has been integrated into @yozora/parser / @yozora/parser-gfm-ex,
so you can use YozoraParser
/ GfmExParser
directly.
- Basic Usage
- YozoraParser
- GfmParser
- GfmExParser
@yozora/tokenizer-autolink-extension cannot be used alone, it needs to be registered in YastParser as a plugin-in before it can be used.
import { DefaultYastParser } from '@yozora/core-parser'
import ParagraphTokenizer from '@yozora/tokenizer-paragraph'
import TextTokenizer from '@yozora/tokenizer-text'
import AutolinkExtensionTokenizer from '@yozora/tokenizer-autolink-extension'
const parser = new DefaultYastParser()
.useBlockFallbackTokenizer(new ParagraphTokenizer())
.useInlineFallbackTokenizer(new TextTokenizer())
.useTokenizer(new AutolinkExtensionTokenizer())
// parse source markdown content
parser.parse(`
foo@bar.example.com
http://foo.bar.baz
made-up-scheme://foo,bar
`)
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
`)
import GfmParser from '@yozora/parser-gfm'
import AutolinkExtensionTokenizer from '@yozora/tokenizer-autolink-extension'
const parser = new GfmParser()
parser.useTokenizer(new AutolinkExtensionTokenizer())
// parse source markdown content
parser.parse(`
foo@bar.example.com
http://foo.bar.baz
made-up-scheme://foo,bar
`)
import GfmExParser from '@yozora/parser-gfm-ex'
const parser = new GfmExParser()
// parse source markdown content
parser.parse(`
foo@bar.example.com
http://foo.bar.baz
made-up-scheme://foo,bar
`)
Options
Name | Type | Required | Default |
---|---|---|---|
name | string | false | "@yozora/tokenizer-autolink-extension" |
priority | number | false | TokenizerPriority.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 thematch-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 { YastParent, YastResource } 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 YastParent<LinkType>, YastResource {}
Live Examples
-
[Extended email autolink][gfm-extended-email-autolink]