@yozora/tokenizer-math

Tokenizer for processing fenced math block (formulas)

Usage no npm install needed!

<script type="module">
  import yozoraTokenizerMath from 'https://cdn.skypack.dev/@yozora/tokenizer-math';
</script>

README

@yozora/tokenizer-math


@yozora/tokenizer-math produce Math type nodes. See documentation for details.

Install

  • npm

    npm install --save @yozora/tokenizer-math
    
  • yarn

    yarn add @yozora/tokenizer-math
    

Usage

@yozora/tokenizer-math has been integrated into @yozora/parser, so you can use YozoraParser directly.

Basic Usage

@yozora/tokenizer-math cannot be used alone, it needs to be registered in YastParser 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 MathTokenizer from '@yozora/tokenizer-math'

const parser = new DefaultParser()
  .useFallbackTokenizer(new ParagraphTokenizer())
  .useFallbackTokenizer(new TextTokenizer())
  .useTokenizer(new MathTokenizer())

// parse source markdown content
parser.parse(`
$x^2 + y^2=z^2$

$
f(x)=\left\lbrace\begin{aligned}
&x^2, &x < 0\\
&0, &x = 0\\
&x^3, &x > 0
\end{aligned}\right.
$
`)

Use within @yozora/parser

import YozoraParser from '@yozora/parser'

const parser = new YozoraParser()

// parse source markdown content
parser.parse(`
$x^2 + y^2=z^2$

$
f(x)=\left\lbrace\begin{aligned}
&x^2, &x < 0\\
&0, &x = 0\\
&x^3, &x > 0
\end{aligned}\right.
$
`)

Use with @yozora/parser-gfm

import GfmParser from '@yozora/parser-gfm'
import MathTokenizer from '@yozora/tokenizer-math'

const parser = new GfmParser()
parser.useTokenizer(new MathTokenizer())

// parse source markdown content
parser.parse(`
$x^2 + y^2=z^2$

$
f(x)=\left\lbrace\begin{aligned}
&x^2, &x < 0\\
&0, &x = 0\\
&x^3, &x > 0
\end{aligned}\right.
$
`)

Use within @yozora/parser-gfm-ex

import GfmExParser from '@yozora/parser-gfm-ex'
import MathTokenizer from '@yozora/tokenizer-math'

const parser = new GfmExParser()
parser.useTokenizer(new MathTokenizer())

// parse source markdown content
parser.parse(`
$x^2 + y^2=z^2$

$
f(x)=\left\lbrace\begin{aligned}
&x^2, &x < 0\\
&0, &x = 0\\
&x^3, &x > 0
\end{aligned}\right.
$
`)

Options

Name Type Required Default
name string false "@yozora/tokenizer-math"
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.

Related