turndown

Convert HTML into clean, customizable Markdown in Node.js and the browser.

Library
npm
v7.2.4
11,482 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
75 /100 Good
Development Activity 76
Maintenance 52
Community 72
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
85 /100 Excellent
Architecture 85
Code Quality 82
Innovation 84
Learning Curve 88

Turndown is a small, dependency-light JavaScript library that converts HTML into Markdown. It accepts either an HTML string or a DOM node and produces CommonMark-compatible output, running the same code in Node.js (via domino) and directly in the browser.

Its real strength is extensibility: a rule engine lets you add custom conversion rules, keep or remove specific elements, override Markdown escaping, and layer in plugins such as GitHub Flavored Markdown support. This makes it a common building block for content pipelines, rich-text-to-Markdown editors, scrapers, and note-taking tools.

What You Get

  • A TurndownService class that converts HTML strings or DOM nodes to CommonMark-style Markdown
  • Configurable options for heading style, bullet markers, code-block fencing, emphasis and link styles
  • An extensible rule system (addRule, keep, remove) plus a plugin API (use) for behaviors like GFM tables and strikethrough
  • Isomorphic builds (CJS, ESM, UMD, IIFE) that run in Node.js and the browser

Common Use Cases

  • Converting WYSIWYG/rich-text editor HTML into Markdown for storage
  • Turning scraped or fetched web pages into Markdown for LLM ingestion or archival
  • Migrating CMS or blog content from HTML to Markdown files
  • Building note-taking and clipping tools that save web content as Markdown

Under The Hood

Architecture

Turndown centers on the TurndownService constructor in src/turndown.js, which merges user options over CommonMark defaults and builds a Rules collection (src/rules.js). The turndown() entry point wraps input in a RootNode (src/root-node.js), then recursively reduces the DOM: process() walks childNodes, wrapping each in a Node (src/node.js) that computes block/blank/flanking-whitespace metadata, and replacementForNode() finds the first matching rule and applies its replacement function. A join() helper reconciles blank-line spacing between fragments, and postProcess() runs rule append hooks and trims the result. In Node.js the HTML is parsed via @mixmark-io/domino (src/html-parser.js); in the browser the native DOMParser is used instead.

Tech Stack

Pure JavaScript authored as ES modules with a single runtime dependency, @mixmark-io/domino (^2.2.0), for server-side DOM parsing. Rollup bundles four output formats (CJS, ESM, UMD, IIFE) plus browser-specific variants via config files under config/, with Babel transforms for block-scoping and shorthand properties. Standard (standardjs) enforces style. Engines require Node >=18. There is no TypeScript in the source, though the library is widely paired with community type definitions.

Code Quality

The codebase is compact and readable, with each concern isolated in its own small module (rules, node, root-node, collapse-whitespace, utilities). Public methods carry JSDoc, and there is a real test suite: test/turndown-test.js drives fixture-based conversions through turndown-attendant plus explicit edge cases (null/undefined input, malformed documents, rule precedence, chaining return values), and test/internals-test.js exercises internal helpers. Notable care shows in details like the hand-rolled trimTrailingNewlines to avoid a regex backtracking bottleneck (issue #370). Style is enforced by standard in the test script.

API Design

The developer experience is excellent for its scope: new TurndownService().turndown(html) is the entire happy path, and every extension point (addRule, keep, remove, use, escape override, and constructor options) returns the instance for chaining and is documented in the README with copy-paste examples. Option names read naturally (headingStyle, bulletListMarker, codeBlockStyle), and the rule filter/replacement contract is small and consistent, making custom rules and plugins straightforward to write.

Used by 38 apps in this directory

TypeScript
77%
Other

Joplin

Note Taking

56,853

The privacy-first, open-source note-taking app with end-to-end encrypted sync, AI assistance, and a powerful plugin ecosystem across every platform.

View details
93
Repo Health
87
Technical
60
Dependency
Built with
TypeScript 77%
JavaScript 14%
Updated yesterday
TypeScript
92%
MIT

Kaneo

Product Management · Productivity · Project Management

9,574

Lightweight self-hosted project management that gives you kanban boards, GitHub sync, and full team collaboration without the enterprise bloat.

View details
87
Repo Health
81
Technical
70
Dependency
Built with
TypeScript 92%
Updated today
TypeScript
98%
AGPL 3.0

Karakeep

Bookmarks Archiving

29,926

Self-hosted bookmark manager that captures links, notes, images, and PDFs with AI tagging, full-text search, and automatic archiving.

View details
88
Repo Health
76
Technical
66
Dependency
Built with
TypeScript 98%
Updated 2 days ago
Go
51%
AGPL 3.0

listmonk

Blogging · Marketing

23,944

High-performance, self-hosted newsletter and mailing list manager packaged as a single binary with built-in analytics, transactional messaging, and multi-channel delivery.

View details
90
Repo Health
74
Technical
64
Dependency
Built with
Go 51%
JavaScript 22%
HTML 20%
Updated today
JavaScript
81%
MIT

localforge

AI Agents · AI Code Assistants · Developer Tools

401

A local, multi-provider AI coding agent with a real desktop and web UI — bring your own Anthropic, OpenAI, Gemini, Bedrock, or local Ollama keys and let it read, edit, and run code in your own project folder.

View details
41
Repo Health
54
Technical
73
Dependency
Built with
JavaScript 81%
CSS 12%
Updated 1 years ago
JavaScript
55%
Other

Lokus

Knowledge Management · Note Taking

829

Local-first note-taking with graph view, canvas & AI plugins—your Markdown files, zero telemetry, blazing-fast Rust performance.

View details
75
Repo Health
75
Technical
64
Dependency
Built with
JavaScript 55%
HTML 21%
Rust 12%
Updated 1 months ago
TypeScript
92%
Apache 2.0

Apache Maka

AI Agents · AI Development · Developer Tools

5,868

An Apache-incubated agent workspace that treats every model call, tool run, and permission decision as an append-only, replayable event log instead of disposable chat history.

View details
82
Repo Health
85
Technical
73
Dependency
Built with
TypeScript 92%
Updated today
TypeScript
51%
Other

Mattermost

Collaboration · Devops · Team Chat

39,418

Open core, self-hosted team collaboration with chat, AI agents, voice calling, and deep DevOps integrations — all under your control.

View details
96
Repo Health
87
Technical
65
Dependency
Built with
TypeScript 51%
Go 40%
Updated today
TypeScript
92%
Other

n8n

Automation · No Code Platforms

208,437

Code when you need it, UI when you don't — the workflow automation platform built for technical teams who refuse to choose.

View details
95
Repo Health
87
Technical
62
Dependency
Built with
TypeScript 92%
Updated yesterday

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers