Steps
Point the field at the text with an expression
The Markdown field must be in Expression mode. In Fixed mode,
{{ $json.text }}came out literally as<p>{{ $json.text }}</p>with a green run. Check the field name in the input panel too: AI Agent nodes usually put their answer inoutput. When we pointed Markdown to HTML at a field that didn't exist, the run was green but no destination key was written at all, so the next node got the item unchanged. HTML to Markdown is the opposite: a missing field failed withCannot convert undefined or null to object.Turn on Tables and Simple Line Breaks for AI output
With default options a GitHub-style table stayed as raw pipes inside one paragraph, and two lines separated by a single newline merged into one. That is why AI reports look broken in emails. Options, Tables gave a real
<table>, and Simple Line Breaks turned each newline into<br />. Strikethrough, Tasklists and Simplified Auto Link are also off by default, so~~old~~,- [ ] taskand bare URLs stay as plain text until you enable them.Fix literal \n from the AI
If the text shows
\nas two characters (the model returned escaped or double-encoded JSON), the converter sees one long line. Our test ended with everything inside one<h1>, visible\nincluded. Replace them first:{{ $json.output.replaceAll('\\n', '\n') }}, or parse the JSON properly before the Markdown node.Send a string, not an object or number
An object or a number in the field failed with
text.replace is not a function. Point at the string field, or wrap it:{{ String($json.total) }}or{{ JSON.stringify($json.data) }}. An empty string andnullpassed through without an error, so empty AI answers send empty emails.Protect snake_case, hashtags and sublists
By default
file_name_v2becamefile<em>name</em>v2and2*3*4became2<em>3</em>4; turn on Literal Mid Word Underscores and Literal Mid Word Asterisks. A line starting with#hashtagbecame a heading until Require Space Before Heading Text was on. A bullet indented 2 spaces under a numbered item broke the list in two; indent 4 spaces or enable Disable Forced 4 Spaces Indented Sublists.Choose the output key and document type
The result goes to Destination Key,
databy default. A dotted key such asemail.bodycreated a nested object, andtextoverwrote your Markdown. Complete HTML Document wraps it in a full<!DOCTYPE HTML>page, which you only need if the email node or file wants one. Headings get automatic ids (helloworld,helloworld-1); No Header ID removes them.Sanitise before you email or render it
Raw HTML in the Markdown, including
<script>, passed straight into the output. If the text comes from an AI model, a form or an email, strip tags first (for example with a Code node) before you put it into a page. From general experience rather than our runs: many email clients strip<input>checkboxes, so Tasklists may not show in emails.HTML to Markdown: images, escapes and blank lines
HTML to Markdown dropped
<style>and<script>, turned tables into pipe tables and<br>into a two-space line break. Adata:image was dropped silently until Keep Data Images was on. Literal*,_and1.in text were backslash-escaped (15\_total), which doubles up if you then escape for Telegram MarkdownV2 or Slack. Gmail-style<div><br></div>left stray blank lines; Max Consecutive New Lines trims them. Nested tables were flattened and the outer table lost, and the Ignore option didn't remove the table in our test, so clean the HTML first if you need that.
What we ran
On 24 October 2026 we ran 38 executions on self-hosted n8n 2.43.7 with n8n execute: Manual Trigger, a Code node with test Markdown or HTML, the Markdown node (v1) with different options, and a Code node that recorded the output. 25 runs were Markdown to HTML and 13 were HTML to Markdown; 35 succeeded and 3 failed.
| Setup | Result |
|---|---|
| AI-style report, default options | Headings, bold and code fences convert; a GitHub table stays as raw pipes inside one <p> |
| Same, Tables option on | Real <table><thead><tbody> |
| Two lines with a single newline, default | Merged into one paragraph, no <br> |
| Simple Line Breaks on | Single newline becomes <br /> |
~~old~~ and - [ ] task, default | Left as literal text |
| Strikethrough and Tasklists on | <del> and disabled checkbox <input> elements |
| Bare https URL, default | Not a link; Simplified Auto Link makes it an <a> |
Markdown field in Fixed mode with {{ $json.text }} | Output is literally <p>{{ $json.text }}</p>, green run |
Field pointing at $json.output, text is in $json.text | Green run, no destination key written at all |
| Object or number in the field | Error: text.replace is not a function |
Empty string; null | ""; null, no error |
Destination Key email.body | Nested {"email":{"body":...}} |
Destination Key text | Overwrites the source Markdown |
| Complete HTML Document on | Full <!DOCTYPE HTML><html><head> document |
Two headings Hello World | Ids helloworld and helloworld-1; No Header ID removes them |
#hashtag at line start | Becomes a heading unless Require Space Before Heading Text |
file_name_v2 and 2*3*4, default | file<em>name</em>v2, 2<em>3</em>4 |
| Literal Mid Word Underscores and Asterisks on | Left as written |
Raw <b> and <script> in the Markdown | Passed straight through, nothing sanitised |
| Open Links In New Window | target="_blank" rel="noopener noreferrer" |
Emoji option, :smile: :rocket: | Unicode emoji |
Nested list indented 2 spaces under 1. | List broken into <ol></ol><ul></ul><ol> |
AI text with literal \n characters | Everything inside one <h1 id="titlennboldnitem"> with visible \n |
| 2 input items | 2 outputs, one conversion per item |
| HTML to Markdown, default | <style>/<script> dropped, tables become pipe tables, <ul> becomes * bullets |
HTML with a data: image, default | Image dropped silently; Keep Data Images keeps it |
Text with *, _ and 1. | Backslash-escaped: \*stars\*, 15\_total, 1\. |
| HTML to Markdown, field missing | Error: Cannot convert undefined or null to object |
Gmail-style <div><br></div> and | Stray blank lines; Max Consecutive New Lines trims them |
Bullet Marker -, Strong Delimiter __ | - one, __Anna__ |
<pre><code class="language-js"> | A ```js fence |
| Nested table | Flattened to one table, outer table lost |
| Object in the HTML field | No error: each value converted, {"a":1} became {"a":"1"} |
Good to know
- Sending the HTML by email? See n8n Send Email (SMTP) errors. Pulling text out of web pages first: n8n HTML node not working. Sending to Telegram instead: Telegram bot for beginners.
- Every error message we reproduced is in the n8n error message index.
What we didn't test
- The editor UI itself (we ran workflows from JSON), n8n Cloud, and how real Gmail or Outlook inboxes render the HTML: email client behaviour above is general knowledge, not measured.
Start from a working agent
FAQ
Why does my Markdown table show as pipes in n8n?
The Markdown node leaves tables off by default. Open Options and turn on Tables, and the table becomes real HTML.
Why are my line breaks lost after the n8n Markdown node?
Standard Markdown joins lines separated by a single newline into one paragraph. Turn on Simple Line Breaks to get a br for each newline.
Why does the n8n Markdown node output nothing?
If the Markdown field points at a field that doesn't exist, or is in Fixed mode, the run stays green and no output key is written or the braces come out as text. Use Expression mode and the right field, often output for AI Agent nodes.
What does "text.replace is not a function" mean in the n8n Markdown node?
The field holds an object or a number, not a string. Point it at the text field or wrap it in String() or JSON.stringify().
How do I send AI agent output as a nice HTML email in n8n?
Use the Markdown node, Markdown to HTML, on the agent output with Tables and Simple Line Breaks on, replace any literal \n first, then put the data field into the email node's HTML body.
Why does HTML to Markdown add backslashes in n8n?
It escapes characters that would otherwise be read as Markdown, such as * _ and 1. at the start of a line. Remove them or skip conversion if your target, like Telegram MarkdownV2, does its own escaping.
Related guides
- n8n Gmail Trigger not working: not firing, silent errors and fixes
- n8n Simple Vector Store not working? 23 tests, every error decoded
- n8n Split Out, Aggregate and Summarize not working: 78 runs, fixed
- n8n HTML Extract not working: empty values, selectors and errors, 32 runs
- n8n static data not saving? 35 runs, every cause found
New guides
- GitHub release notifications in Slack (any public repo, stable releases only)
- Send RSS feeds to Slack with a keyword filter (free, incoming webhook)
- Forward emails to a Slack channel (Gmail, Outlook, any IMAP), free with an incoming webhook
- n8n Google Sheets Trigger not working: not firing, activation errors and fixes