Loading via CDN
The easiest way to use Turndown in the browser is to load it from a CDN: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: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
Thepackage.json uses the browser field to provide browser-specific builds:
Input Validation
Turndown validates that the input can be converted before processing: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