Telegram markdown
с оф. страницы Телеграм
Formatting options
The Bot API supports basic formatting for messages. You can use bold, italic, underlined and strikethrough text, as well as inline links and pre-formatted code in your bots' messages. Telegram clients will render them accordingly. You can use either markdown-style or HTML-style formatting.
Note that Telegram clients will display an alert to the user before opening an inline link ('Open this link?' together with the full URL).
Message entities can be nested, providing following restrictions are met: - If two entities has common characters then one of them is fully contained inside another. - bold, italic, underline and strikethrough entities can contain and to be contained in any other entities, except pre and code. - All other entities can't contain each other.
Links tg://user?id=<user_id>
can be used to mention a user by their ID without using a username. Please note:
These links will work only if they are used inside an inline link. For example, they will not work, when used in an inline keyboard button or in a message text.
These mentions are only guaranteed to work if the user has contacted the bot in the past, has sent a callback query to the bot via inline button or is a member in the group where he was mentioned.
MarkdownV2 style
To use this mode, pass MarkdownV2 in the parse_mode field. Use the following syntax in your message:
Please note:
Any character with code between 1 and 126 inclusively can be escaped anywhere with a preceding '\' character, in which case it is treated as an ordinary character and not a part of the markup.
Inside
pre
andcode
entities, all '`' and '\' characters must be escaped with a preceding '\' character.Inside
(...)
part of inline link definition, all ')' and '\' must be escaped with a preceding '\' character.In all other places characters '_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!' must be escaped with the preceding character '\'.
In case of ambiguity between
italic
andunderline
entities__
is always greadily treated from left to right as beginning or end ofunderline
entity, so instead of___italic underline___
use___italic underline_\r__
, where\r
is a character with code 13, which will be ignored.
HTML style
To use this mode, pass HTML in the parse_mode field. The following tags are currently supported:
Please note:
Only the tags mentioned above are currently supported.
All
<
,>
and&
symbols that are not a part of a tag or an HTML entity must be replaced with the corresponding HTML entities (<
with<
,>
with>
and&
with&
).All numerical HTML entities are supported.
The API currently supports only the following named HTML entities:
<
,>
,&
and"
.Use nested
pre
andcode
tags, to define programming language forpre
entity.Programming language can't be specified for standalone
code
tags.
Markdown style
This is a legacy mode, retained for backward compatibility. To use this mode, pass Markdown in the parse_mode field. Use the following syntax in your message:
Please note:
Entities must not be nested, use parse mode MarkdownV2 instead.
There is no way to specify underline and strikethrough entities, use parse mode MarkdownV2 instead.
To escape characters '_', '*', '`', '[' outside of an entity, prepend the characters '\' before them.
Escaping inside entities is not allowed, so entity must be closed first and reopened again: use
_snake_\__case_
for italicsnake_case
and*2*\**2=4*
for bold2*2=4
.
Last updated