【发布时间】:2020-06-27 06:43:29
【问题描述】:
从 Telegram 的 Bot API 版本 4.5 开始,该 API 支持新的文本格式 MarkdownV2。这是以前 Markdown 支持的增强版本。
"specification" for MarkdownV2 说:
- 在内联链接定义的
(...)部分内,所有“)”和“\”都必须使用前面的“\”字符进行转义。- 在所有其他地方字符 '_'、'*'、'['、']'、'('、')'、'~'、'`'、'>'、'#'、'+ ', '-', '=', '|', '{', '}', '.', '!'必须使用前面的字符“\”进行转义。
为什么点. 字符需要转义?据我所知,它没有用于任何格式化语法。 Telegram 提供的语法示例肯定不会以那种方式使用.:
要使用此模式,请在 parse_mode 字段中传递 MarkdownV2。在您的消息中使用以下语法:
*bold \*text* _italic \*text_ __underline__ ~strikethrough~ *bold _italic bold ~italic bold strikethrough~ __underline italic bold___ bold* [inline URL](http://www.example.com/) [inline mention of a user](tg://user?id=123456789) `inline fixed-width code` ``` pre-formatted fixed-width code block ``` ```python pre-formatted fixed-width code block written in the Python programming language ```
【问题讨论】:
-
一个更好的问题是“为什么电报不能使用像样的 Markdown 库而不是手动转义所有内容。有点违背 Markdown 的目的.....
标签: escaping markdown telegram telegram-bot