@abhi1264/fastmd
v1.0.2
Published
High-performance markdown parser for Node.js and the browser
Downloads
22
Readme
fastmd
High-performance markdown parser for Node.js and the browser (Rust/WASM core).
Build
pnpm install
pnpm build:wasm # build WASM (web + Node)
pnpm build # compile TS and copy WASM into packages/fastmd/distTest
pnpm test # unit tests; integration tests run when WASM is builtBenchmark
fastmd only:
pnpm build:wasm:node
pnpm benchCompare vs react-markdown and Bun’s native markdown:
- Build WASM:
pnpm build:wasm:node - Optional: install react-markdown for comparison:
pnpm add -D react-markdown react react-dom - Run comparison (Node):
pnpm bench:compare - Or run under Bun (uses Bun’s runtime; Bun’s native markdown is included if your Bun version exposes it):
bun run crates/fastmd-core/bench/compare.bench.ts
Same fixture and iteration count for all parsers; output is ops/sec so you can compare.
Usage
Node.js (sync, no init):
import { parseToTokens, renderHTML } from "@abhi1264/fastmd"
const tokens = parseToTokens("# Hello\n")
console.log(renderHTML(tokens, "# Hello\n")) // <h1>Hello</h1>Browser (async init once):
import initfastmd, { parseToTokens } from "@abhi1264/fastmd"
await initfastmd()
const tokens = parseToTokens("# Hello\n")See docs/INIT.md and docs/STREAMING.md.
Supported syntax
| Feature | Supported |
|--------|-----------|
| Headings (#–######) | ✅ |
| Bold (** / __) | ✅ |
| Italic (* / _) | ✅ |
| ~~Strikethrough~~ (~~) | ✅ |
| Code inline | ✅ |
| Fenced code blocks (```) with optional language | ✅ |
| Links | ✅ |
| Autolinks <https://…> | ✅ |
| Blockquotes (>) | ✅ |
| Unordered lists (- / * / +) | ✅ |
| Ordered lists (1. …) | ✅ |
| Horizontal rule (--- / ***) | ✅ |
Not supported: raw HTML, tables, task lists, definition lists, footnotes, front matter. Use a full CommonMark/GFM parser if you need those.
Render options
renderHTML(tokens, src, options) accepts:
linkTarget– e.g."_blank"for linksheadingIdPrefix– prefix for headingid(slug from text)codeClassPrefix– prefix for code block class (e.g."language-"for syntax highlighting)
React components (optional)
For custom React components per element (like react-markdown):
import { parseToTokens, renderToReact } from "@abhi1264/fastmd/react"
const tokens = parseToTokens("# Hi\n")
const nodes = renderToReact(tokens, "# Hi\n", {
a: (props) => <a {...props} target="_blank" />,
})Requires react as peer. Import from fastmd/react.
Token format
Parse returns a flat Uint32Array: 4 u32 per token [kind, start, end, aux]. Use tokensFromBuffer(buf) to get Token[], or parseToTokens(md) for the full string → tokens pipeline. start/end are UTF-16 code unit offsets for correct src.slice(start, end) in JS.
