Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to make blockquote expandable. #2343

Merged
merged 3 commits into from
Jul 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading