Skip to main content

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:
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 turndown() method to convert HTML:
Congratulations! You’ve just converted your first HTML to Markdown.

More Examples

Converting Complex HTML

Turndown handles complex HTML structures with ease:
Output:

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

For a complete list of options, see Conversion Options.

Working with Code

Inline Code

Code Blocks with Language

Output:

Error Handling

Turndown throws a TypeError if you pass invalid input:
Valid input types:
  • 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
Pro Tip: Start with the default options and customize as needed. Turndown’s defaults follow CommonMark conventions and work well for most use cases.