turndown is a free, open source browsers & extensions project written in HTML and released under MIT. It has 11,438 GitHub stars, 994 forks and 144 open issues, and was last pushed 15 days ago. On this registry it ranks #36 of 101 tracked projects in Browsers & Extensions, with 5 head-to-head comparisons available.

What is turndown?

Turndown is a JavaScript library, published under the MIT licence, that converts HTML into CommonMark or GitHub Flavored Markdown and runs both in Node.js and in the browser.

What it is

Turndown is an open-source HTML-to-Markdown converter written in JavaScript and maintained at mixmark-io/turndown on GitHub, from where it also serves an online demo. It accepts either an HTML string or a DOM node β€” element nodes, document nodes, and document fragment nodes are all supported β€” and returns Markdown. A single TurndownService instance holds the configuration and the conversion rules, and calling turndown() on it produces the output. The topics attached to the repository place it squarely in the browser, Node, CommonMark, and GFM ecosystems, and the project occupies the HTML-to-Markdown niche inside those ecosystems.

The concrete problem it solves is the conversion step between HTML as a document format and Markdown as a text format. Rather than hand-rewriting exported HTML, or maintaining bespoke regular expressions and string surgery per project, a caller passes markup to the service and receives Markdown that follows a named specification. Turndown explicitly replaces its own predecessor: the project was previously published as to-markdown and was renamed, with a migration guide documenting the move from the old name to the new one, and the repository itself later changed its URL to https://github.com/mixmark-io/turndown. Adoption is broad β€” the repository carries 11,438 stars and 994 forks.

