tdlib / telegram-bot-api

Telegram Bot API server
https://core.telegram.org/bots
Boost Software License 1.0
2.94k stars 569 forks source link

Blockquote HTML syntax issues #592

Open gagarski opened 1 month ago

gagarski commented 1 month ago

Let me copy an HTML syntax example from docs to here:

<b>bold</b>, <strong>bold</strong>
<i>italic</i>, <em>italic</em>
<u>underline</u>, <ins>underline</ins>
<s>strikethrough</s>, <strike>strikethrough</strike>, <del>strikethrough</del>
<span class="tg-spoiler">spoiler</span>, <tg-spoiler>spoiler</tg-spoiler>
<b>bold <i>italic bold <s>italic bold strikethrough <span class="tg-spoiler">italic bold strikethrough spoiler</span></s> <u>underline italic bold</u></i> bold</b>
<a href="http://www.example.com/">inline URL</a>
<a href="tg://user?id=123456789">inline mention of a user</a>
<tg-emoji emoji-id="5368324170671202286">👍</tg-emoji>
<code>inline fixed-width code</code>
<pre>pre-formatted fixed-width code block</pre>
<pre><code class="language-python">pre-formatted fixed-width code block written in the Python programming language</code></pre>
<blockquote>Block quotation started\nBlock quotation continued\nThe last line of the block quotation</blockquote>
<blockquote expandable>Expandable block quotation started\nExpandable block quotation continued\nExpandable block quotation continued\nHidden by default part of the block quotation started\nExpandable block quotation continued\nThe last line of the block quotation</blockquote>

Even though it's not explicitly mentioned, line break in HTML mode (unlike real HTML) is represented by a literal newline symbol.

However, inside blockquote example we see \n character syntax. Quick experiments have shown me that when I send \n (either inside blockquote, or outside) it gets rendered as literal \n, i. e. hte following markup:

aaa<blockquote>bbb</blockquote><blockquote xxxx="">ccc\nddd</blockquote>

becomes this:

image

This seems to be a mistake in the example.

Besides that, I have two more questions/suggestions for new expandable blockquote syntax:

levlam commented 1 month ago

"\n" is the newline character with the code 0x0A there. The exact way to use it in a string depends on your programming language, but most popular languages allow to specify it as "\n" inside strings.

Can I send <blockquote expandable="expandable"> or <blockquote expandable="">.

Yes. Actually, <blockquote expandable> is a shortcut for <blockquote expandable="">.

It's impossible to check now (clients do not seem to support expandable quotes yet),

No need to use other clients for checking. You can just look at the response of sendMessage and the entities of the sent message.

Given that expandable is not a standard attribute for <blockquote> tag, it might be a good idea to provide more pedantic syntax, like <blockquote class="expandable">

Are you afraid of the possibility that the attribute expandable can be added to the blockquote tag someday?