Syntax
Description
Adds a custom rule to the TurndownService instance. Rules define how specific HTML elements should be converted to Markdown. Each rule has a unique key and contains a filter to match elements and a replacement function to define the conversion.Parameters
string
required
A unique identifier for the rule. Used for easy reference and debugging.
object
required
The rule object defining how to convert matching elements
Returns
TurndownService
Returns the TurndownService instance for method chaining
Examples
Strikethrough Rule
Highlight Rule
Custom Filter Function
Chaining Multiple Rules
Notes
- Returns the instance to enable method chaining
- Rules are processed in order of precedence (see Rule Precedence documentation)
- Custom rules take precedence over CommonMark rules but not over the blank rule
- Tag names in filters should be lowercase
- The replacement function receives already-converted content for nested elements