Usage
Basic Options
These options control the Markdown syntax style used for common elements.The style to use for headings.Valid values:
setext- Uses underlines for h1 and h2 (h1 uses=, h2 uses-)atx- Uses#symbols for all heading levels
The character to use for unordered list items.Valid values:
-, +, or *The style to use for code blocks.Valid values:function hello()
indented- Uses 4-space indentationfenced- Uses code fences with backticks
The fence character to use for fenced code blocks.Only used when
codeBlockStyle is fenced.Valid values: ``` or ~~~The delimiter to use for emphasis (italic) text.Valid values:
_ or *The delimiter to use for strong (bold) text.Valid values:
** or __The style to use for links.Valid values:
inlined- Places URL directly in the linkreferenced- Uses reference-style links with definitions at the bottom
The style to use for reference links.Only used when
linkStyle is referenced.Valid values:full- Uses numeric referencescollapsed- Uses empty square bracketsshortcut- Uses link text as reference
The string to use for line breaks (
<br> elements).Default is two spaces (CommonMark line break syntax).Whether to preserve whitespace in code blocks.When
true, prevents collapsing of whitespace in <pre> elements.See collapse-whitespace issue #16 for details.Advanced Options
These options provide fine-grained control over special conversion cases using custom replacement functions.A function that determines how blank elements should be converted.A blank element contains only whitespace and is not an The default returns two newlines for block elements and an empty string for inline elements.
<a>, <td>, <th>, or void element.Function signature: function(content, node)Default implementation:A function that determines how elements marked with The default surrounds block-level elements with blank lines.
keep() should be rendered.Elements marked with keep() are rendered as HTML in the Markdown output.Function signature: function(content, node)Default implementation:A function that handles elements not matched by any rule.This is the fallback for unrecognized elements.Function signature: The default outputs the element’s text content, surrounded by blank lines if it’s a block element.
function(content, node)Default implementation:Complete Example
Here’s an example using multiple options:Options can only be set during instantiation. To use different options, create a new TurndownService instance.