【问题标题】:Why is '.' a reserved character in MarkdownV2 in Telegram's Bot API?为什么是 '。' Telegram 的 Bot API 中 MarkdownV2 中的保留字符?
【发布时间】: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


【解决方案1】:

我不具体了解 Telegram,但 Markdown 使用 . 作为有序列表的一部分,例如:

1. One
1. Two
1. Three

呈现为:

  1. 一个
  2. 两个
  3. 三个

请注意,在原始规范中,使用的数字无关紧要; Markdown 为您重新编号。

相比之下,

1\. One
1\. Two
1\. Three

呈现为

1。一 1. 两个 1.三个

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-13
    • 1970-01-01
    • 2016-03-14
    • 1970-01-01
    • 2018-01-07
    • 1970-01-01
    • 1970-01-01
    • 2018-04-07
    相关资源
    最近更新 更多