Fix regexp. use raw-strings

This commit is contained in:
Yax 2025-09-24 18:35:47 +02:00
parent 3ddaee4820
commit e961eeb5eb

View file

@ -87,7 +87,7 @@ def log(msg, *args):
def truncate(text, words=25):
"""Remove tags and truncate text to the specified number of words."""
return " ".join(re.sub("(?s)<.*?>", " ", text).split()[:words])
return " ".join(re.sub(r"(?s)<.*?>", " ", text).split()[:words])
def read_headers(text):
@ -113,8 +113,8 @@ def slugify(value):
value = (
unicodedata.normalize("NFKD", value).encode("ascii", "ignore").decode("ascii")
)
value = re.sub("[^\w\s-]", "", value).strip().lower()
return re.sub("[-\s]+", "-", value)
value = re.sub(r"[^\w\s-]", "", value).strip().lower()
return re.sub(r"[-\s]+", "-", value)
def read_content(filename, params):
@ -173,8 +173,8 @@ def clean_html_tag(text):
"""Remove HTML tags."""
while True:
original_text = text
text = re.sub("<\w+.*?>", "", text)
text = re.sub("<\/\w+>", "", text)
text = re.sub(r"<\w+.*?>", "", text)
text = re.sub(r"<\/\w+>", "", text)
if original_text == text:
break
return text