Syntax
Description
Loads one or more plugins to extend TurndownService functionality. Plugins are functions that receive the TurndownService instance and can add rules, modify options, or apply multiple extensions at once.Parameters
function | array
required
A plugin function or array of plugin functions:
- Function: A plugin that receives the TurndownService instance
- Array: Multiple plugins to be applied in order
(turndownService) => voidReturns
TurndownService
Returns the TurndownService instance for method chaining
Errors
Throws aTypeError if:
- Plugin is not a function or array of functions
"plugin must be a Function or an Array of Functions"
Examples
Using GFM Plugin
Using Multiple Plugins
Creating a Custom Plugin
Chaining with Other Methods
Plugin with Configuration
Multiple Plugins in Sequence
Plugin Structure
A plugin is simply a function that receives the TurndownService instance:Notes
- Returns the instance to enable method chaining
- Plugins are applied in the order they are provided
- When passing an array, each plugin is applied sequentially
- Plugins have full access to the TurndownService instance and can:
- Add custom rules
- Configure keep/remove filters
- Modify options
- Override methods
- Popular plugins include
turndown-plugin-gfmfor GitHub Flavored Markdown support