8000 Add support for parsing multi-line blockquotes Β· aelkheir/python-telegram-bot@ba9cfcf Β· GitHub
[go: up one dir, main page]

Skip to content

Commit ba9cfcf

Browse files
committed
Add support for parsing multi-line blockquotes
1 parent 0af70b3 commit ba9cfcf

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

β€Žtelegram/_message.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3698,7 +3698,10 @@ def _parse_markdown(
36983698
raise ValueError(
36993699
"Blockquote entities are not supported for Markdown version 1"
37003700
)
3701-
insert = f">{escaped_text}"
3701+
prefix = ">" if entity.offset == 0 else "\n>"
3702+
message_length = len(str(message_text, encoding="utf-16-le")) # type: ignore
3703+
suffix = "" if entity.offset + entity.length - 1 == message_length else "\n"
3704+
insert = prefix + escaped_text.replace("\n", "\n>") + suffix
37023705
elif entity.type == MessageEntity.CUSTOM_EMOJI:
37033706
if version == 1:
37043707
raise ValueError(

β€Žtests/test_message.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,12 @@ class TestMessageBase:
375375
{"length": 7, "offset": 141, "type": "spoiler"},
376376
{"length": 2, "offset": 150, "type": "custom_emoji", "custom_emoji_id": "1"},
377377
{"length": 10, "offset": 154, "type": "blockquote"},
378+
{"length": 15, "offset": 166, "type": "blockquote"},
378379
]
379380
test_text_v2 = (
380381
r"Test for <bold, ita_lic, \`code, links, text-mention and `\pre. "
381382
"http://google.com and bold nested in strk>trgh nested in italic. Python pre. Spoiled. "
382-
"πŸ‘. blockquote."
383+
"πŸ‘. blockquote. Multiline\nquote"
383384
)
384385
test_message = Message(
385386
message_id=1,
@@ -585,7 +586,7 @@ def test_text_html_simple(self):
585586
'<pre><code class="python">Python pre</code></pre>. '
586587
'<span class="tg-spoiler">Spoiled</span>. '
587588
'<tg-emoji emoji-id="1">πŸ‘</tg-emoji>. '
588-
"<blockquote>blockquote</blockquote>."
589+
"<blockquote>blockquote</blockquote>. <blockquote>Multiline\nquote</blockquote>"
589590
)
590591
text_html = self.test_message_v2.text_html
591592
assert text_html == test_html_string
@@ -606,7 +607,7 @@ def test_text_html_urled(self):
606607
'<pre><code class="python">Python pre</code></pre>. '
607608
'<span class="tg-spoiler">Spoiled</span>. '
608609
'<tg-emoji emoji-id="1">πŸ‘</tg-emoji>. '
609-
"<blockquote>blockquote</blockquote>."
610+
"<blockquote>blockquote</blockquote>. <blockquote>Multiline\nquote</blockquote>"
610611
)
611612
text_html = self.test_message_v2.text_html_urled
612613
assert text_html == test_html_string
@@ -627,7 +628,8 @@ def test_text_markdown_v2_simple(self):
627628
"[links](http://github.com/abc\\\\\\)def), "
628629
"[text\\-mention](tg://user?id=123456789) and ```\\`\\\\pre```\\. "
629630
r"http://google\.com and _bold *nested in ~strk\>trgh~ nested in* italic_\. "
630-
"```python\nPython pre```\\. ||Spoiled||\\. ![πŸ‘](tg://emoji?id=1)\\. >blockquote\\."
631+
"```python\nPython pre```\\. ||Spoiled||\\. ![πŸ‘](tg://emoji?id=1)\\. "
632+
"\n>blockquote\n\\. \n>Multiline\n>quote"
631633
)
632634
text_markdown = self.test_message_v2.text_markdown_v2
633635
assert text_markdown == test_md_string
@@ -682,7 +684,7 @@ def test_text_markdown_v2_urled(self):
682684
"[text\\-mention](tg://user?id=123456789) and ```\\`\\\\pre```\\. "
683685
r"[http://google\.com](http://google.com) and _bold *nested in ~strk\>trgh~ "
684686
"nested in* italic_\\. ```python\nPython pre```\\. ||Spoiled||\\. "
685-
"![πŸ‘](tg://emoji?id=1)\\. >blockquote\\."
687+
"![πŸ‘](tg://emoji?id=1)\\. \n>blockquote\n\\. \n>Multiline\n>quote"
686688
)
687689
text_markdown = self.test_message_v2.text_markdown_v2_urled
688690
assert text_markdown == test_md_string
@@ -799,7 +801,7 @@ def test_caption_html_simple(self):
799801
'<pre><code class="python">Python pre</code></pre>. '
800802
'<span class="tg-spoiler">Spoiled</span>. '
801803
'<tg-emoji emoji-id="1">πŸ‘</tg-emoji>. '
802-
"<blockquote>blockquote</blockquote>."
804+
"<blockquote>blockquote</blockquote>. <blockquote>Multiline\nquote</blockquote>"
803805
)
804806
caption_html = self.test_message_v2.caption_html
805807
assert caption_html == test_html_string
@@ -820,7 +822,7 @@ def test_caption_html_urled(self):
820822
'<pre><code class="python">Python pre</code></pre>. '
821823
'<span class="tg-spoiler">Spoiled</span>. '
822824
'<tg-emoji emoji-id="1">πŸ‘</tg-emoji>. '
823-
"<blockquote>blockquote</blockquote>."
825+
"<blockquote>blockquote</blockquote>. <blockquote>Multiline\nquote</blockquote>"
824826
)
825827
caption_html = self.test_message_v2.caption_html_urled
826828
assert caption_html == test_html_string
@@ -841,7 +843,8 @@ def test_caption_markdown_v2_simple(self):
841843
"[links](http://github.com/abc\\\\\\)def), "
842844
"[text\\-mention](tg://user?id=123456789) and ```\\`\\\\pre```\\. "
843845
r"http://google\.com and _bold *nested in ~strk\>trgh~ nested in* italic_\. "
844-
"```python\nPython pre```\\. ||Spoiled||\\. ![πŸ‘](tg://emoji?id=1)\\. >blockquote\\."
846+
"```python\nPython pre```\\. ||Spoiled||\\. ![πŸ‘](tg://emoji?id=1)\\. "
847+
"\n>blockquote\n\\. \n>Multiline\n>quote"
845848
)
846849
caption_markdown = self.test_message_v2.caption_markdown_v2
847850
assert caption_markdown == test_md_string
@@ -869,7 +872,7 @@ def test_caption_markdown_v2_urled(self):
869872
"[text\\-mention](tg://user?id=123456789) and ```\\`\\\\pre```\\. "
870873
r"[http://google\.com](http://google.com) and _bold *nested in ~strk\>trgh~ "
871874
"nested in* italic_\\. ```python\nPython pre```\\. ||Spoiled||\\. "
872-
"![πŸ‘](tg://emoji?id=1)\\. >blockquote\\."
875+
"![πŸ‘](tg://emoji?id=1)\\. \n>blockquote\n\\. \n>Multiline\n>quote"
873876
)
874877
caption_markdown = self.test_message_v2.caption_markdown_v2_urled
875878
assert caption_markdown == test_md_string
@@ -1136,7 +1139,8 @@ async def test_reply_markdown_v2(self, monkeypatch, message):
11361139
"[links](http://github.com/abc\\\\\\)def), "
11371140
"[text\\-mention](tg://user?id=123456789) and ```\\`\\\\pre```\\. "
11381141
r"http://google\.com and _bold *nested in ~strk\>trgh~ nested in* italic_\. "
1139-
"```python\nPython pre```\\. ||Spoiled||\\. ![πŸ‘](tg://emoji?id=1)\\. >blockquote\\."
1142+
"```python\nPython pre```\\. ||Spoiled||\\. ![πŸ‘](tg://emoji?id=1)\\. "
1143+
"\n>blockquote\n\\. \n>Multiline\n>quote"
11401144
)
11411145

11421146
async def make_assertion(*_, **kwargs):
@@ -1178,7 +1182,7 @@ async def test_reply_html(self, monkeypatch, message):
11781182
'<pre><code class="python">Python pre</code></pre>. '
11791183
'<span class="tg-spoiler">Spoiled</span>. '
11801184
'<tg-emoji emoji-id="1">πŸ‘</tg-emoji>. '
1181-
"<blockquote>blockquote</blockquote>."
1185+
"<blockquote>blockquote</blockquote>. <blockquote>Multiline\nquote</blockquote>"
11821186
)
11831187

11841188
async def make_assertion(*_, **kwargs):

0 commit comments

Comments
Β (0)
0