Skip to content
yozorajsPublic

About

A customizable markup parser for resolving markdown-like syntax strings into AST and vice versa.

Topics

Resources

Contributing

Stars

156 stars

Watchers

3 watching

Forks

Latest commit

 

History

1,645 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


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

yozora.demo.mp4

中文文档

🎉 Why is it named "Yozora"?

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

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

✨ Features

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

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

  • 🚀 Robust.

    • All code is written in TypeScript, with strict static type checking.

    • ESLint and Prettier constrain coding styles to avoid error-prone problems such as hacky syntax and shadowed variables.

    • Tested with Vitest and a large number of test cases.

  • 💚 Tidy: No third-party runtime dependencies.

  • ⚡️ Efficient.

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

    • The parser API supports streaming input (using generators/iterators), and supports parsing while reading (currently only block-level data is supported).

    • Array creation and concatenation are handled carefully. Arrays are reused as much as possible during the entire matching phase, and array indexes delineate matching ranges. Several strategies are also applied to reduce repeated matching and 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.

  • 🎨 Extensibility: Yozora comes with a plugin system that allows it to schedule tokenizers through an internal algorithm to complete the parsing tasks.

    • It's easy to create and integrate custom tokenizers.

    • All tokenizers can be mounted or unmounted freely.

      Some tokenizers for data types 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 by default; you can uninstall them at will if you don't like them.

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 the GFM specification. Built-in tokenizers support all grammars mentioned in the 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 Flavored Markdown content')
  • @yozora/parser-gfm-ex: A Markdown parser that supports the GFM specification. Built-in tokenizers support all grammars mentioned in the 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 Flavored Markdown content with extensions')
  • Convert an 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.

Related

About

A customizable markup parser for resolving markdown-like syntax strings into AST and vice versa.

Topics

Resources

Contributing

Stars

156 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages