Installation
Install Turndown from npm:Basic Usage
Require Turndown and create an instance:CommonJS vs ES Modules
Turndown provides different module formats to suit your project:- CommonJS
- ES Modules
lib/turndown.cjs.js.Server-Side HTML Parsing with Domino
Turndown includes@mixmark-io/domino as a dependency for server-side DOM manipulation. This allows you to parse HTML strings and work with DOM nodes in Node.js:
The domino dependency is automatically excluded in browser builds via the
browser field in package.json.Integration Patterns
Express.js Middleware
Create a middleware to convert HTML responses to Markdown:Processing Files
Convert HTML files to Markdown:Batch Processing
Process multiple HTML files:Streaming Large Files
For very large HTML files, you might want to process them in chunks:Configuration Options
Customize Turndown behavior when instantiating:Error Handling
Turndown validates input and throws aTypeError for invalid input:
Next Steps
Custom Rules
Extend Turndown with custom conversion rules for specialized HTML elements
GFM Plugin
Add GitHub Flavored Markdown features like tables and strikethrough