Skip to main content

md-to-rich

Convert Markdown to HTML, ANSI terminal output, and Doc Tree

$ npm install md-to-rich
🌐

HTML Output

Convert Markdown to clean HTML with optional heading IDs, custom CSS class injection per element, GFM tables, task lists, and built-in URL sanitisation.

🖥

ANSI Terminal

Render Markdown in the terminal with ANSI escape codes. Fully themeable without chalk, with word-wrap, box-drawing tables, and OSC 8 hyperlink support.

🌲

Doc Tree

Parse Markdown into a typed JSON tree. Perfect for ProseMirror, Slate, Quill, and other rich-text editors. Flat inline marks — no nested AST wrangling.

See It In Action

import { toHtml } from 'md-to-rich'

const html = toHtml(`
# Welcome

A paragraph with **bold**, *italic*, and \`inline code\`.

> A blockquote

- Item one
- Item two
`, { headingIds: true, classNames: { p: 'prose' } })

// Output:
// <h1 id="welcome">Welcome</h1>
// <p class="prose">A paragraph with <strong>bold</strong>,
// <em>italic</em>, and <code>inline code</code>.</p>
// <blockquote><p>A blockquote</p></blockquote>
// <ul><li>Item one</li><li>Item two</li></ul>

Extensible by Design

The Serializer<T> interface is the only contract. Implement it to add any output format — plain text, Word count, PDF metadata — without touching this package. No inheritance, no registration, no boilerplate.

export interface Serializer<TOutput, TOptions = Record<never, never>> {
serialize(ast: Root, options: TOptions): TOutput
}

Read the Custom Serializer guide →