Why is '.' a reserved character in MarkdownV2 in Telegram's Bot API?
Asked Answered
Q

1

17

As of Telegram's Bot API version 4.5, the API supports a new text format, MarkdownV2. This is an enhanced version of the previous Markdown support.

The "specification" for MarkdownV2 says:

  • 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 '\'.

Why does the dot . character need to be escaped? As far as I can see, it isn't used in any formatting syntax. The syntax examples that Telegram provides certainly doesn't use . in that way:

To use this mode, pass MarkdownV2 in the parse_mode field. Use the following syntax in your message:

*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
```
Quadrireme answered 26/6, 2020 at 18:12 Comment(1)
A better question would be "Why can't telegram use a decent Markdown library instead of this escape everything manually. Sort of defeats the purpose of Markdown.....Jimmie
D
12

I don't know about Telegram specifically, but Markdown uses . as part of ordered lists, e.g.:

1. One
1. Two
1. Three

which renders as:

  1. One
  2. Two
  3. Three

Note that in the original spec the number used doesn't matter; Markdown renumbers for you.

In contrast,

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

renders as

1. One 1. Two 1. Three

Dossal answered 26/6, 2020 at 18:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.