Kamiby Typo Monster
Docs

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.

Package overview

Package@kami/html-to-md
Version0.1.0
LicenseMIT
BundleESM + CJS (dual output via tsup)
Parserhtmlparser2 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:

FieldTypeDescription
titlestringPage title extracted from the H1 heading
markdownstringThe converted Markdown content
childPageLinksChildPageLink[]Links to child Notion pages ({ title, href })
imagesImageRef[]Image references ({ src, alt })
iconstring?Page emoji icon (e.g. "rocket")
coverImagestring?Cover image URL

ConvertOptions

OptionTypeDefaultDescription
includeTitlebooleantrueInclude 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