mirror of
https://github.com/aclist/dztui.git
synced 2026-10-30 14:42:54 +01:00
feat: dzgui 7 alpha
This commit is contained in:
1 parent
1acdbd58c5
commit
2e5b771137
150 files changed
+10359
No files matched your search
@@ -0,0 +1,44 @@
|
||||
import re
|
||||
|
||||
from dzgui.util.localize import number
|
||||
from dzgui.util.strings import no_mods
|
||||
|
||||
|
||||
def format_pango(text: str) -> str:
|
||||
medium = '<span size="medium"><b>'
|
||||
large = '<span size="large"><b>'
|
||||
xlarge = '<span size="x-large"><b>'
|
||||
text = re.sub("^# ", xlarge, text, flags=re.M)
|
||||
text = re.sub("^## ", large, text, flags=re.M)
|
||||
text = re.sub("^### ", medium, text, flags=re.M)
|
||||
text = re.sub(r"(<span size=.*)", r"\1</b></span>", text)
|
||||
return text
|
||||
|
||||
|
||||
def pluralize(plural: str, count: int) -> str:
|
||||
suffix = plural[-2:]
|
||||
if suffix == "es":
|
||||
base = plural[:-2]
|
||||
return f"{base}{'es'[:2*count ^ 2]}"
|
||||
else:
|
||||
base = plural[:-1]
|
||||
return f"{base}{'s'[:count ^ 1]}"
|
||||
|
||||
|
||||
def format_hyperlinks(text: str) -> str:
|
||||
def href(string: str) -> str:
|
||||
return f'<a href="{string}">{string}</a>'
|
||||
|
||||
reg = r"\s(www\.*?)"
|
||||
text = re.sub(reg, " http://" + r"\1", text)
|
||||
reg2 = r"(http.*?)([ ,\r\n]|$)"
|
||||
text = re.sub(reg2, href(r"\1") + r"\2", text)
|
||||
return text
|
||||
|
||||
|
||||
def format_mods(size: int, mods: int) -> str:
|
||||
if mods == 0:
|
||||
return no_mods
|
||||
l_size = number(size)
|
||||
plural = pluralize("mods", mods)
|
||||
return f"Found {mods:n} {plural} taking up {l_size} MiB"
|
||||
Reference in new issue
Block a user