tellerbot icon indicating copy to clipboard operation
tellerbot copied to clipboard

Change MARKDOWN to MARKDOWN_V2

Open r4rdsn opened this issue 5 years ago • 0 comments

Markdown is now legacy parse mode and was superseded by MarkdownV2 (as per Telegram bot API: https://core.telegram.org/bots/api#markdownv2-style). This change is reflected in aiogram's quote function, so in order to not add reduntant escape characters, it had to be updated. It also allows nested, underline and strikethrough entities, which may be nice in some future.

Unfortunately, it means that a whole lot more characters now must be escaped. These characters: >#+-=|{}.! are not used in markup as of now but are still reserved and require escaping in any place of the message for some reason. For instance, .! reservation means that even translation strings themselves that have punctuation now have to be escaped when used in markdown, because formatter's field values are often should not be escaped (e. g. user links). Meanwhile, _{} reservation means that formatter's placeholders will be escaped with aiogram's markdown.escape_md function. So as a solution I've added an optional argument escape_md to i18n which escaped translation string but rolls back placeholders as they were afterwards.

All in all, the style update is a mixed bag. There are some new features which can be useful, but it complicates string construction as reserved characters should be watched much more closely, and some choices for markup characters (in particular, punctuation marks . and !) are questionable to say the least.

Signed-off-by: alfred richardsn [email protected]

Proposed Changes

  • Change parse_mode from MARKDOWN to MARKDOWN_V2
  • Escape characters in strings according to bot API

Should be tested on unstable bot more for merging.

By sending this contribution I hereby agree to the terms of Contributor License Agreement.

r4rdsn avatar Jun 10 '20 19:06 r4rdsn