@yozora/tokenizer-admonition
Install
- npm
- Yarn
- pnpm
npm install --save @yozora/tokenizer-admonition
yarn add @yozora/tokenizer-admonition
pnpm add @yozora/tokenizer-admonition
Usage
@yozora/tokenizer-admonition has been integrated into @yozora/parser,
so you can use YozoraParser
directly.
- Basic Usage
- YozoraParser
- GfmParser
- GfmExParser
@yozora/tokenizer-admonition 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 AdmonitionTokenizer from '@yozora/tokenizer-admonition'
const parser = new DefaultYastParser()
.useBlockFallbackTokenizer(new ParagraphTokenizer())
.useInlineFallbackTokenizer(new TextTokenizer())
.useTokenizer(new AdmonitionTokenizer())
// parse source markdown content
parser.parse(`
:::info[this is a info type admonition]
waw
### some block contents
:::
`)
import YozoraParser from '@yozora/parser'
const parser = new YozoraParser()
// parse source markdown content
parser.parse(`
:::info[this is a info type admonition]
waw
### some block contents
:::
`)
import GfmParser from '@yozora/parser-gfm'
import AdmonitionTokenizer from '@yozora/tokenizer-admonition'
const parser = new GfmParser()
parser.useTokenizer(new AdmonitionTokenizer())
// parse source markdown content
parser.parse(`
:::info[this is a info type admonition]
waw
### some block contents
:::
`)
import GfmExParser from '@yozora/parser-gfm-ex'
import AdmonitionTokenizer from '@yozora/tokenizer-admonition'
const parser = new GfmExParser()
parser.useTokenizer(new AdmonitionTokenizer())
// parse source markdown content
parser.parse(`
:::info[this is a info type admonition]
waw
### some block contents
:::
`)
Options
Name | Type | Required | Default |
---|---|---|---|
name | string | false | "@yozora/tokenizer-admonition" |
priority | number | false | TokenizerPriority.FENCED_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-admonition produce Admonition type nodes. See @yozora/ast for full base types.
import type { YastParent } from '@yozora/ast'
export const AdmonitionType = 'admonition'
export type AdmonitionType = typeof AdmonitionType
/**
* Admonitions are block elements. The titles can include inline markdown and
* the body can include any block markdown except another admonition.
* @see https://github.com/elviswolcott/remark-admonitions
*/
export interface Admonition extends YastParent<AdmonitionType> {
/**
* Keyword of an admonition.
*/
keyword: 'note' | 'important' | 'tip' | 'caution' | 'warning' | string
/**
* Admonition title.
*/
title: YastNode[]
}
Live Examples
-
Basic Usage.
#1yozorapretty-json -
Admonition body could be empty.
#2yozorapretty-json -
Admonition body supported full features of markdown.
#3yozorapretty-json -
Admonition title could include inlines.
#4yozorapretty-json