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

Package detail

@yozora/core-parser

yozorajs6.4kMIT2.3.12TypeScript support: included

null

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/core-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/core-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)
  • :white_check_mark: test: fix tests (dd9c762)

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)

  • :white_check_mark: test: fix tests (dd9c762)

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/core-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 lint (224e248)
  • :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/core-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 lint (224e248)
  • :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/core-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)

2.2.0 (2023-08-21)

Performance Improvements

2.1.5 (2023-05-13)

Performance Improvements

  • 🔧 don't sourcemaps into tarball (fc37aa8)
  • 📝 update CHANGELOGs (c51b283)

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

2.1.2 (2023-03-11)

Performance Improvements

2.1.1 (2023-03-10)

Performance Improvements

2.0.6 (2023-03-05)

Performance Improvements

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

  • 🔖 publish v2.0.3 (8cc8f95)
  • 🔧 update build script (d934cad)
  • ⬆️ upgrade devDependencies (0f93641)

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

2.0.0 (2022-01-15)

Performance Improvements

  • 💥 [breaking] rename 'NodePoint' and 'NodePosition' (76692a2)
  • 🎨 move 'createPhrasingLineGenerator' from @yozora/core-tokenizer to @yozora/core-parser (f2d5ab4)
  • 🔖 publish v2.0.0 (65e99d1)
  • 📝 update READMEs (d6e6eeb)

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

Features

  • 💥 [breaking] remove 'I' prefix for AST node types (cad4b0b)
  • 💥 [breaking] remove 'IYastNode' prefix for AST types (35c8fd2)

Performance Improvements

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

Performance Improvements

  • 💥 refactor IParseBlockPhaseApi, use processInlines instead buildPhrasingContent and parsePhrasingContent (0715e39)
  • 🎨 refactor parse-inline hooks (455cfbd)
  • 🎨 refactor removePosition (87a974f)
  • 🔖 publish v2.0.0-alpha.2 (da59d85)
  • 🎨 remove PhrasingContentTokenizer (processInline throw hook api directly) (d69d884)
  • 🔥 remove unused codes (4e8b719)
  • 🎨 rewrite removePositions (427b6c2)
  • 🎨 simplify codes (0712473)

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

Features

  • :breaking: refactor parse-block hooks (117104d)

Performance Improvements

  • 🎨 add removePositions (0bc66ba)
  • 🔖 publish v2.0.0-alpha.1 (86202e1)
  • 🔥 remove @yozora/tokenizer-list-item, please use @yozora/tokenizer-list directly (ee3307c)
  • 🔥 remove post-match-block lifecycle (747a693)
  • 📝 update READMEs (320afeb)

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

Bug Fixes

Features

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

Performance Improvements

  • 💥 refactor block tokenizers (50ea4da)
  • 🎨 refactor eatOptionalBlankLines (f55552e)
  • 💥 refactor inline tokenizers (85e2d65)
  • 🔖 publish v2.0.0-alpha.0 (0171501)
  • 🎨 rename parser hooks (ef6cbc5)
  • 🎨 set print width to 100 (657a621)
  • 🎨 simplify codes (b531940)
  • 🎨 simplify codes & fix logic errors (c704cce)

1.3.0 (2021-10-09)

Features

  • 💥 move func parameter nodePoints to api.getNodePoints() (6bbfd4e)
  • 💥 move func parameter nodePoints to api.getNodePoints() (10e5033)

Performance Improvements

  • 🔖 publish v1.3.0 (18c9b16)
  • 🎨 set the default children to empty array instead of undefined (8fe26ca)

1.2.2 (2021-09-06)

Performance Improvements

1.2.1 (2021-09-04)

Bug Fixes

  • 🐛 The first child of footnote could have higher priority (c6f947f)

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)

Bug Fixes

  • 🐛 fix logic errors in shallowMutateAstInPreorder (0705bc6)

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)

Features

  • 💥 [BREAKING] change the timing of collecting definition identifiers and footnote definition identifiers (405382c)

Performance Improvements

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

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

Performance Improvements

  • 🔖 publish v1.1.0-alpha.1 (0d6aa91)

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

Performance Improvements

  • 🔖 publish v1.1.0-alpha.0 (082653e)

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)
  • ⚡️ remove unnecessary slice operations (c389b98)
  • 📝 update READMEs (9d9f940)

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

Performance Improvements

  • 🔖 publish v1.0.0-alpha.29 (f2291db)

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

Bug Fixes

  • 🐛 missing internal tokens when calling isDelimiterPair (e5a3b2f)

Performance Improvements

  • 🔖 publish v1.0.0-alpha.28 (f18d90a)
  • 🎨 rename variable names (use terminal 'internal' instead of 'inner') (b374c26)

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

Performance Improvements

  • ⚰️ remove dead codes (5e223d8)
  • 🎨 update base abstract tokenizer (cca9dd6)
  • ✅ update tests (9917315)
  • 🔖 publish v1.0.0-alpha.27 (8efea07)
  • ⬆️ upgrade dev dependencies (d126ff4)
  • 🎨 use @yozora/invariant instead of tiny-invariant (78723ba)

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

Performance Improvements

  • 🔖 publish v1.0.0-alpha.26 (cbde29c)

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

