Skip to content

Commit

Permalink
Merge pull request #2343 from EgorKhabarov/develop
Browse files Browse the repository at this point in the history
Added the ability to make blockquote expandable.
  • Loading branch information
Badiboy authored Jul 10, 2024
2 parents f9f525b + 77e3f13 commit e97e33e
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions telebot/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def hide_link(url: str) -> str:
return f'<a href="{url}">&#8288;</a>'


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.
Expand All @@ -333,15 +333,20 @@ 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


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.
Expand All @@ -350,11 +355,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 '<blockquote>{}</blockquote>'.format(escape_html(content) if escape else content)
return "<blockquote{}>{}</blockquote>".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:
Expand Down

0 comments on commit e97e33e

Please sign in to comment.