Skip to main content
Plugins provide a convenient way to package and distribute multiple rules and customizations as a single reusable module. A plugin is simply a function that receives the TurndownService instance and configures it.

What Are Plugins?

A plugin is a function that takes a TurndownService instance and extends it with custom rules, options, or behavior:
Plugins are applied using the use() method:

Using Plugins

The use() method accepts either a single plugin function or an array of plugins.

Single Plugin

Multiple Plugins

use() returns the TurndownService instance, allowing you to chain method calls.

Official Plugins

turndown-plugin-gfm

Adds support for GitHub Flavored Markdown (GFM) extensions:
Available plugins:
  • gfm - All GFM features (combines all plugins below)
  • tables - Table support
  • strikethrough - Strikethrough text (~~text~~)
  • taskListItems - Task list checkboxes
Installation:

Creating Custom Plugins

Create a plugin by writing a function that configures a TurndownService instance.

Basic Plugin Structure

Plugin with Multiple Rules

Plugin with Options

Create a plugin factory that accepts configuration:

Plugin that Modifies Service Behavior

Plugins can do more than add rules:

Packaging Plugins

When creating a plugin package for distribution:

Module Structure

Exporting Multiple Plugins

Complete Plugin Example

Here’s a complete plugin that adds support for Bootstrap alert components:

Plugin Best Practices

Plugins should not modify the TurndownService options object. Let users configure options when instantiating the service.
Best practices:
  • Keep plugins focused on a single feature or set of related features
  • Document all rules and behavior your plugin adds
  • Test plugins with various HTML inputs
  • Consider edge cases (empty content, nested elements, etc.)
  • Follow Markdown and CommonMark specifications
  • Provide options for customization when appropriate

Loading Plugins

Plugins can be loaded in different ways depending on your environment:

Node.js

ES Modules

Browser (CDN)

  • Rules - Learn about the rule system that powers plugins
  • API Reference - Detailed use() method documentation
  • Examples - More plugin examples