Spaces:
Sleeping
Sleeping
File size: 737 Bytes
ca4eb6d 11ae35a ca4eb6d 89ad488 ca4eb6d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
from html import escape
from re import compile as compilere
from re import sub
async def cleanhtml(raw_html: str) -> str:
"""Clean html data."""
cleanr = compilere("<.*?>")
return sub(cleanr, "", raw_html)
async def escape_markdown(text: str) -> str:
"""Escape markdown data."""
escape_chars = r"\*_`\["
return sub(f"([{escape_chars}])", r"\\\1", text)
async def mention_html(name: str, user_id: int) -> str:
"""Mention user in html format."""
name = escape(name)
return f'<a href="tg://user?id={user_id}">{name}</a>'
async def mention_markdown(name: str, user_id: int) -> str:
"""Mention user in markdown format."""
return f"[{(await escape_markdown(name))}](tg://user?id={user_id})"
|