@clevertree/md2ast
Markdown → JSON AST for CleverScript / Relay hosts (WASM, JNI, Rust).
Architecture
graph TD
subgraph "Input"
MD[Markdown Source]
end
subgraph "Parser Core (Rust)"
CM[pulldown-cmark]
HTML[HTML Tag Filter]
AST[AST Generator]
end
subgraph "Output"
JSON[JSON AST]
end
MD --> CM
CM --> HTML
HTML --> AST
AST --> JSON
This library parses Markdown (including GitHub Flavored Markdown) and converts it into a JSON-serializable Abstract Syntax Tree (AST) for CleverScript, Relay, React, or other JSX-like runtimes.
Features
- Fast: Powered by Rust and
pulldown-cmark. - Cross-Platform: WASM for Web, JNI for Android.
- HTML Support: Supports nested HTML tags within Markdown.
- Custom Tag Filtering: Only renders HTML tags explicitly allowed in
allowed_tags. - GFM Support: Tables, task lists, and strikethrough enabled by default.
Installation
NPM (Web)
Maven (Android)
Add to your build.gradle:
dependencies
Cargo (Rust)
[]
= "1.0.0"
Usage
Web (WASM)
import init from '@clevertree/md2ast';
Android (Kotlin)
val astJson = MarkdownParser.parse(markdown, allowedTags = listOf("CustomBox"))
AST Structure
The output is a list of nodes:
License
MIT OR Apache-2.0