Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@yozora/parser

yozorajs6.3kMIT2.3.12TypeScript support: included

A markdown parser with rich built-in tokenizers

markdown, markdown ast, markdown parser, gfm, gfm extensions

readme

Yozora
logo.png


See Yozora document (or https://yozorajs.github.io) for more details.

https://user-images.githubusercontent.com/42513619/129205123-6a1983c4-6a86-4c80-83d6-02bdbf70edbf.mp4


中文文档

🎉 Why named "yozora" ?

Yozora is the Roman sound of Japanese 「よぞら」, taken from the lyrics in『花鳥風月』 by the band 世界の終わり.

This project is a monorepo that aims to implement a highly extensible, pluggable Markdown parser. Based on the idea of middlewares, the core algorithm @yozora/core-parser will schedule tokenizers (such as @yozora/tokenizer-autolink) to complete the parsing tasks. More accurately, yozora is an algorithm to parse Markdown or its extended syntax contents into an abstract syntax tree (AST).

✨ Features

  • 🔖 Fully support all the rules mentioned in the GFM specification, and has passed almost all test cases created based on the examples in the specification (except the one https://github.github.com/gfm/#example-653, as there is no plan to support native HTML tags in the React Renderer, for the Yozora AST, so I'm a little lazy to do the tag filtering. If you need it, you can do the filtering by yourself).

    See @yozora/parser-gfm or @yozora/parser-gfm-ex for further information.

  • 🚀 Robust.

    • All codes are written in Typescript, with the guarantee of strictly static type checking.

    • Eslint and Prettier to constrain coding styles to avoid error-prone problems such as hack syntax and shadow variables.

    • Tested with Jest, and passed a large number of test cases.

  • 💚 Tidy: No third-party dependencies.

  • ⚡️ Efficient.

    • The parsing complexity is the length of source contents multiplied by the number of tokenizers, which has reached the lower bound of theoretical complexity.

    • The parser API supports streaming read-in (using generators /iterators for input), and supports parsing while read-in (Only block-level data is supported yet).

    • Carefully handle the array creation / concat operations. To reused the array as much as possible during the entire matching phase, only use the array index to delineate the matching range. And a lot of strategies applied to reduce duplicated matching / parsing operations.

  • 🩹 Compatibility, the parsed syntax tree is compatible with the one defined in Mdast.

    Even if some data types are not compatible in the future, it is easy to traverse the AST for adaptation and modification through the API provided in @yozora/ast-util.

  • 🎨 Extendibility, Yozora comes with a plug-in system, which allowed Yozora to schedule the tokenizers through an internal algorithms to complete the parsing tasks.

    • It's easy to create and integrate custom tokenizers.
    • All tokenizers can be mounted or unmounted freely.

      Some tokenizers of the data types that not mentioned in GFM have been implemented in this repository, such as @yozora/tokenizer-admonition, @yozora/tokenizer-footnote, etc. All of them are built into @yozora/parser in default, you can uninstall them at will, if you don't like it.

Usage

  • @yozora/parser: (Recommended) A Markdown parser with rich built-in tokenizers.

    import YozoraParser from '@yozora/parser'
    
    const parser = new YozoraParser()
    parser.parse('source content')
  • @yozora/parser-gfm: A Markdown parser that supports GFM specification. Built-in tokenizers that supports all grammars mentioned in GFM specification (excluding the extended grammar mentioned in the specification, such as table).

    import GfmParser from '@yozora/parser-gfm'
    
    const parser = new GfmParser()
    parser.parse('github flavor markdown contents')
  • @yozora/parser-gfm-ex: A Markdown parser that supports GFM specification. Built-in tokenizers that supports all grammars mentioned in GFM specification (including the extended grammar mentioned in the specification, such as table).

    import GfmExParser from '@yozora/parser-gfm-ex'
    
    const parser = new GfmExParser()
    parser.parse('github flavor markdown contents (with gfm extensions enabled)')
  • Content AST into markup content

    import { DefaultMarkupWeaver } from '@yozora/markup-weaver'
    
    const weaver = new DefaultMarkupWeaver()
    weaver.weave({
      "type": "root",
      "children": [
        {
          "type": "paragraph",
          "children": [
            {
              "type": "text",
              "value": "emphasis: "
            },
            {
              "type": "strong",
              "children": [
                {
                  "type": "text",
                  "value": "foo \""
                },
                {
                  "type": "emphasis",
                  "children": [
                    {
                      "type": "text",
                      "value": "bar"
                    }
                  ]
                },
                {
                  "type": "text",
                  "value": "\" foo"
                }
              ]
            }
          ]
        }
      ]
    })
    // => emphasis: **foo "*bar*" foo**

Overview

💡 FAQ

💬 Contact

📄 License

Yozora is MIT licensed.

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

2.3.12 (2025-02-26)

  • :bookmark: release: publish v2.3.10 (a36b4dd)
  • :bookmark: release: publish v2.3.11 (dcc0a95)
  • :bookmark: release: publish v2.3.8 (c4ddb8b)
  • :bookmark: release: publish v2.3.9 (d125df1)
  • chore: fix nx dependencies (d11d405)

2.3.11 (2025-01-13)

Note: Version bump only for package @yozora/parser

2.3.10 (2025-01-09)

  • chore: fix nx dependencies (d11d405)

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

2.3.9 (2024-12-05)

Note: Version bump only for package @yozora/parser

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

2.3.8 (2024-12-03)

  • :bookmark: release: publish v2.3.7 (ba79410)
  • :bug: fix(inline-math): the inline syntax wihtout backticks could be interruptted by emphasis/strong (c347f97)

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

2.3.7 (2024-11-06)

  • :bug: fix(inline-math): the inline syntax wihtout backticks could be interruptted by emphasis/strong (c347f97)

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

2.3.6 (2024-10-23)

Note: Version bump only for package @yozora/parser

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

2.3.5 (2024-10-06)

  • :bookmark: release: publish v2.3.3 (be6d159)
  • :bookmark: release: publish v2.3.4 (ac66f62)
  • :wrench: chore: fix nx config (139b132)
  • :wrench: chore: fix nx config (b8c4d73)
  • :wrench: chore: fix nx config (38c2325)

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

2.3.4 (2024-09-29)

Note: Version bump only for package @yozora/parser

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

2.3.3 (2024-09-20)

  • :wrench: chore: fix nx config (b8c4d73)
  • :wrench: chore: fix nx config (38c2325)

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

2.3.2 (2024-06-17)

Note: Version bump only for package @yozora/parser

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

2.3.1 (2024-01-30)

Performance Improvements

  • 🎨 support new parser option 'formatUrl' to resolve urls in the ast (#24) (a2c5ac8)
  • 🔧 use nx to simplify running commands on the monorepo (#25) (377a126)

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

2.3.0 (2023-09-18)

Performance Improvements

  • :fire: remove 'tsconfig.json's in sub packages (1e6a8b3)
  • ⬆️ upgrade devDependencies (0097a04)

2.2.0 (2023-08-21)

Performance Improvements

  • ⬆️ upgrade devDependencies (bc46ce2)

2.1.5 (2023-05-13)

Performance Improvements

  • 🔧 don't sourcemaps into tarball (fc37aa8)
  • 📝 update CHANGELOGs (c51b283)
  • ⬆️ upgrade dependencies (aa83988)

2.1.4 (2023-04-02)

Performance Improvements

  • 🔧 don't pack src/ folder into tarball (c9fac38)
  • 🔖 publish v2.1.4 (aa464ed)

2.1.3 (2023-03-23)

Performance Improvements

  • ⬆️ fix default export in cjs format bundle (16b5a30)
  • 🔖 publish v2.1.3 (9abaaff)

2.1.2 (2023-03-11)

Performance Improvements

2.1.1 (2023-03-10)

Performance Improvements

  • 🔖 publish v2.1.1 (257a36d)
  • ⬆️ upgrade devDependencies (8c7c2c6)

2.0.6 (2023-03-05)

Performance Improvements

  • 🔖 publish v2.0.6 (a263c53)
  • ⬆️ upgrade devDependencies (de6b465)

2.0.5 (2023-01-09)

Performance Improvements

2.0.5-alpha.0 (2023-01-05)

Performance Improvements

  • 🔧 fix test configuration (f50b2d7)
  • 🔖 publish v2.0.5-alpha.0 (8bf941f)
  • 🔧 update package entries (2c94f27)
  • ⬆️ upgrade devDependencies (13059a9)

2.0.4 (2022-11-02)

Performance Improvements

2.0.3 (2022-10-11)

Performance Improvements

2.0.2 (2022-09-24)

Performance Improvements

2.0.2-alpha.0 (2022-05-22)

Performance Improvements

  • 🔖 publish v2.0.2-alpha.0 (430eaab)

2.0.1 (2022-05-21)

Performance Improvements

  • ✅ refactor test utils & rename createTester to createTokenizerTester (7f2ce75)
  • 🔖 publish v2.0.1 (3aea330)
  • 🎨 tweak tokenizers (2e14175)

2.0.0 (2022-01-15)

Performance Improvements

2.0.0-alpha.3 (2022-01-12)

Performance Improvements

  • 🔖 publish v2.0.0-alpha.3 (9f274fc)

2.0.0-alpha.2 (2022-01-09)

Performance Improvements

  • ✅ add test for removePositions (967f3c6)
  • 🎨 refactor removePosition (87a974f)
  • 🔖 publish v2.0.0-alpha.2 (da59d85)

2.0.0-alpha.1 (2022-01-08)

Performance Improvements

  • 🎨 merge @yozora/tokenizer-list and @yozora/tokenizer-list-item (53e1f6a)
  • 🔖 publish v2.0.0-alpha.1 (86202e1)
  • 🔥 remove @yozora/tokenizer-list-item, please use @yozora/tokenizer-list directly (ee3307c)
  • 📝 update READMEs (320afeb)

2.0.0-alpha.0 (2022-01-03)

Features

  • 💥 [breaking] rename types with 'I' prefix (d37d862)

Performance Improvements

  • 💥 refactor block tokenizers (50ea4da)
  • 🔖 publish v2.0.0-alpha.0 (0171501)
  • 🎨 set print width to 100 (657a621)

1.3.0 (2021-10-09)

Performance Improvements

1.2.2 (2021-09-06)

Performance Improvements

1.2.1 (2021-09-04)

Performance Improvements

1.2.0 (2021-08-22)

Performance Improvements

1.2.0-alpha.1 (2021-08-16)

Performance Improvements

  • 🔖 publish v1.2.0-alpha.1 (ce3c173)

1.2.0-alpha.0 (2021-08-15)

Performance Improvements

  • 🔖 publish v1.2.0-alpha.0 (bd8ef45)

1.1.0 (2021-08-12)

Performance Improvements

1.1.0-alpha.2 (2021-08-07)

Performance Improvements

  • 🔖 publish v1.1.0-alpha.2 (d88b8ec)

1.1.0-alpha.1 (2021-08-01)

Performance Improvements

1.1.0-alpha.0 (2021-07-31)

Features

  • ✨ implement new tokenizer '@yozora/tokenizer-ecma-import' (7e4a1b1)

Performance Improvements

1.0.0 (2021-07-20)

Performance Improvements

1.0.0-beta.0 (2021-07-08)

Performance Improvements

  • 🔖 publish v1.0.0-beta.0 (bb66320)

1.0.0-1.0.0-beta.0.0 (2021-07-08)

Performance Improvements

  • 🔖 publish v1.0.0-1.0.0-beta.0.0 (4051dd2)
  • 📝 update READMEs (9d9f940)

1.0.0-alpha.29 (2021-07-08)

Performance Improvements

  • expose new utility func 'createTester' and 'createTesters' (a4e9613)
  • 🔖 publish v1.0.0-alpha.29 (f2291db)
  • 🎨 use path alias in tests (29cca94)

1.0.0-alpha.28 (2021-06-30)

Performance Improvements

  • 🔖 publish v1.0.0-alpha.28 (f18d90a)

1.0.0-alpha.27 (2021-06-28)

Bug Fixes

  • 🐛 FootnoteDefinitionTokenizer has priority over DefinitionTokenizer (a19084a)

Performance Improvements

  • 🔖 publish v1.0.0-alpha.27 (8efea07)
  • ⬆️ upgrade dev dependencies (d126ff4)

1.0.0-alpha.26 (2021-06-25)

Performance Improvements

  • 🔖 publish v1.0.0-alpha.26 (cbde29c)
  • 📝 update READMEs (11e4f61)

1.0.0-alpha.25 (2021-06-17)

Performance Improvements

  • 🔖 publish v1.0.0-alpha.25 (5e17f71)
  • ⚰️ remove delimiterGroup as we are no longer need it (e9de208)

1.0.0-alpha.24 (2021-06-10)

Performance Improvements

  • 🔖 publish v1.0.0-alpha.24 (6169f8e)

1.0.0-alpha.23 (2021-06-08)

Performance Improvements

  • Move repository from github.com/guanghechen to github.com/yozorajs (c1fd32c)
  • 🔖 publish v1.0.0-alpha.23 (131a216)
  • 📝 update READMEs (6420941)

1.0.0-alpha.22 (2021-05-20)

Performance Improvements

  • 📝 fix invalid link references (bee63ad)
  • 🔖 publish v1.0.0-alpha.22 (a07a41d)
  • 🔧 rename the main branch to 'main' instead of 'master' (c915653)

1.0.0-alpha.21 (2021-05-12)

Performance Improvements

  • 🔖 publish v1.0.0-alpha.21 (e6655a2)

1.0.0-alpha.20 (2021-04-20)

Performance Improvements

  • 🔖 publish v1.0.0-alpha.20 (3f3831f)

1.0.0-alpha.19 (2021-04-19)

Performance Improvements

1.0.0-alpha.18 (2021-04-18)

Features

  • ✨ implemented new tokenizer @yozora/tokenizer-definition-footnote & and built it into @yozora/parser (eb796f8)
  • ✨ implemented new tokenizer @yozora/tokenizer-definition-footnote & and built it into @yozora/parser & update tests (dad817f)
  • ✨ implemented new tokenizer @yozora/tokenizer-footnote & and built it into @yozora/parser (9def79e)

Performance Improvements

  • 🎨 support new member method 'replaceTokenizer' (67e7085)
  • 🔖 publish v1.0.0-alpha.18 (219b28b)

1.0.0-alpha.17 (2021-04-15)

Performance Improvements

  • :construction: [parser] feat: make wrapping backticks optional of inline-math in default (93cb009)
  • 🔖 publish v1.0.0-alpha.17 (0e7facd)
  • :whitespace_check_mark: udpate tests (6910b98)
  • 📝 update docs (acffd75)
  • ✅ update tests (1710d04)

1.0.0-alpha.16 (2021-04-12)

Features

  • 🚧 support preset definition (bd6a8bc)

Performance Improvements

  • ✅ collect all test cases in the scaffolds/jest-for-tokenizer/fixtures/ directory (a328ffd)
  • 🔖 publish v1.0.0-alpha.16 (9da34dd)
  • 📝 update READMEs (715a4f0)

1.0.0-alpha.15 (2021-04-11)

Performance Improvements

  • :bug: [math] fix: bad content positions of single line math (64eb8bf)
  • 🔖 publish v1.0.0-alpha.15 (988d25f)

1.0.0-alpha.14 (2021-04-11)

Features

  • ✨ implemented new parser @yozora/parser (de85088)
  • ✨ split gfm-ex parser to a new sub-package (c1737e8)

Performance Improvements