import re
def make_urls_clickable(text):
"""Convert URLs in text to clickable HTML links."""
url_pattern = r"https?://(?:[-\w.])+(?:\:[0-9]+)?(?:/(?:[\w/_.])*(?:\?(?:[\w&=%.])*)?(?:\#(?:[\w.])*)?)?"
def replace_url(match):
url = match.group(0)
return f'{url}'
return re.sub(url_pattern, replace_url, text)
def create_safe_markdown_text(text, message_placeholder):
"""Create safe markdown text with proper encoding"""
safe_text = text.encode("utf-16", "surrogatepass").decode("utf-16")
message_placeholder.markdown(
safe_text.replace("\\n", "
"), unsafe_allow_html=True
)