[feat] startpage: support for news and images

This commit is contained in:
Bnyro 2025-02-13 11:43:45 +01:00 committed by Markus Heiser
parent feb15e3878
commit 0f2fc5879d
3 changed files with 143 additions and 77 deletions

View file

@ -470,6 +470,21 @@ def ecma_unescape(string: str) -> str:
return string
def remove_pua_from_str(string):
"""Removes unicode's "PRIVATE USE CHARACTER"s (PUA_) from a string.
_PUA: https://en.wikipedia.org/wiki/Private_Use_Areas
"""
pua_ranges = ((0xE000, 0xF8FF), (0xF0000, 0xFFFFD), (0x100000, 0x10FFFD))
s = []
for c in string:
i = ord(c)
if any(a <= i <= b for (a, b) in pua_ranges):
continue
s.append(c)
return "".join(s)
def get_string_replaces_function(replaces: Dict[str, str]) -> Callable[[str], str]:
rep = {re.escape(k): v for k, v in replaces.items()}
pattern = re.compile("|".join(rep.keys()))