@markitdownjs/ast
v0.1.2
Published
Unified AST types and renderers for MarkItDownJS
Readme
@markitdownjs/ast
AST utilities and multi-format renderers for MarkItDownJS. Convert a DocumentNode AST to Markdown, HTML, plain text, or JSON.
Install
npm install @markitdownjs/astUsage
import { MarkdownRenderer, HtmlRenderer } from "@markitdownjs/ast";
const md = new MarkdownRenderer().render(documentNode);
const html = new HtmlRenderer().render(documentNode);Key Exports
Renderers
| Export | Output format |
|---|---|
| MarkdownRenderer | GitHub-flavored Markdown |
| HtmlRenderer | Semantic HTML5 |
| PlaintextRenderer | Stripped plain text |
| JsonRenderer | Serialized AST as JSON |
All renderers implement the same interface:
interface Renderer {
render(node: DocumentNode): string;
}Utilities
| Export | Description |
|---|---|
| AstUtils | Traverse, query, and transform DocumentNode trees |
import { AstUtils } from "@markitdownjs/ast";
const headings = AstUtils.selectAll(documentNode, "HeadingNode");
const text = AstUtils.extractText(documentNode);Renderer Options
const renderer = new HtmlRenderer({ includeIds: true, wrapInDocument: false });
const html = renderer.render(documentNode);Part of the MarkItDownJS monorepo.
