@yozora/tokenizer-inline-math
A backtick string is a string of one or more backtick
characters (`
) that is neither preceded nor followed by a backtick.
A inline math begins with a backtick string + $
and ends with a $
+ backtick string of equal length. The
contents of the inline math are the characters between the two $
character,
normalized in the following ways:
-
First, line endings are converted to spaces.
-
If the resulting string both begins and ends with a space character, but does not consist entirely of space characters, a single space character is removed from the front and back. This allows you to include code that begins or ends with backtick characters, which must be separated by whitespace from the opening or closing backtick strings.
- See Live Examples for an intuitive impression.
Install
- npm
- Yarn
- pnpm
npm install --save @yozora/tokenizer-inline-math
yarn add @yozora/tokenizer-inline-math
pnpm add @yozora/tokenizer-inline-math
Usage
@yozora/tokenizer-inline-math has been integrated into @yozora/parser,
so you can use YozoraParser
directly.
- Basic Usage
- YozoraParser
- GfmParser
- GfmExParser
@yozora/tokenizer-inline-math 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 InlineMathTokenizer from '@yozora/tokenizer-inline-math'
const parser = new DefaultYastParser()
.useBlockFallbackTokenizer(new ParagraphTokenizer())
.useInlineFallbackTokenizer(new TextTokenizer())
.useTokenizer(new InlineMathTokenizer())
// parse source markdown content
parser.parse("`$x^2 + y^2 = z^2, x < 0$`")
import YozoraParser from '@yozora/parser'
const parser = new YozoraParser()
// parse source markdown content
parser.parse("`$x^2 + y^2 = z^2, x < 0$`")
import GfmParser from '@yozora/parser-gfm'
import InlineMathTokenizer from '@yozora/tokenizer-inline-math'
const parser = new GfmParser()
parser.useTokenizer(new InlineMathTokenizer())
// parse source markdown content
parser.parse("`$x^2 + y^2 = z^2, x < 0$`")
import GfmExParser from '@yozora/parser-gfm-ex'
import InlineMathTokenizer from '@yozora/tokenizer-inline-math'
const parser = new GfmExParser()
parser.useTokenizer(new InlineMathTokenizer())
// parse source markdown content
parser.parse("`$x^2 + y^2 = z^2, x < 0$`")
Options
Name | Type | Required | Default |
---|---|---|---|
name | string | false | "@yozora/tokenizer-inline-math" |
priority | number | false | TokenizerPriority.ATOMIC |
-
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-inline-math produce InlineMath type nodes. See @yozora/ast for full base types.
import type { YastLiteral } from '@yozora/ast'
export const InlineMathType = 'inlineMath'
export type InlineMathType = typeof InlineMathType
/**
* Inline math content.
*/
export type InlineMath = YastLiteral<InlineMathType>
Live Examples
-
Basic.
#1yozorapretty-json