Description
Markdown to Telegram-HTML n8n Node
This repository contains a custom n8n node that converts Markdown into Telegram-compatible HTML.
It preserves Telegram-specific features (like spoilers using ||spoiler||) and formats standard Markdown into HTML that Telegram accepts.

Based on andresberrios/n8n-nodes-telegram-better-markdown.
๐ Overview
This node is designed to:
- Accept a Markdown string and convert it into Telegram-safe HTML.
- Handle Telegram's 4096-character message limit intelligently.
- Allow customization of output field names and overflow strategies.
โ๏ธ Node Properties
| Property | Type | Default | Description |
|---|---|---|---|
| Markdown Text | string |
โ | The Markdown content to convert. |
| Output Field | string |
telegram_html |
Field name in the output JSON containing the generated HTML. |
| Message Limit Strategy | options |
truncate |
Strategy for handling messages exceeding Telegram's 4096-character limit. |
๐งฉ Message Limit Strategies
Telegram limits messages to 4096 characters.
This node provides two ways to handle longer content:
1. truncate โ Truncate Message
Behavior:
The generated HTML is truncated to a safe boundary (avoiding broken tags) and appends [...] to indicate omitted content.
Use Case:
When you only need one message output and can tolerate trimming the end.
2. split โ Split Message
Behavior:
The HTML is split into multiple parts (each โค4096 characters).
Splitting preserves HTML integrity and returns multiple output items โ one per chunk โ with the same original data except for the updated Output Field.
Use Case:
When you want to send the entire message as multiple consecutive Telegram messages without breaking formatting.
Notes on Behavior
- The node uses helper functions that tokenize HTML and prefer to cut at safe points (e.g., closed tags or line breaks).
- In
truncatemode, a[...]suffix is appended. - In
splitmode, each chunk becomes a separate output item โ downstream nodes (like Telegram Send Message) will process each part independently.
๐งช Example Outputs
truncate Mode
{
"telegram_html": "<p>This is a long message... [...]</p>"
}
A single output item is returned with truncated HTML.
split Mode
[
{ "telegram_html": "<p>Part 1 of the message...</p>" },
{ "telegram_html": "<p>Part 2 of the message...</p>" }
]
Multiple items are returned, each containing a valid HTML chunk.
๐งฐ Local Development
1. Install Dependencies
npm install
2. Run in Development Mode
npm run dev
3. Run unit test
npm test -- --coverage --runInBand
๐ง Usage in n8n
- Add the Markdown to Telegram-HTML node to your workflow.
- Provide your Markdown content in the Markdown Text field.
- Optionally change the Output Field name (default:
telegram_html). - Choose a Message Limit Strategy:
truncatefor a single, shortened message.splitfor multiple message chunks.