Bug Fixes

  • 🐛 fix GFM#588 (7b8d430)
  • 🐛 resolve closer delimiter when there is no closer delimiter in the front (d399e14)
  • 🐛 rewrite bad pairing logic (eba796d)
  • 🐛 there are no non-text token constitutes children of autolink or autolink-extension (7125cbc)

Performance Improvements

  • 🔖 publish v1.0.0-alpha.25 (5e17f71)
  • ⚰️ remove delimiterGroup as we are no longer need it (e9de208)
  • ⚡️ rewrite algorithm for processing inline tokens (d7b1138)
  • 💩 rewrite LinkReferenceTokenizer (319f4db)
  • 🎨 tokenizer-footnote should take same priority with images and link (7aaf02f)
  • 🎨 update interface types (755d774)

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)
  • 🎨 lint codes (0d2d798)
  • 🔖 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)

Bug Fixes

  • 🐛 remove the position from the root node of ast when shouldReservePosition is set to false (8f98f3b)

Performance Improvements

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

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

Performance Improvements

  • :construction: [ast-util] feat: update ast utility funcs (f9ac6c9)
  • 🔖 publish v1.0.0-alpha.20 (3f3831f)

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

Features

  • 💥 remove meta from Yozora Ast Root, provider util funcs in @yozora/ast-util for handling this instead (c90c8a9)

Performance Improvements

  • 🔖 publish v1.0.0-alpha.19 (50b55f9)
  • 📝 update READMEs (c6c6364)

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

Features

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

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

  • 🔖 publish v1.0.0-alpha.17 (0e7facd)

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

Features

  • 🚧 support preset definition (bd6a8bc)

Performance Improvements

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

Performance Improvements

  • 🔖 publish v1.0.0-alpha.15 (988d25f)

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

Performance Improvements

  • 🔖 publish v1.0.0-alpha.14 (3fcfffa)
  • 🎨 rename isContainerBlock to isContainingBlock & use enum TokenizerPriority instead of magic numbers to present tokenizer priority (940c50b)
  • 🎨 support to specify which tokenizer to register before (e8607f4)
  • 🎨 tweak parser interfaces (218008e)

1.0.0-alpha.13 (2021-04-10)

Features

  • ✨ implemented @yozora/tokenizer-admonition & add tests (a1880cd)

Performance Improvements

  • :art: [core-parser] improve: enhance ParseBlockPhaseApi to support parsing inlines in the parse-block phase (75e67bd)
  • :zap: [core-parser] improve: rewrite parse logic, use generator api to support stream contents (9424e99)
  • 🎨 add api for match-block phase & remove TokenizerContext (5a387ee)
  • 🎨 add api for match-inline and parse-inline phase (150231a)
  • 🎨 add api for parse-block phase (b266352)
  • 🎨 add api for post-match-block phase (7a9af93)
  • 🔖 publish v1.0.0-alpha.13 (949455c)
  • 💥 remove parse-meta phase (calc meta such as definitions after parse-block). (463e751)

1.0.0-alpha.12 (2021-03-27)

Features

  • 💥 redesign interfaces & refactor tokenizer codes with types from @yozora/ast (af3603d)

Performance Improvements

  • 🎨 make '_tokenizer' optional in the result of tokenizers on match phase (b1ea8de)
  • 🔖 publish v1.0.0-alpha.12 (897f131)
  • 🎨 use AST types from @yozora/ast instead of @yozora/core-tokenizer (fc55ceb)
  • 🎨 use types defined in @yozora/ast & use tokenizerName as unique id of token (d51f022)

1.0.0-alpha.11 (2021-03-20)

Performance Improvements

  • 🔖 publish v1.0.0-alpha.11 (df10f73)

1.0.0-alpha.10 (2021-03-20)

Bug Fixes

  • 🐛 add missed url of Definition Meta & update tests (886ca13)

Performance Improvements

  • 🔖 publish v1.0.0-alpha.10 (dbd0114)

1.0.0-alpha.9 (2021-03-20)

Performance Improvements

  • 📝 fix invalid badge urls (4d78b23)
  • 🔖 publish v1.0.0-alpha.9 (1b41b56)

1.0.0-alpha.8 (2021-03-13)

Performance Improvements

  • 🔖 publish v1.0.0-alpha.8 (3cb3080)
  • 📝 update badges (418e221)
  • 🔧 update configs & lint codes (3e9ded3)
  • 🔧 update package.json (cba99c5)
  • 📝 update READMEs (188b30b)

1.0.0-alpha.7 (2021-03-06)

Performance Improvements

  • 🎨 format codes (c3f0023)
  • 🎨 format codes (1fbd596)
  • 🔧 add directory in repository field (8daefc9)
  • 📝 update badges (967819b)
  • 🔖 publish v1.0.0-alpha.7 (115ce36)
  • 🔧 update scripts field (72841c5)
  • 🔧 use @guanghechen/rollup-config instead of @barusu/rollup-config (6228c33)
  • 🔨 use top level rollup.config.js (818c59b)

1.0.0-alpha.6 (2021-02-25)

Performance Improvements

  • 🔖 publish v1.0.0-alpha.6 (e4f20f7)
  • 🚚 rename @yozora/parser-core to @yozora/core-parser (e94956f)
  • ⬆️ upgrade @barusu/* to v0.0.47 & upgrade rollup to v2.39.1 (173b431)