Skip to main content

Syntax

Description

Determines which HTML elements should be kept as HTML in the Markdown output instead of being converted. By default, Turndown converts all recognized HTML to Markdown. Use this method to preserve specific elements as raw HTML.

Parameters

string | array | function
required
Specifies which elements to keep as HTML:
  • String: A single tag name (e.g., 'del')
  • Array: Multiple tag names (e.g., ['del', 'ins'])
  • Function: Custom filter function (node, options) => boolean

Returns

TurndownService
Returns the TurndownService instance for method chaining

Examples

Keep Single Element

Keep Multiple Elements

Keep with Custom Filter

Chaining Keep Calls

Behavior Details

Block-Level Elements

Block-level elements that are kept will be separated from surrounding content by blank lines:

Inline Elements

Inline elements are kept without additional spacing:

Notes

  • Returns the instance to enable method chaining
  • Can be called multiple times; newer filters take precedence
  • Keep filters are overridden by standard CommonMark rules and added rules
  • To keep elements handled by default rules, add a custom rule instead
  • The default keepReplacement function can be customized via constructor options
  • Block-level kept elements are wrapped with blank lines; inline elements are not