Skip to main content
Version: 2.x.x

@yozora/parser

Npm VersionNpm DownloadNpm LicenseModule formats: cjs, esmNode.js VersionTested with JestCode Style: prettier

A markdown parser with rich built-in tokenizers.

github flavor markdown spec

Install

npm install --save @yozora/parser

Usage

  • Basic

    import YozoraParser from '@yozora/parser'

    const parser = new YozoraParser()

    // parse markdown source content.
    parser.parse('source markdown content')

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

    // parse multiple markdown source content pieces.
    parser.parse(['source', 'contents'])
  • Use withing generator:

    import YozoraParser from '@yozora/parser'

    const parser = new YozoraParser()

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

    parser.parse(source())

Options

  • Constructor Options

    NameTypeRequiredDescription
    blockFallbackTokenizerBlockFallbackTokenizerfalseFallback tokenizer on processing block structure phase
    inlineFallbackTokenizerInlineFallbackTokenizerfalseFallback tokenizer on processing inline structure phase
    defaultParseOptionsParseOptionsfalseDefault options for parse()
  • ParseOptions

    NameTypeRequiredDescription
    shouldReservePositionbooleanfalseWhether it is necessary to reserve the position in the Node produced
    presetDefinitionsArray<Omit<Definition, 'type'>falsePreset definitions
    presetFootnoteDefinitionsArray<Omit<FootnoteDefinition, 'type'>falsePreset footnote definition

Overview

Live Examples

Thematic break

See @yozora/tokenizer-thematic-break for details.

  
  

ATX headings

See @yozora/tokenizer-heading for details.

  
  

Setext headings

See @yozora/tokenizer-setext-heading for details.

  
  

Indented code blocks

See @yozora/tokenizer-indented-code for details.

  
  

Fenced code blocks

See @yozora/tokenizer-fenced-code for details.

  
  

HTML blocks

See @yozora/tokenizer-html-block for details.

  
  

See @yozora/tokenizer-definition for details.

  
  

Paragraphs

See @yozora/tokenizer-paragraph for details.

  
  

Tables (extension)

See @yozora/tokenizer-table for details.

  
  

Block quotes

See @yozora/tokenizer-blockquote for details.

  
  

List items

See @yozora/tokenizer-list for details.

  
  

Task list items (extension)

See @yozora/tokenizer-list for details.

  
  

Lists

See @yozora/tokenizer-list for details.

  
  

Code spans

See @yozora/tokenizer-inline-code for details.

  
  

Emphasis and strong emphasis

See @yozora/tokenizer-emphasis for details.

  
  

Strikethrough (extension)

See @yozora/tokenizer-delete for details.

  
  

See @yozora/tokenizer-link for details.

  
  

See @yozora/tokenizer-link-reference for details.

  
  

Images

See @yozora/tokenizer-image for details.

  
  

Reference images

See @yozora/tokenizer-image-reference for details.

  
  

See @yozora/tokenizer-autolink for details.

  
  

See @yozora/tokenizer-autolink-extension for details.

  
  

Raw HTML

See @yozora/tokenizer-html-inline for details.

  
  

Hard line breaks

See @yozora/tokenizer-break for details.