Skip to main content
Version: 3.x.x 🚧

@yozora/parser-gfm

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

A markdown parser with built-in tokenizers to fully support GFM (without GFM extensions).

github flavor markdown spec

Install

npm install --save @yozora/parser-gfm

Usage

  • Basic

    import GfmParser from '@yozora/parser-gfm'

    const parser = new GfmParser()

    // 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 GfmParser from '@yozora/parser-gfm'

    const parser = new GfmParser()

    /**
    * 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 YastNode 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.

  
  

Soft line breaks

See @yozora/tokenizer-break for details.

  
  

Textual content

See @yozora/tokenizer-text for details.