v2.0.0

pardnchiu/NanoMD

Last updated

[!NOTE] This README was generated by SKILL, get the ZH version from here.


FAST MARKDOWN TO AST AND HTML IN ONE PARSER!

npm Downloads License


A TypeScript Markdown parser with a JSON AST, on-demand Mermaid/KaTeX/Chart.js rendering, and sanitized HTML output

Table of Contents

Features

npm i @pardnchiu/nanomd · Documentation · v1 Deprecation · Docs Site

v1 vs v2

The same sample document, repeated to each size, rendered to HTML in headless Chrome; runs over 15 seconds are recorded as timeouts, and their ratios use 15 seconds as a lower bound.

Size v1.11.6 MDParser().parse() v2 Parse().html() Speedup
4.4 KB 2.6 ms 0.4 ms 7×
44.3 KB 29.6 ms 1.8 ms 16×
443.4 KB 1,790 ms 17.7 ms 101×
1.08 MB 11,037 ms 47.4 ms 233×
2.16 MB Timeout 82.3 ms 182× or more
4.33 MB Timeout 156.4 ms 96× or more

Architecture

Full Architecture

graph LR
    Input[Markdown text] --> Block[Block parsing ParseLines]
    Block --> Inline[Inline parsing ParseInline]
    Inline --> Post[Footnote and link-ref post-processing]
    Post --> AST[AST]
    AST --> HTML["AST.html()"]
    AST --> Native["Native rendering iOS/Flutter (build your own)"]
    HTML --> Refresh["Refresh() dependency rendering"]
    Init["Init() loads dependencies"] --> Refresh

License

This project is licensed under the MIT LICENSE.

Author

Just open an issue to share an idea.

NanoMD contributors

©️ 2024 邱敬幃 Pardn Chiu

中文