Skip to main content

Loading via CDN

The easiest way to use Turndown in the browser is to load it from a CDN:
The library is exposed as a global TurndownService constructor that you can instantiate and use immediately.

Loading via RequireJS/UMD

For projects using RequireJS or other UMD-compatible module loaders, Turndown provides a browser-specific UMD build:
The UMD build is located at lib/turndown.browser.umd.js in the npm package. If you need to generate it manually:
The browser UMD build excludes the @mixmark-io/domino dependency, which is only needed for Node.js environments.

Working with DOM Elements

One of Turndown’s most powerful features in the browser is its ability to accept DOM nodes directly as input:
Turndown accepts element nodes (nodeType 1), document nodes (nodeType 9), and document fragment nodes (nodeType 11).

Complete Browser Example

Here’s a complete example of a browser-based HTML to Markdown converter:

Browser-Specific Considerations

Package Configuration

The package.json uses the browser field to provide browser-specific builds:
This ensures that when bundlers like webpack or browserify process your code, they automatically use the browser-optimized builds.

Input Validation

Turndown validates that the input can be converted before processing:
If you pass invalid input (not a string or valid DOM node), Turndown will throw a TypeError: input is not a string, or an element/document/fragment node.

Empty Input

When given an empty string, Turndown returns an empty string immediately without processing:

Next Steps

Custom Rules

Learn how to create custom conversion rules for specialized HTML elements

GFM Plugin

Add GitHub Flavored Markdown support with tables and strikethrough