MarkdownV2 escaper

Telegram MarkdownV2 syntax requires a backslash before every special character in plain text. Paste your text here and copy it back escaped, ready for parse_mode=MarkdownV2. It fixes the “can’t parse entities” error and runs in your browser.

Escape text

Type or paste the text your bot should send. Escaped in your browser.

All 18 special characters and the backslash get a backslash in front.

0 → 0 characters

The rule

Plain text_ * [ ] ( ) ~ ` > # + - = | { } . !
code / pre` \
Link URL (…)) \

Source: Bot API, MarkdownV2 style.

How MarkdownV2 escaping works

In MarkdownV2 these characters have a meaning: _ * [ ] ( ) ~ ` > # + - = | { } . !. Anywhere they should appear as themselves, they need a backslash in front. That includes the full stop and the exclamation mark, which is why a plain sentence like “Done.” is refused.

Inside code and pre blocks only the backtick and the backslash need escaping. Inside the address part of a link, only the closing parenthesis and the backslash.

A worked example

You want to send: Price: 1.5 (approx). Unescaped, Telegram stops at the full stop. Escaped, the text reads Price: 1\.5 \(approx\). If you want “Price” in bold, write the asterisks yourself around the escaped text: *Price:* 1\.5 \(approx\).

Escape the variables, not the template

The usual pattern is a template with your own formatting and some values from users or data. Escape each value on its own, then put it into the template. Escaping the whole finished message turns your own asterisks and underscores into literal characters.

Common mistakes

  • Using parse_mode=Markdown (the old version) rules with MarkdownV2. The two escape differently.
  • Forgetting the hyphen and the plus sign in numbers and dates.
  • Escaping twice, so a backslash shows up in the message.

FAQ

Which characters must be escaped in MarkdownV2?

In ordinary text: _ * [ ] ( ) ~ ` > # + - = | { } . ! — each with a preceding backslash. Inside code and pre blocks only the backtick and the backslash; inside the (…) part of a link only the closing parenthesis and the backslash.

What does “can't parse entities: Character '.' is reserved” mean?

Your text contains one of the special characters without a backslash in front of it. Escape all user-supplied text before you put it into a MarkdownV2 message.

Should I escape the whole message?

No — only the parts that are plain text. If you escape the whole message, your own *bold* and _italic_ markers are escaped too and show up literally. Escape each variable, then put it into your template.

Is HTML easier?

Often, yes: with parse_mode=HTML only <, > and & need escaping (as &lt; &gt; &amp;).

How do I make a new line in MarkdownV2?

Put a real line break (\n) in the text. It needs no escaping.

How do I write a link in MarkdownV2?

[text](https://example.com). Escape special characters in the text part as usual; in the address only ) and \ need a backslash.