explaingit

mixmark-io/turndown

11,161HTMLAudience · developerComplexity · 2/5Setup · easy

TLDR

A JavaScript library that converts HTML into Markdown text, working in both Node.js and the browser, with customizable output style and support for plugins like GitHub Flavored Markdown tables.

Mindmap

mindmap
  root((repo))
    What it does
      HTML to Markdown
      Browser and Node
      Plugin support
    Output options
      Heading style
      List bullet char
      Link style
    Extend it
      Custom rules
      Keep elements
      Remove elements
    Setup
      npm install
      Script tag CDN
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Convert HTML content from a web page or rich text editor into clean Markdown text.

USE CASE 2

Build a tool that exports user-written HTML blog posts or notes as Markdown files.

USE CASE 3

Add a custom rule to handle non-standard HTML tags and control exactly how they appear in Markdown output.

USE CASE 4

Use the turndown-plugin-gfm plugin to include GitHub-style tables and strikethrough formatting in the output.

Tech stack

JavaScript

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

Turndown is a JavaScript library that converts HTML into Markdown. You give it an HTML string (or a DOM node in a browser) and it returns the equivalent Markdown text. It works both in Node.js and directly in the browser via a script tag. The basic usage is a few lines: you create a TurndownService instance, call its turndown method with your HTML, and get a Markdown string back. For example, passing the string for an h1 heading tag returns that heading formatted as Markdown. A variety of options let you control the output style, including how headings are formatted, what character is used for bullet list items, whether code blocks are fenced or indented, and whether links are written inline or as references. The library can be extended with rules. A rule is a small JavaScript object that specifies which HTML elements to match (by tag name or a custom function) and a replacement function that returns the Markdown string for that element. This lets you handle unusual HTML tags that the library does not cover by default, or override how standard tags are converted. You can also use the keep method to tell the library to leave certain HTML elements as-is in the Markdown output rather than converting them, and the remove method to drop elements entirely. Plugins are also supported through a use method. A separate package called turndown-plugin-gfm adds support for GitHub Flavored Markdown features like tables and strikethrough, which are not part of the CommonMark standard that Turndown handles by default. Installation is through npm with a single command, or by including a script tag from a CDN. The project was previously called to-markdown and was renamed to Turndown when the repository moved.

Copy-paste prompts

Prompt 1
Using the Turndown library, write a Node.js script that reads an HTML file and saves it as a Markdown file.
Prompt 2
I have an HTML string with tables. Show me how to use Turndown with turndown-plugin-gfm to convert it to Markdown with proper table formatting.
Prompt 3
Write a custom Turndown rule that converts aside tags into Markdown blockquotes.
Prompt 4
I'm building a browser extension that copies the main content of the current page as Markdown using Turndown. Show me the code.
Prompt 5
How do I configure Turndown to use ATX-style headings and fenced code blocks in the output?
Open on GitHub → Explain another repo

← mixmark-io on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.