@yozora/core-parser
TypeScript icon, indicating that this package has built-in type declarations

2.3.1 • Public • Published

@yozora/core-parser


Install

  • npm

    npm install --save @yozora/core-parser
  • yarn

    yarn add @yozora/core-parser

Usage

@yozora/core-parser provide a DefaultParser, which without any built-in tokenizers.

import { DefaultParser } from '@yozora/parser-gfm-ex'
import ParagraphTokenizer from '@yozora/tokenizer-paragraph'
import IndentedTokenizer from '@yozora/tokenizer-indented-code'
import InlineCodeTokenizer from '@yozora/tokenizer-inline-code'
import InlineMathTokenizer from '@yozora/tokenizer-inline-math'
import TextTokenizer from '@yozora/tokenizer-text'

const parser = new DefaultParser()
parser
  .useFallbackTokenizer(new ParagraphTokenizer())
  .useFallbackTokenizer(new TextTokenizer())
  .useTokenizer(new IndentedCodeTokenizer())
  .useTokenizer(new InlineMathTokenizer())
  .useTokenizer(new InlineCodeTokenizer())

parser.parse(
  'source markdown content',  // markdown source contents, `string|Iterable<string>`
  {},                         // ParseOptions, optional.
)

parser.parse(['source', 'contents'])

/**
 * String stream is supported through the iterator API.
 */
function* source () {
  yield 'hello',
  yield 'world',
}
parser.parse(source())

Options

  • Constructor Options

    Name Type Required Description
    blockFallbackTokenizer BlockFallbackTokenizer false Fallback tokenizer on processing block structure phase
    inlineFallbackTokenizer InlineFallbackTokenizer false Fallback tokenizer on processing inline structure phase
    defaultParseOptions ParseOptions false Default options for parse()
  • Parse Options

    Name Type Required Description
    shouldReservePosition boolean false Whether it is necessary to reserve the position in the Node produced
    presetDefinitions Array<Omit<Definition, 'type'> false Preset definitions
    presetFootnoteDefinitions Array<Omit<FootnoteDefinition, 'type'> false Preset footnote definitions

Related

Readme

Keywords

none

Package Sidebar

Install

npm i @yozora/core-parser

Weekly Downloads

2

Version

2.3.1

License

MIT

Unpacked Size

179 kB

Total Files

8

Last publish

Collaborators

  • lemonclown