@clevertree/md2ast
v1.0.1
Published
Markdown → JSON AST for CleverScript / Relay hosts (WASM, JNI, Rust).
Readme
@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 --> JSONThis 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)
npm install @clevertree/md2astMaven (Android)
Add to your build.gradle:
dependencies {
implementation 'com.clevertree:md2ast:1.0.0'
}Cargo (Rust)
[dependencies]
md2ast = "1.0.0"Usage
Web (WASM)
import init, { parse_markdown } from '@clevertree/md2ast';
async function run() {
await init();
const markdown = "# Hello\n<CustomBox title=\"Alert\">Content</CustomBox>";
const options = {
allowed_tags: ["CustomBox"]
};
const ast = parse_markdown(markdown, options);
console.log(ast);
}Android (Kotlin)
val astJson = MarkdownParser.parse(markdown, allowedTags = listOf("CustomBox"))AST Structure
The output is a list of nodes:
[
{
"type": "element",
"tag": "h1",
"props": {},
"children": [
{ "type": "text", "content": "Hello" }
]
}
]License
MIT OR Apache-2.0
