Skip to main content
Version: 3.x.x ๐Ÿšง

@yozora/tokenizer-blockquote

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

github flavor markdown spec

A block quote marker consists of 0-3 spaces of initial indent, plus

  • a) the character > together with a following space, or
  • b) a single character > not followed by a space.

The following rules define block quotes:

  1. Basic case. If a string of lines LsL_s constitute a sequence of blocks BsB_s, then the result of prepending a block quote marker to the beginning of each line in LsL_s is a block quote containing BsB_s.

  2. Laziness. If a string of lines LsL_s constitute a [block quote]gfm-blockquote] with contents Bs, then the result of deleting the initial block quote marker from one or more lines in which the next non-whitespace character after the block quote marker is paragraph continuation text is a block quote with BsB_s as its content. Paragraph continuation text is text that will be parsed as part of the content of a paragraph, but does not occur at the beginning of the paragraph.

  3. Consecutiveness. A document cannot contain two block quotes in a row unless there is a blank line between them.

Installโ€‹

npm install --save @yozora/tokenizer-blockquote

Usageโ€‹

tip

@yozora/tokenizer-blockquote 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(`
> This is blockquote
> - with some list contents
> - apple
>
> ## A cat in heading
`)

Optionsโ€‹

NameTypeRequiredDefault
namestringfalse"@yozora/tokenizer-blockquote"
prioritynumberfalseTokenizerPriority.CONTAINING_BLOCK
  • 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-blockquote produce Blockquote type nodes. See @yozora/ast for full base types.

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

export const BlockquoteType = 'blockquote'
export type BlockquoteType = typeof BlockquoteType

/**
* Blockquote represents a section quoted from somewhere else.
* @see https://github.com/syntax-tree/mdast#blockquote
* @see https://github.github.com/gfm/#block-quotes
*/
export type Blockquote = Parent<BlockquoteType>

Live Examplesโ€‹

  • Basic.

    ย ย 
    ย ย 
  • Laziness.

    ย ย 
    ย ย 
  • Consecutiveness.

    ย ย 
    ย ย