Skip to content

Conversation

@r4rdsn
Copy link
Member

@r4rdsn r4rdsn commented Jun 10, 2020

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 rchrdsn@protonmail.ch

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 r4rdsn requested review from Kwaskoff and tnam0rken June 10, 2020 19:19
@r4rdsn r4rdsn added the help wanted Extra attention is needed label Jun 10, 2020
@r4rdsn r4rdsn force-pushed the markdown-v2 branch 3 times, most recently from 1077a3b to 609658b Compare June 11, 2020 01:35
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 <rchrdsn@protonmail.ch>
r4rdsn added 3 commits June 11, 2020 19:46
There is a bug in [aiogram](https://github.com/aiogram/aiogram) 2.8
which quotes markdown values as html and tagged 2.9 release outright
breaks markdown helpers. It was fixed a couple of days ago in a
referenced commit, so bot will use that version of aiogram as a
temporary measurement until it will be tagged.

Signed-off-by: alfred richardsn <rchrdsn@protonmail.ch>
Signed-off-by: alfred richardsn <rchrdsn@protonmail.ch>
Signed-off-by: alfred richardsn <rchrdsn@protonmail.ch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wanted Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants