@yozora/tokenizer-admonition
Version:
Tokenizer for processing admonitions
425 lines (377 loc) • 18.3 kB
Markdown
<!-- :begin use tokenizer/banner -->
<header>
<h1 align="center">
<a href="https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/admonition#readme">/tokenizer-admonition</a>
</h1>
<div align="center">
<a href="https://www.npmjs.com/package/@yozora/tokenizer-admonition">
<img
alt="Npm Version"
src="https://img.shields.io/npm/v/@yozora/tokenizer-admonition.svg"
/>
</a>
<a href="https://www.npmjs.com/package/@yozora/tokenizer-admonition">
<img
alt="Npm Download"
src="https://img.shields.io/npm/dm/@yozora/tokenizer-admonition.svg"
/>
</a>
<a href="https://www.npmjs.com/package/@yozora/tokenizer-admonition">
<img
alt="Npm License"
src="https://img.shields.io/npm/l/@yozora/tokenizer-admonition.svg"
/>
</a>
<a href="#install">
<img
alt="Module formats: cjs, esm"
src="https://img.shields.io/badge/module_formats-cjs%2C%20esm-green.svg"
/>
</a>
<a href="https://github.com/nodejs/node">
<img
alt="Node.js Version"
src="https://img.shields.io/node/v/@yozora/tokenizer-admonition"
/>
</a>
<a href="https://github.com/facebook/jest">
<img
alt="Tested with Jest"
src="https://img.shields.io/badge/tested_with-jest-9c465e.svg"
/>
</a>
<a href="https://github.com/prettier/prettier">
<img
alt="Code Style: prettier"
src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square"
/>
</a>
</div>
</header>
<br/>
<!-- :end -->
[/tokenizer-admonition] produce [Admonition][node-type] type nodes. See
[documentation][docpage] for details.
<!-- :begin use tokenizer/usage -->
## Install
- npm
```bash
npm install --save /tokenizer-admonition
```
## Usage
[/tokenizer-admonition][] has been integrated into [@yozora/parser][], so you can use
`YozoraParser` directly.
### Basic Usage
[@yozora/tokenizer-admonition][] cannot be used alone, it needs to be registered in _YastParser_ as
a plugin-in before it can be used.
```typescript {4,9}
import { DefaultParser } 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 DefaultParser()
.useFallbackTokenizer(new ParagraphTokenizer())
.useFallbackTokenizer(new TextTokenizer())
.useTokenizer(new AdmonitionTokenizer())
// parse source markdown content
parser.parse(`
:::info this is a info type admonition
waw
### some block contents
:::
`)
```
### Use within [/parser][]
```typescript
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
:::
`)
```
### Use with [/parser-gfm][]
```typescript {2,5}
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
:::
`)
```
### Use within [/parser-gfm-ex][]
```typescript {2,5}
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 the `match-block` stage, a high-priority tokenizer can
interrupt the matching process of a low-priority tokenizer.
<!-- :end -->
### Node Type
```typescript
export interface Admonition extends Parent<'admonition'> {
type: 'admonition'
/**
* Keyword of an admonition.
*/
keyword: 'note' | 'important' | 'tip' | 'caution' | 'warning' | string
/**
* Admonition title.
*/
title: Node[]
/**
* Admonition body.
*/
children: Node[]
}
```
### Output Example
- positions omitted:
```json
{
"type": "admonition",
"keyword": "tip",
"title": [
{
"type": "text",
"value": "pro tip"
}
],
"children": [
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "admonition is awesome!\n"
}
]
}
]
}
```
## Related
- [/ast][]
- [/parser][]
- [/parser-gfm][]
- [/parser-gfm-ex][]
- [/react-admonition][]
- [/react-markdown][]
- [Live Examples][live-examples]
- [Admonition | Yozora AST][node-type]
- [Documentation][docpage]
[node-type]: http://yozora.guanghechen.com/docs/package/ast#admonition
<!-- :begin use tokenizer/definitions -->
[live-examples]: https://yozora.guanghechen.com/docs/package/tokenizer-admonition#live-examples
[docpage]: https://yozora.guanghechen.com/docs/package/tokenizer-admonition
[homepage]: https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/admonition#readme
[gfm-spec]: https://github.github.com/gfm
[mdast-homepage]: https://github.com/syntax-tree/mdast
[/ast]: https://github.com/yozorajs/yozora/tree/v2.3.13/packages/ast#readme
[/ast-util]: https://github.com/yozorajs/yozora/tree/v2.3.13/packages/ast-util#readme
[/character]: https://github.com/yozorajs/yozora/tree/v2.3.13/packages/character#readme
[/eslint-config]:
https://github.com/yozorajs/yozora/tree/release-2.x.x/packages/eslint-config#readme
[/core-parser]: https://github.com/yozorajs/yozora/tree/v2.3.13/packages/core-parser#readme
[/core-tokenizer]:
https://github.com/yozorajs/yozora/tree/v2.3.13/packages/core-tokenizer#readme
[/invariant]: https://github.com/yozorajs/yozora/tree/v2.3.13/packages/invariant#readme
[/jest-for-tokenizer]:
https://github.com/yozorajs/yozora/tree/release-2.x.x/packages/jest-for-tokenizer#readme
[/parser]: https://github.com/yozorajs/yozora/tree/v2.3.13/packages/parser#readme
[/parser-gfm]: https://github.com/yozorajs/yozora/tree/v2.3.13/packages/parser-gfm#readme
[/parser-gfm-ex]:
https://github.com/yozorajs/yozora/tree/v2.3.13/packages/parser-gfm-ex#readme
[/template-tokenizer]:
https://github.com/yozorajs/yozora/tree/release-2.x.x/packages/template-tokenizer#readme
[/tokenizer-admonition]:
https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/admonition#readme
[/tokenizer-autolink]:
https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/autolink#readme
[/tokenizer-autolink-extension]:
https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/autolink-extension#readme
[/tokenizer-blockquote]:
https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/blockquote#readme
[/tokenizer-break]: https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/break#readme
[/tokenizer-definition]:
https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/definition#readme
[/tokenizer-delete]: https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/delete#readme
[/tokenizer-ecma-import]:
https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/ecma-import#readme
[/tokenizer-emphasis]:
https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/emphasis#readme
[/tokenizer-fenced-block]:
https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/fenced-block#readme
[/tokenizer-fenced-code]:
https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/fenced-code#readme
[/tokenizer-footnote]:
https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/footnote#readme
[/tokenizer-footnote-definition]:
https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/footnote-definition#readme
[/tokenizer-footnote-reference]:
https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/footnote-reference#readme
[/tokenizer-heading]:
https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/heading#readme
[/tokenizer-html-block]:
https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/html-block#readme
[/tokenizer-html-inline]:
https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/html-inline#readme
[/tokenizer-image]: https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/image#readme
[/tokenizer-image-reference]:
https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/image-reference#readme
[/tokenizer-indented-code]:
https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/indented-code#readme
[/tokenizer-inline-code]:
https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/inline-code#readme
[/tokenizer-inline-math]:
https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/inline-math#readme
[/tokenizer-link]: https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/link#readme
[/tokenizer-link-reference]:
https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/link-reference#readme
[/tokenizer-list]: https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/list#readme
[/tokenizer-math]: https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/math#readme
[/tokenizer-paragraph]:
https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/paragraph#readme
[/tokenizer-setext-heading]:
https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/setext-heading#readme
[/tokenizer-table]: https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/table#readme
[/tokenizer-text]: https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/text#readme
[/tokenizer-thematic-break]:
https://github.com/yozorajs/yozora/tree/v2.3.13/tokenizers/thematic-break#readme
[/react-admonition]:
https://github.com/yozorajs/yozora-react/tree/main/packages/admonition#readme
[/react-blockquote]:
https://github.com/yozorajs/yozora-react/tree/main/packages/blockquote#readme
[/react-break]: https://github.com/yozorajs/yozora-react/tree/main/packages/break#readme
[/react-delete]: https://github.com/yozorajs/yozora-react/tree/main/packages/delete#readme
[/react-emphasis]:
https://github.com/yozorajs/yozora-react/tree/main/packages/emphasis#readme
[/react-code]: https://github.com/yozorajs/yozora-react/tree/main/packages/code#readme
[/react-code-live]:
https://github.com/yozorajs/yozora-react/tree/main/packages/code-live#readme
[/react-footnote-definitions]:
https://github.com/yozorajs/yozora-react/tree/main/packages/footnote-definitions#readme
[/react-footnote-reference]:
https://github.com/yozorajs/yozora-react/tree/main/packages/footnote-reference#readme
[/react-heading]: https://github.com/yozorajs/yozora-react/tree/main/packages/heading#readme
[/react-image]: https://github.com/yozorajs/yozora-react/tree/main/packages/image#readme
[/react-inline-code]:
https://github.com/yozorajs/yozora-react/tree/main/packages/inline-code#readme
[/react-inline-math]:
https://github.com/yozorajs/yozora-react/tree/main/packages/inline-math#readme
[/react-link]: https://github.com/yozorajs/yozora-react/tree/main/packages/link#readme
[/react-list]: https://github.com/yozorajs/yozora-react/tree/main/packages/list#readme
[/react-list-item]:
https://github.com/yozorajs/yozora-react/tree/main/packages/list-item#readme
[/react-markdown]:
https://github.com/yozorajs/yozora-react/tree/main/packages/markdown#readme
[/react-math]: https://github.com/yozorajs/yozora-react/tree/main/packages/math#readme
[/react-paragraph]:
https://github.com/yozorajs/yozora-react/tree/main/packages/paragraph#readme
[/react-strong]: https://github.com/yozorajs/yozora-react/tree/main/packages/strong#readme
[/react-table]: https://github.com/yozorajs/yozora-react/tree/main/packages/table#readme
[/react-text]: https://github.com/yozorajs/yozora-react/tree/main/packages/text#readme
[/react-thematic-break]:
https://github.com/yozorajs/yozora-react/tree/main/packages/thematic-break#readme
[doc-live-examples/gfm]: https://yozora.guanghechen.com/docs/example/gfm
[doc-/ast]: https://yozora.guanghechen.com/docs/package/ast
[doc-/ast-util]: https://yozora.guanghechen.com/docs/package/ast-util
[doc-/core-parser]: https://yozora.guanghechen.com/docs/package/core-parser
[doc-/core-tokenizer]: https://yozora.guanghechen.com/docs/package/core-tokenizer
[doc-/parser]: https://yozora.guanghechen.com/docs/package/parser
[doc-/parser-gfm]: https://yozora.guanghechen.com/docs/package/parser-gfm
[doc-/parser-gfm-ex]: https://yozora.guanghechen.com/docs/package/parser-gfm-ex
[doc-/tokenizer-admonition]: https://yozora.guanghechen.com/docs/package/tokenizer-admonition
[doc-/tokenizer-autolink]: https://yozora.guanghechen.com/docs/package/tokenizer-autolink
[doc-/tokenizer-autolink-extension]:
https://yozora.guanghechen.com/docs/package/tokenizer-autolink-extension
[doc-/tokenizer-blockquote]: https://yozora.guanghechen.com/docs/package/tokenizer-blockquote
[doc-/tokenizer-break]: https://yozora.guanghechen.com/docs/package/tokenizer-break
[doc-/tokenizer-delete]: https://yozora.guanghechen.com/docs/package/tokenizer-delete
[doc-/tokenizer-emphasis]: https://yozora.guanghechen.com/docs/package/tokenizer-emphasis
[doc-/tokenizer-fenced-code]:
https://yozora.guanghechen.com/docs/package/tokenizer-fenced-code
[doc-/tokenizer-heading]: https://yozora.guanghechen.com/docs/package/tokenizer-heading
[doc-/tokenizer-html-block]: https://yozora.guanghechen.com/docs/package/tokenizer-html-block
[doc-/tokenizer-html-inline]:
https://yozora.guanghechen.com/docs/package/tokenizer-html-inline
[doc-/tokenizer-image]: https://yozora.guanghechen.com/docs/package/tokenizer-image
[doc-/tokenizer-image-reference]:
https://yozora.guanghechen.com/docs/package/tokenizer-image-reference
[doc-/tokenizer-indented-code]:
https://yozora.guanghechen.com/docs/package/tokenizer-indented-code
[doc-/tokenizer-inline-code]:
https://yozora.guanghechen.com/docs/package/tokenizer-inline-code
[doc-/tokenizer-inline-math]:
https://yozora.guanghechen.com/docs/package/tokenizer-inline-math
[doc-/tokenizer-link]: https://yozora.guanghechen.com/docs/package/tokenizer-link
[doc-/tokenizer-definition]: https://yozora.guanghechen.com/docs/package/tokenizer-definition
[doc-/tokenizer-link-reference]:
https://yozora.guanghechen.com/docs/package/tokenizer-link-reference
[doc-/tokenizer-list]: https://yozora.guanghechen.com/docs/package/tokenizer-list
[doc-/tokenizer-math]: https://yozora.guanghechen.com/docs/package/tokenizer-math
[doc-/tokenizer-paragraph]: https://yozora.guanghechen.com/docs/package/tokenizer-paragraph
[doc-/tokenizer-setext-heading]:
https://yozora.guanghechen.com/docs/package/tokenizer-setext-heading
[doc-/tokenizer-table]: https://yozora.guanghechen.com/docs/package/tokenizer-table
[doc-/tokenizer-text]: https://yozora.guanghechen.com/docs/package/tokenizer-text
[doc-/tokenizer-thematic-break]:
https://yozora.guanghechen.com/docs/package/tokenizer-thematic-break
[doc-/jest-for-tokenizer]: https://yozora.guanghechen.com/docs/package/jest-for-tokenizer
[doc-/parser-gfm]: https://yozora.guanghechen.com/docs/package/parser-gfm
[gfm-atx-heading]: https://github.github.com/gfm/#atx-heading
[gfm-autolink]: https://github.github.com/gfm/#autolinks
[gfm-autolink-extension]: https://github.github.com/gfm/#autolinks-extension-
[gfm-blockquote]: https://github.github.com/gfm/#block-quotes
[gfm-bullet-list]: https://github.github.com/gfm/#bullet-list
[gfm-delete]: https://github.github.com/gfm/#strikethrough-extension-
[gfm-emphasis]: https://github.github.com/gfm/#can-open-emphasis
[gfm-fenced-code]: https://github.github.com/gfm/#fenced-code-block
[gfm-hard-line-break]: https://github.github.com/gfm/#hard-line-break
[gfm-html-block]: https://github.github.com/gfm/#html-block
[gfm-html-inline]: https://github.github.com/gfm/#raw-html
[gfm-image]: https://github.github.com/gfm/#images
[gfm-image-reference]: https://github.github.com/gfm/#example-590
[gfm-indented-code]: https://github.github.com/gfm/#indented-code-block
[gfm-inline-code]: https://github.github.com/gfm/#code-span
[gfm-link]: https://github.github.com/gfm/#inline-link
[gfm-definition]: https://github.github.com/gfm/#link-reference-definition
[gfm-link-reference]: https://github.github.com/gfm/#reference-link
[gfm-list]: https://github.github.com/gfm/#lists
[gfm-list-item]: https://github.github.com/gfm/#list-items
[gfm-list-task-item]: https://github.github.com/gfm/#task-list-items-extension-
[gfm-paragraph]: https://github.github.com/gfm/#paragraph
[gfm-setext-heading]: https://github.github.com/gfm/#setext-heading
[gfm-soft-line-break]: https://github.github.com/gfm/#soft-line-breaks
[gfm-strong]: https://github.github.com/gfm/#can-open-strong-emphasis
[gfm-tab]: https://github.github.com/gfm/#tabs
[gfm-table]: https://github.github.com/gfm/#table
[gfm-text]: https://github.github.com/gfm/#soft-line-breaks
[gfm-thematic-break]: https://github.github.com/gfm/#thematic-break
<!-- :end -->