Quickstart
This guide will walk you through your first HTML to Markdown conversion using Turndown. In just a few minutes, you’ll be converting HTML to clean, readable Markdown.Before You Begin
Make sure you have Turndown installed. If not, follow the Installation guide first.Your First Conversion
1
Import Turndown
First, import the TurndownService:
- Node.js
- ES Module
- Browser
2
Create a service instance
Create a new instance of TurndownService:
You can call TurndownService with or without the
new keyword - both work the same way.3
Convert HTML to Markdown
Use the Congratulations! You’ve just converted your first HTML to Markdown.
turndown() method to convert HTML:More Examples
Converting Complex HTML
Turndown handles complex HTML structures with ease:Converting DOM Elements
In a browser environment, you can convert DOM elements directly:Customizing the Conversion
Basic Configuration
Customize how Turndown converts HTML by passing options to the constructor:Common Options
- Heading Styles
- Code Block Styles
- Link Styles
Working with Code
Inline Code
Code Blocks with Language
Error Handling
Turndown throws aTypeError if you pass invalid input:
- Strings containing HTML
- Element nodes (
nodeType === 1) - Document nodes (
nodeType === 9) - Document fragment nodes (
nodeType === 11)
Complete Example
Here’s a complete working example bringing it all together:Next Steps
Now that you’ve completed the quickstart, explore these topics to get the most out of Turndown:Conversion Options
Learn about all available configuration options
Custom Rules
Create custom rules to handle specific HTML elements
Plugins
Extend Turndown with plugins like GFM support
API Reference
Explore the complete API documentation