@yozora/tokenizer-delete
GFM enables the strikethrough extension, where an additional emphasis type is available.
Strikethrough text is any text wrapped in two tildes (~
).
- See github flavor markdown spec for details.
- See Live Examples for an intuitive impression.
Install
- npm
- Yarn
- pnpm
npm install --save @yozora/tokenizer-delete
yarn add @yozora/tokenizer-delete
pnpm add @yozora/tokenizer-delete
Usage
@yozora/tokenizer-delete has been integrated into @yozora/parser / @yozora/parser-gfm-ex,
so you can use YozoraParser
/ GfmExParser
directly.
- Basic Usage
- YozoraParser
- GfmParser
- GfmExParser
@yozora/tokenizer-delete 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 DeleteTokenizer from '@yozora/tokenizer-delete'
const parser = new DefaultYastParser()
.useBlockFallbackTokenizer(new ParagraphTokenizer())
.useInlineFallbackTokenizer(new TextTokenizer())
.useTokenizer(new DeleteTokenizer())
// parse source markdown content
parser.parse(`
This ~~has a
new paragraph~~.
`)
import YozoraParser from '@yozora/parser'
const parser = new YozoraParser()
// parse source markdown content
parser.parse(`
This ~~has a
new paragraph~~.
`)
import GfmParser from '@yozora/parser-gfm'
import DeleteTokenizer from '@yozora/tokenizer-delete'
const parser = new GfmParser()
parser.useTokenizer(new DeleteTokenizer())
// parse source markdown content
parser.parse(`
This ~~has a
new paragraph~~.
`)
import GfmExParser from '@yozora/parser-gfm-ex'
const parser = new GfmExParser()
// parse source markdown content
parser.parse(`
This ~~has a
new paragraph~~.
`)
Options
Name | Type | Required | Default |
---|---|---|---|
name | string | false | "@yozora/tokenizer-delete" |
priority | number | false | TokenizerPriority.CONTAINING_INLINE |
-
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.Exception: Delimiters of type
full
are always processed before other type delimiters.
Types
@yozora/tokenizer-delete produce Delete type nodes. See @yozora/ast for full base types.
import type { YastParent } from '@yozora/ast'
export const DeleteType = 'delete'
export type DeleteType = typeof DeleteType
/**
* Delete represents contents that are no longer accurate or no longer relevant.
* @see https://github.com/syntax-tree/mdast#delete
* @see https://github.github.com/gfm/#strikethrough-extension-
*/
export type Delete = YastParent<DeleteType>
Live Examples
-
Basic.
-
As with regular emphasis delimiters, a new paragraph will cause strikethrough parsing to cease.