@yozora/tokenizer-blockquote
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:
-
Basic case. If a string of lines constitute a sequence of blocks , then the result of prepending a block quote marker to the beginning of each line in is a block quote containing .
-
Laziness. If a string of lines 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 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.
-
Consecutiveness. A document cannot contain two block quotes in a row unless there is a blank line between them.
- See github flavor markdown spec for details.
- See Live Examples for an intuitive impression.
Installโ
- npm
- Yarn
- pnpm
npm install --save @yozora/tokenizer-blockquote
yarn add @yozora/tokenizer-blockquote
pnpm add @yozora/tokenizer-blockquote
Usageโ
@yozora/tokenizer-blockquote has been integrated into @yozora/parser / @yozora/parser-gfm-ex / @yozora/parser-gfm,
so you can use YozoraParser
/ GfmExParser
/ GfmParser
directly.
- Basic Usage
- YozoraParser
- GfmParser
- GfmExParser
@yozora/tokenizer-blockquote cannot be used alone, it needs to be registered in Parser as a plugin-in before it can be used.
import { DefaultParser } from '@yozora/core-parser'
import ParagraphTokenizer from '@yozora/tokenizer-paragraph'
import TextTokenizer from '@yozora/tokenizer-text'
import BlockquoteTokenizer from '@yozora/tokenizer-blockquote'
const parser = new DefaultParser()
.useFallbackTokenizer(new ParagraphTokenizer())
.useFallbackTokenizer(new TextTokenizer())
.useTokenizer(new BlockquoteTokenizer())
// parse source markdown content
parser.parse(`
> This is blockquote
> - with some list contents
> - apple
>
> ## A cat in heading
`)
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
`)
import GfmParser from '@yozora/parser-gfm'
const parser = new GfmParser()
// parse source markdown content
parser.parse(`
> This is blockquote
> - with some list contents
> - apple
>
> ## A cat in heading
`)
import GfmExParser from '@yozora/parser-gfm-ex'
const parser = new GfmExParser()
// parse source markdown content
parser.parse(`
> This is blockquote
> - with some list contents
> - apple
>
> ## A cat in heading
`)
Optionsโ
Name | Type | Required | Default |
---|---|---|---|
name | string | false | "@yozora/tokenizer-blockquote" |
priority | number | false | TokenizerPriority.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 thematch-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.