From 73645302fefb828edc35ef4e02e4d78943e80ae3 Mon Sep 17 00:00:00 2001 From: EgorKhabarov Date: Wed, 10 Jul 2024 16:49:00 +0200 Subject: [PATCH 1/2] Added the ability to make blockquote expandable --- telebot/formatting.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/telebot/formatting.py b/telebot/formatting.py index dd7309416..e536e1bb0 100644 --- a/telebot/formatting.py +++ b/telebot/formatting.py @@ -341,7 +341,7 @@ def mcite(content: str, escape: Optional[bool]=True) -> str: return content -def hcite(content: str, escape: Optional[bool]=True) -> str: +def hcite(content: str, escape: Optional[bool] = True, expandable: Optional[bool] = False) -> str: """ Returns a html-formatted block-quotation string. @@ -350,11 +350,17 @@ def hcite(content: str, escape: Optional[bool]=True) -> str: :param escape: True if you need to escape special characters. Defaults to True. :type escape: :obj:`bool` - + + :param expandable: True if you need the quote to be expandable. Defaults to False. + :type expandable: :obj:`bool` + :return: The formatted string. :rtype: :obj:`str` """ - return '
{}
'.format(escape_html(content) if escape else content) + return "{}".format( + " expandable" if expandable else "", + escape_html(content) if escape else content, + ) def apply_html_entities(text: str, entities: Optional[List], custom_subs: Optional[Dict[str, str]]) -> str: From 77e3f130936f9e5751ef84018c7b3f7496681c5a Mon Sep 17 00:00:00 2001 From: EgorKhabarov Date: Wed, 10 Jul 2024 17:47:31 +0200 Subject: [PATCH 2/2] Added the ability to make blockquote expandable --- telebot/formatting.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/telebot/formatting.py b/telebot/formatting.py index 51869a2a0..24299b51a 100644 --- a/telebot/formatting.py +++ b/telebot/formatting.py @@ -323,7 +323,7 @@ def hide_link(url: str) -> str: return f'' -def mcite(content: str, escape: Optional[bool]=True) -> str: +def mcite(content: str, escape: Optional[bool] = True, expandable: Optional[bool] = False) -> str: """ Returns a Markdown-formatted block-quotation string. @@ -333,11 +333,16 @@ def mcite(content: str, escape: Optional[bool]=True) -> str: :param escape: True if you need to escape special characters. Defaults to True. :type escape: :obj:`bool` + :param expandable: True if you need the quote to be expandable. Defaults to False. + :type expandable: :obj:`bool` + :return: The formatted string. :rtype: :obj:`str` """ content = escape_markdown(content) if escape else content - content = '\n'.join(['>' + line for line in content.split('\n')]) + content = "\n".join([">" + line for line in content.split("\n")]) + if expandable: + return f"**{content}||" return content