Skip to main content
Version: 2.x.x

@yozora/tokenizer-definition

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

github flavor markdown spec

A link reference definition consists of a link label, indented up to three spaces, followed by a colon (:), optional whitespace (including up to one line ending), a link destination, optional whitespace (including up to one line ending), and an optional link title, which if it is present must be separated from the link destination by whitespace. No further non-whitespace characters may occur on the line.

A link reference definition does not correspond to a structural element of a document. Instead, it defines a label which can be used in reference links and reference-style images elsewhere in the document. Link reference definitions can come either before or after the links that use them.

Install

npm install --save @yozora/tokenizer-definition

Usage

tip

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

import YozoraParser from '@yozora/parser'

const parser = new YozoraParser()

// parse source markdown content
parser.parse(`
[foo]: /url '
title
line1
line2
'

[foo]
`)

Options

NameTypeRequiredDefault
namestringfalse"@yozora/tokenizer-definition"
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.

Types

@yozora/tokenizer-definition produce Definition type nodes. See @yozora/ast for full base types.

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

export const DefinitionType = 'definition'
export type DefinitionType = typeof DefinitionType

/**
* Definition represents a resource.
* @see https://github.com/syntax-tree/mdast#definition
* @see https://github.github.com/gfm/#link-reference-definitions
*/
export interface Definition extends
Node<DefinitionType>,
Association,
Resource {}

Live Examples

  • Basic.

    Loading...
    {2 properties}
  • The title may extend over multiple lines.

    #165
    Loading...
    {2 properties}
  • However, it may not contain a blank line.

    #166
    Loading...
    {2 properties}
  • The title may be omitted.

    #167
    Loading...
    {2 properties}
  • The link destination may not be omitted.

    #168
    Loading...
    {2 properties}
  • However, an empty link destination may be specified using angle brackets.

    #169
    Loading...
    {2 properties}
  • The title must be separated from the link destination by whitespace.

    #170
    Loading...
    {2 properties}
  • Both title and destination can contain backslash escapes and literal backslashes.

    #171
    Loading...
    {2 properties}
  • A link can come before its corresponding definition.

    #172
    Loading...
    {2 properties}
  • If there are several matching definitions, the first one takes precedence.

    #173
    Loading...
    {2 properties}
  • As noted in the section on Links, matching of labels is case-insensitive (see matches).

    Loading...
    {2 properties}
  • Here is a link reference definition with no corresponding link. It contributes nothing to the document.

    Loading...
    {2 properties}
  • This is not a link reference definition, because there are non-whitespace characters after the title.

    #178
    Loading...
    {2 properties}
  • This is a link reference definition, but it has no title.

    #179
    Loading...
    {2 properties}
  • This is not a link reference definition, because it is indented four spaces.

    #180
    Loading...
    {2 properties}
  • This is not a link reference definition, because it occurs inside a code block.

    #181
    Loading...
    {2 properties}
  • A link reference definition cannot interrupt a paragraph.

    #182
    Loading...
    {2 properties}
  • However, it can directly follow other block elements, such as headings and thematic breaks, and it need not be followed by a blank line.

    Loading...
    {2 properties}
  • Several link reference definitions can occur one after another, without intervening blank lines.

    #186
    Loading...
    {2 properties}
  • Link reference definitions can occur inside block containers, like lists and block quotations. They affect the entire document, not just the container in which they are defined.

    #187
    Loading...
    {2 properties}
  • Whether something is a link reference definition is independent of whether the link reference it defines is used in the document. Thus, for example, the following document contains just a link reference definition, and no visible content.

    #188
    Loading...
    {2 properties}