Add escape_markup_text() utility function to safely escape special characters

This commit is contained in:
tr1x_em committed 2025-08-14 22:28:34 +05:30
1 parent eb243ab8e8
commit d53341a0c0
5 files changed
+95 -46

No files matched your search

+19
View File
@@ -1,3 +1,4 @@
import html
import json
import os
import threading
@@ -151,5 +152,23 @@ def is_special_workspace(client: dict) -> bool:
return False
def escape_markup_text(text: str) -> str:
"""
Escape special characters in text to make it safe for Pango markup.
Args:
text: Raw text that may contain special characters
Returns:
Escaped text safe for use in Pango markup
"""
if not text or not isinstance(text, str):
return ""
# Use html.escape to escape XML/HTML special characters
# This handles &, <, >, and quotes
return html.escape(text)