Spaces:
Runtime error
Runtime error
Download utils/html.py from qqqsfasdf/Games-In-Arabic: direct link, hf CLI and curl.
- Browser
- Download file 1.35 kB
-
https://huggingface.co/spaces/qqqsfasdf/Games-In-Arabic/resolve/main/utils/html.py
- Command line
-
hf download hf://spaces/qqqsfasdf/Games-In-Arabic/utils/html.py
-
curl -L -o html.py https://huggingface.co/spaces/qqqsfasdf/Games-In-Arabic/resolve/main/utils/html.py
1.35 kB
| # utils/html.py | |
| import re | |
| def esc(text: str) -> str: | |
| if not text: | |
| return "" | |
| return str(text).replace("&", "&").replace("<", "<").replace(">", ">") | |
| def b(text: str) -> str: | |
| return f"<b>{esc(text)}</b>" | |
| def i(text: str) -> str: | |
| return f"<i>{esc(text)}</i>" | |
| def bq(text: str, expandable: bool = False) -> str: | |
| if expandable: | |
| return f"<blockquote expandable>{text}</blockquote>" | |
| return f"<blockquote>{text}</blockquote>" | |
| def code(text: str) -> str: | |
| return f"<code>{esc(text)}</code>" | |
| def link(label: str, url: str) -> str: | |
| safe_label = esc(label) | |
| return f'<a href="{url}">{safe_label}</a>' | |
| def clean_steam_html(html_str: str) -> str: | |
| """تحويل HTML متطلبات Steam إلى نص عربي نظيف.""" | |
| if not html_str: | |
| return "" | |
| text = re.sub(r'<br\s*/?>', '\n', html_str) | |
| text = re.sub(r'<li>', '• ', text) | |
| text = re.sub(r'</li>', '\n', text) | |
| text = re.sub(r'<strong>(.*?)</strong>', r'*\1*', text) | |
| text = re.sub(r'<ul[^>]*>', '', text) | |
| text = re.sub(r'</ul>', '', text) | |
| text = re.sub(r'<[^>]+>', '', text) | |
| text = re.sub(r'&', '&', text) | |
| text = re.sub(r'<', '<', text) | |
| text = re.sub(r'>', '>', text) | |
| text = re.sub(r' ', ' ', text) | |
| text = re.sub(r'\n{3,}', '\n\n', text) | |
| return text.strip() | |