Key capabilities

  • Converts an HTML string or a DOM node through the TurndownService instance method turndown(), including element nodes, document nodes, and document fragment nodes.
  • Targets CommonMark and GFM output, with formatting controlled by constructor options such as headingStyle (setext or atx), bulletListMarker (-, +, or *), codeBlockStyle (indented or fenced), and fence ( ``` or ~~~).
  • Controls inline markup through emDelimiter (_ or *), strongDelimiter (** or __), and link rendering through linkStyle (inlined or referenced) plus linkReferenceStyle (full, collapsed, or shortcut).
  • Extends conversion with addRule(key, rule), which returns the service for chaining; the documented example maps del, s, and strike to ~content~ for strikethrough.
  • Preserves selected elements as raw HTML with keep(filter) and deletes elements and their contents with remove(filter), with newly added filters taking precedence over older ones.
  • Ships UMD bundles at lib/turndown.umd.js for Node.js and lib/turndown.browser.umd.js for the browser, generated at publish time or manually via npm run build.

Who uses it and how

  • Node.js services that store or receive HTML and need Markdown, using require('turndown') and a TurndownService instance.
  • Browser applications that convert live DOM directly, for example by passing document.getElementById('content'), avoiding a server round trip.
  • Teams producing GFM for documentation, issue trackers, or README files, where linkStyle: 'referenced' and other options let output match house style.
  • Projects with non-standard elements, which add custom rules for their own tags and use keep() to leave unrecognised markup as HTML.
  • Existing to-markdown users, who are directed to a migration guide for the rename.

Getting started

Install with npm install turndown, or load the browser build through a script tag; the project publishes UMD bundles for both Node.js and browser use, and an online demo is available at https://mixmark-io.github.io/turndown.

How it compares

This registry lists no comparable HTML-to-Markdown converters or paid products alongside Turndown, so no licence, self-hosting, or cost-model contrast can be drawn from the available facts. On the evidence provided β€” an MIT licence, a public npm package, browser and Node builds, and no hosted commercial tier β€” Turndown stands alone here rather than sitting in a field of named alternatives.

When to use it β€” and when not to

Turndown is a library, not a service, so there is no database, object store, or SMTP server to operate; the requirement is a JavaScript runtime, either Node.js or a browser, and someone to install and version the package. It converts in one direction only, so projects that also need Markdown-to-HTML rendering must supply that separately. Be aware of the maintenance signal before adopting: the repository has 144 open issues, the README documents advanced options partly by linking out to an upstream collapse-whitespace issue for preformattedCode, and no release cadence, support policy, or security process appears in the material provided.

project readme (upstream, from github) β€” read inline

Turndown

Convert HTML into Markdown with JavaScript.

See it in action online.

Project Updates

Installation

npm:

npm install turndown

Browser:

<script src="https://unpkg.com/turndown/dist/turndown.js"></script>

For usage with RequireJS, UMD versions are located in lib/turndown.umd.js (for Node.js) and lib/turndown.browser.umd.js for browser usage. These files are generated when the npm package is published. To generate them manually, clone this repo and run npm run build.

Usage

// For Node.js
var TurndownService = require('turndown')

var turndownService = new TurndownService()
var markdown = turndownService.turndown('<h1>Hello world!</h1>')

Turndown also accepts DOM nodes as input (either element nodes, document nodes, or document fragment nodes):

var markdown = turndownService.turndown(document.getElementById('content'))

Options

Options can be passed in to the constructor on instantiation. For example:

var turndownService = new TurndownService({ option: 'value' })
Option Valid values Default
headingStyle setext or atx setext
hr Any Thematic break * * *
bulletListMarker -, +, or * *
codeBlockStyle indented or fenced indented
fence ``` or ~~~ ```
emDelimiter _ or * _
strongDelimiter ** or __ **
linkStyle inlined or referenced inlined
linkReferenceStyle full, collapsed, or shortcut full
preformattedCode false or true false

Advanced Options

Option Valid values Default
blankReplacement rule replacement function See Special Rules below
keepReplacement rule replacement function See Special Rules below
defaultReplacement rule replacement function See Special Rules below

Methods

addRule(key, rule)

The key parameter is a unique name for the rule for easy reference. Example:

turndownService.addRule('strikethrough', {
  filter: ['del', 's', 'strike'],
  replacement: function (content) {
    return '~' + content + '~'
  }
})

addRule returns the TurndownService instance for chaining.

See Extending with Rules below.

keep(filter)

Determines which elements are to be kept and rendered as HTML. By default, Turndown does not keep any elements. The filter parameter works like a rule filter (see section on filters belows). Example:

turndownService.keep(['del', 'ins'])
turndownService.turndown('<p>Hello <del>world</del><ins>World</ins></p>') // 'Hello <del>world</del><ins>World</ins>'

This will render and elements as HTML when converted.

keep can be called multiple times, with the newly added keep filters taking precedence over older ones. Keep filters will be overridden by the standard CommonMark rules and any added rules. To keep elements that are normally handled by those rules, add a rule with the desired behaviour.

keep returns the TurndownService instance for chaining.

remove(filter)

Determines which elements are to be removed altogether i.e. converted to an empty string. By default, Turndown does not remove any elements. The filter parameter works like a rule filter (see section on filters belows). Example:

turndownService.remove('del')
turndownService.turndown('<p>Hello <del>world</del><ins>World</ins></p>') // 'Hello World'

This will remove `` elements (and contents).

remove can be called multiple times, with the newly added remove filters taking precedence over older ones. Remove filters will be overridden by the keep filters, standard CommonMark rules, and any added rules. To remove elements that are normally handled by those rules, add a rule with the desired behaviour.

remove returns the TurndownService instance for chaining.

use(plugin|array)

Use a plugin, or an array of plugins. Example:

// Import plugins from turndown-plugin-gfm
var turndownPluginGfm = require('turndown-plugin-gfm')
var gfm = turndownPluginGfm.gfm
var tables = turndownPluginGfm.tables
var strikethrough = turndownPluginGfm.strikethrough

// Use the gfm plugin
turndownService.use(gfm)

// Use the table and strikethrough plugins only
turndownService.use([tables, strikethrough])

use returns the TurndownService instance for chaining.

See Plugins below.

Extending with Rules

Turndown can be extended by adding rules. A rule is a plain JavaScript object with filter and replacement properties. For example, the rule for converting <p> elements is as follows:

{
  filter: 'p',
  replacement: function (content) {
    return '\n\n' + content + '\n\n'
  }
}

The filter selects <p> elements, and the replacement function returns the <p> contents separated by two new lines.

filter String|Array|Function

The filter property determines whether or not an element should be replaced with the rule's replacement. DOM nodes can be selected simply using a tag name or an array of tag names:

  • filter: 'p' will select <p> elements
  • filter: ['em', 'i'] will select <em> or <i> elements

The tag names in the filter property are expected in lowercase, regardless of their form in the document.

Alternatively, the filter can be a function that returns a boolean depending on whether a given node should be replaced. The function is passed a DOM node as well as the TurndownService options. For example, the following rule selects <a> elements (with an href) when the linkStyle option is inlined:

filter: function (node, options) {
  return (
    options.linkStyle === 'inlined' &&
    node.nodeName === 'A' &&
    node.getAttribute('href')
  )
}

replacement Function

The replacement function determines how an element should be converted. It should return the Markdown string for a given node. The function is passed the node's content, the node itself, and the TurndownService options.

The following rule shows how <em> elements are converted:

rules.emphasis = {
  filter: ['em', 'i'],

  replacement: function (content, node, options) {
    return options.emDelimiter + content + options.emDelimiter
  }
}

Special Rules

Blank rule determines how to handle blank elements. It overrides every rule (even those added via addRule). A node is blank if it only contains whitespace, and it's not an <a>, <td>,<th> or a void element. Its behaviour can be customised using the blankReplacement option.

Keep rules determine how to handle the elements that should not be converted, i.e. rendered as HTML in the Markdown output. By default, no elements are kept. Block-level elements will be separated from surrounding content by blank lines. Its behaviour can be customised using the keepReplacement option.

Remove rules determine which elements to remove altogether. By default, no elements are removed.

Default rule handles nodes which are not recognised by any other rule. By default, it outputs the node's text content (separated by blank lines if it is a block-level element). Its behaviour can be customised with the defaultReplacement option.

Rule Precedence

Turndown iterates over the set of rules, and picks the first one that matches the filter. The following list describes the order of precedence:

  1. Blank rule
  2. Added rules (optional)
  3. Commonmark rules
  4. Keep rules
  5. Remove rules
  6. Default rule

Plugins

The plugin API provides a convenient way for developers to apply multiple extensions. A plugin is just a function that is called with the TurndownService instance.

Escaping Markdown Characters

Turndown uses backslashes (\) to escape Markdown characters in the HTML input. This ensures that these characters are not interpreted as Markdown when the output is compiled back to HTML. For example, the contents of <h1>1. Hello world</h1> needs to be escaped to 1\. Hello world, otherwise it will be interpreted as a list item rather than a heading.

To avoid the complexity and the performance implications of parsing the content of every HTML element as Markdown, Turndown uses a group of regular expressions to escape potential Markdown syntax. As a result, the escaping rules can be quite aggressive.

Overriding

readme truncated β€” read the full docs on github

Frequently asked questions

Is turndown free to use?

turndown is open source under the MIT licence. There is no licence fee and no seat count β€” you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does turndown do?

πŸ› An HTML to Markdown converter written in JavaScript

What is turndown written in?

turndown is primarily written in HTML. Its source is publicly available at https://github.com/mixmark-io/turndown, and it has 11,438 GitHub stars.