Skip to main content
Version: 1.x.x

@yozora/tokenizer-image-reference

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

github flavor markdown spec

Syntax for images is like the syntax for links, with one difference. Instead of link text, we have an image description. The rules for this are the same as for link text, except that

  • a) an image description starts with ![ rather than [, and
  • b) an image description may contain links. An image description has inline elements as its contents. When an image is rendered to HTML, this is standardly used as the image’s alt attribute.

Install

npm install --save @yozora/tokenizer-image-reference

Usage

tip

@yozora/tokenizer-image-reference 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][]

[foo]: /url "title"
`)

Options

NameTypeRequiredDefault
namestringfalse"@yozora/tokenizer-image-reference"
prioritynumberfalseTokenizerPriority.LINKS
  • 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-image-reference produce ImageReference type nodes. See @yozora/ast for full base types.

import type {
YastAlternative,
YastAssociation,
YastNode,
YastReference,
} from '@yozora/ast'

export const ImageReferenceType = 'imageReference'
export type ImageReferenceType = typeof ImageReferenceType

/**
* ImageReference represents an image through association, or its original
* source if there is no association.
* @see https://github.github.com/gfm/#images
* @see https://github.com/syntax-tree/mdast#imagereference
*/
export interface ImageReference extends
YastNode<ImageReferenceType>,
YastAssociation,
YastReference,
YastAlternative {}

Live Examples

Full style

  • Basic.

      
      

Collapsed style

  • Basic.

      
      
  • The labels are case-insensitive.

    #594
      
      
  • As with reference links, whitespace is not allowed between the two sets of brackets.

    #595
      
      

Shortcut styled

  • Basic.

      
      
  • Note that link labels cannot contain unescaped brackets.

    #598
      
      
  • The link labels are case-insensitive。

    #599
      
      
  • If you just want a literal ! followed by bracketed text, you can backslash-escape the opening [.

    #600
      
      
  • If you want a link after a literal !, backslash-escape the !.

    #601