MarkdownV2 escaper for Telegram bots
Telegram's MarkdownV2 parse mode rejects messages with any of
_*[]()~`>#+=-|{}.! outside of valid syntax. Paste your message and
we'll show you the escaped version that will actually send.
To escape special characters for Telegram MarkdownV2, prefix each reserved
character (_ * [ ] ( ) ~ ` > # + - = | { } . !) with a backslash.
Paste your message below and tgkit returns the escaped version that won't trip the
"can't parse entities" error. Runs in your browser, no login.
Escaped output (paste into Bot API)
Preview (what Telegram will render)
Why MarkdownV2 is finicky
Telegram's original Markdown parser was lenient, extra characters were just
ignored. MarkdownV2 (released 2020) is strict: every character in
_ * [ ] ( ) ~ ` > # + - = | { } . !
must be either part of a valid markup token or escaped with a backslash.
An unescaped one returns
Bad Request: can't parse entities.
Reference, what needs escaping where
| Inside normal text | All of _ * [ ] ( ) ~ ` > # + - = | { } . ! |
Inside `inline code` | Backtick ` and backslash \ only |
Inside ```pre block``` | Backtick ` and backslash \ only |
| Inside link/text-mention URL | Parens ) and backslash \ only |
Common gotchas
- Dots and exclamation marks. Sentences ending in
.or!are 90% of the "MarkdownV2 won't send" tickets. Always escape them. - URLs with parens. Wikipedia-style URLs (
...(disambiguation)) break[text](url). Escape the closing paren inside the URL:\). - Hyphens in numbers / phone formats.
+1-555-1234needs each-escaped. Or switch to HTML parse mode. - Bullet lists with
*. A leading* itemlooks like bold-open. Escape:\* itemor switch to HTML mode. - Tables.
|must be escaped, and Telegram doesn't render tables anyway, so just don't ship them.
Alternative: HTML parse_mode
If MarkdownV2's escaping is fighting you, switch parse_mode to
HTML. You only need to escape < > &,
and tags like <b>, <i>, <code>,
<pre>, <a href="…"> work as expected.
Frequently asked questions
How do I escape special characters for Telegram MarkdownV2?
\. The reserved set is _ * [ ] ( ) ~ ` > # + - = | { } . !. tgkit's MarkdownV2 escaper does it for you: paste your message and it returns the version that will actually send without a parsing error.Which characters need to be escaped in MarkdownV2?
_ * [ ] ( ) ~ ` > # + - = | { } . !. Inside pre and code blocks only ` and \ need escaping. Inside link URLs you only need to escape ) and \.Why does my Telegram bot return 'can't parse entities' or 'character must be escaped'?
What's the difference between Markdown, MarkdownV2, and HTML in Telegram?
<, >, and & need escaping.