Skip to main content

Getting Started

Install​

npm install md-to-rich

Requires Node.js ≥ 20.


Quick Start​

import { toHtml, toAnsi, toDocTree } from 'md-to-rich'

// Markdown → HTML string
toHtml('# Hello\n\n**bold**')
// → '<h1 id="hello">Hello</h1><p><strong>bold</strong></p>'

// Markdown → ANSI terminal string
toAnsi('# Hello\n\n**bold**', { columns: 80 })
// → ANSI-escaped terminal output

// Markdown → structured JSON tree
toDocTree('# Hello')
// → { type: 'document', children: [{ type: 'heading', depth: 1, ... }] }

Sub-path Imports​

Import only the serializer you need to keep your bundle lean:

// HTML only
import { toHtml } from 'md-to-rich/html'

// ANSI only
import { toAnsi } from 'md-to-rich/ansi'

// Doc Tree only
import { toDocTree } from 'md-to-rich/doc-tree'

All four sub-paths are also available from the main entry:

import { toHtml, toAnsi, toDocTree, serialize } from 'md-to-rich'

ESM and CJS​

md-to-rich ships dual ESM and CJS output with full TypeScript declarations per entry point.

EnvironmentImport
ESM (Node, bundlers, Deno)import { toHtml } from 'md-to-rich'
CJS (CommonJS)const { toHtml } = require('md-to-rich')

Next Steps​