Skip to main content

Introduction

A modern markdown parser built for TypeScript that handles both complete documents and incremental streaming content. Perfect for parsing LLM markdown streams, building documentation sites, or rendering user-generated content.

Installation

Get started with npm, yarn, or pnpm in seconds

Quick start

Parse your first markdown in under 5 minutes

API reference

Explore the complete API documentation

React integration

Render markdown with React Server Components

Why markdown-parser?

Streaming support

Built-in support for incremental parsing. Feed growing input and emit only finalized blocks - ideal for LLM streams.

CommonMark compliant

100% support for the CommonMark specification plus GitHub Flavored Markdown tables.

Fully typed

Complete TypeScript types for all nodes and API methods. Get autocomplete and type safety out of the box.

React ready

Optional React package for server-side rendering with customizable components.

Features

Block nodes

Supports all CommonMark block-level elements:
  • Headings (ATX and setext style)
  • Paragraphs
  • Code blocks (fenced and indented)
  • Thematic breaks (horizontal rules)
  • HTML blocks
  • Blockquotes
  • Lists (ordered and unordered)
  • Link reference definitions
  • Tables (GitHub Flavored Markdown)

Inline nodes

Full support for inline formatting:
  • Text and code spans
  • Hard and soft breaks
  • Inline HTML
  • Autolinks, links, and images
  • Emphasis and strong emphasis

How it works

The parser converts markdown text into a structured, fully-typed AST (Abstract Syntax Tree) of block and inline nodes. You can parse complete documents or use streaming mode to handle incremental content:
import { MarkdownParser } from "markdown-parser";

const parser = new MarkdownParser();

// Parse complete markdown
const nodes = parser.parse("# Hello World\nThis is a paragraph.");
In streaming mode, the parser maintains internal state across calls and returns only blocks that have been finalized since the last parse:
// Parse incrementally as content arrives
const partialNodes = parser.parse("# Hello World\nThis", { stream: true });
// Returns: [{ type: "heading", level: 1, children: [...] }]

const moreNodes = parser.parse(" is a paragraph.\n\n", { stream: true });
// Returns: [{ type: "paragraph", children: [...] }]
When streaming is enabled, link references might not resolve immediately since their definitions could arrive in later chunks.

Next steps

Install the package

Choose your package manager and install markdown-parser

Follow the quickstart

Parse your first markdown document in minutes

Build docs developers (and LLMs) love