Overview
Thereplacement property is a function that defines how a matched HTML element should be converted to Markdown. It receives information about the element and returns the Markdown string.
Function Signature
string - The Markdown representation of the element
Simple Replacements
Paragraph
Wraps content with blank lines:<p>Hello world</p>
Output:
Blockquote
Prefixes each line with>:
<blockquote>Hello\nWorld</blockquote>
Output:
Horizontal Rule
Outputs the configured horizontal rule:hr option (default: '* * *').
Replacements Using Options
Line Break
Uses the configured line break style:br option determines the line break format (default: ' ' - two spaces).
Emphasis
Wraps content with the configured emphasis delimiter:emDelimiter option (default: '_'). Returns empty string if content is blank.
Input: <em>italic</em>
Output: _italic_
Strong
Wraps content with the configured strong delimiter:strongDelimiter option (default: '**').
Input: <strong>bold</strong>
Output: **bold**
Replacements Using Node Properties
Heading
Extracts heading level from the node name:h2):
h1):
List Item
Checks parent element and position:- Determines if the list is ordered or unordered
- Calculates the appropriate prefix (bullet or number)
- Indents multiline content
- Adds newlines between items
Image
Extracts attributes from the node:<img src="logo.png" alt="Logo" title="Company Logo">
Output: 
Inline Link
Extracts and escapes link attributes:<a href="https://example.com" title="Example">Link</a>
Output: [Link](https://example.com "Example")
Complex Replacements
List
Contextual formatting based on parent:Inline Code
Dynamically determines delimiter:- Replaces newlines with spaces
- Determines if extra spaces are needed
- Finds a delimiter that doesn’t conflict with backticks in the content
- Wraps the content appropriately
<code>`code`</code>
Output: `` `code` ``
Fenced Code Block
Extracts language and adapts fence size:- Extracts the language from the class name
- Gets the raw code text
- Determines the minimum fence size to avoid conflicts
- Builds the fenced code block
Reference Link
Collects references for later output:references array to collect link definitions, which are output at the end via the append function.
Input: <a href="https://example.com">Link</a>
Output (in content): [Link][1]
Output (appended):
Indented Code Block
Directly accesses text content:node.firstChild.textContent instead of content to get the raw code without markdown conversion.
Best Practices
Return Empty String for Empty Content
Use Consistent Spacing
Block-level elements typically use\n\n before and after:
Escape Special Characters
When outputting user content, escape characters that have special meaning:Access Raw Text When Needed
For code blocks, usetextContent instead of the converted content: