npm Library
Use the @kami/html-to-md converter in your own JavaScript or TypeScript project.
The core conversion engine is available as an open-source npm package. It works in Node.js, Cloudflare Workers, Deno, Bun, and any JavaScript runtime — no DOM required.
Installation
Install the package and convert your first file.
Supported Blocks
See which Notion blocks are converted.
Package overview
| Package | @kami/html-to-md |
| Version | 0.1.0 |
| License | MIT |
| Bundle | ESM + CJS (dual output via tsup) |
| Parser | htmlparser2 SAX (streaming, no DOM) |
Quick example
typescript
import { notionHtmlToMarkdown } from "@kami/html-to-md";
import { readFileSync } from "fs";
const html = readFileSync("notion-export.html", "utf-8");
const markdown = notionHtmlToMarkdown(html);
console.log(markdown);Exports
The package exports two main APIs:
notionHtmlToMarkdown(html, options?)
One-shot convenience function. Takes an HTML string and returns clean Markdown.
typescript
const markdown = notionHtmlToMarkdown(html);NotionHtmlConverter
Class-based API for reuse with shared options:
typescript
import { NotionHtmlConverter } from "@kami/html-to-md";
const converter = new NotionHtmlConverter({ includeTitle: false });
const result = converter.convert(html);
console.log(result.title); // "My Page"
console.log(result.markdown); // "## Section one\n\n..."
console.log(result.images); // [{ src: "img.png", alt: "diagram" }]ConvertResult
The convert() method returns a result object with metadata:
| Field | Type | Description |
|---|---|---|
title | string | Page title extracted from the H1 heading |
markdown | string | The converted Markdown content |
childPageLinks | ChildPageLink[] | Links to child Notion pages ({ title, href }) |
images | ImageRef[] | Image references ({ src, alt }) |
icon | string? | Page emoji icon (e.g. "rocket") |
coverImage | string? | Cover image URL |
ConvertOptions
| Option | Type | Default | Description |
|---|---|---|---|
includeTitle | boolean | true | Include the page title as an H1 heading in the output |
Why SAX?
The converter uses a streaming SAX parser (htmlparser2) instead of building a DOM tree. This means:
- No DOM dependency — works in Cloudflare Workers and other edge runtimes
- Low memory — processes HTML as a stream, no full document in memory
- Fast — single-pass parsing with minimal allocations
Next steps
- Installation — install and run your first conversion
- Supported Blocks — full list of converted elements