Fix regexp. use raw-strings
This commit is contained in:
parent
3ddaee4820
commit
e961eeb5eb
1 changed files with 5 additions and 5 deletions
10
makesite.py
10
makesite.py
|
@ -87,7 +87,7 @@ def log(msg, *args):
|
||||||
|
|
||||||
def truncate(text, words=25):
|
def truncate(text, words=25):
|
||||||
"""Remove tags and truncate text to the specified number of words."""
|
"""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):
|
def read_headers(text):
|
||||||
|
@ -113,8 +113,8 @@ def slugify(value):
|
||||||
value = (
|
value = (
|
||||||
unicodedata.normalize("NFKD", value).encode("ascii", "ignore").decode("ascii")
|
unicodedata.normalize("NFKD", value).encode("ascii", "ignore").decode("ascii")
|
||||||
)
|
)
|
||||||
value = re.sub("[^\w\s-]", "", value).strip().lower()
|
value = re.sub(r"[^\w\s-]", "", value).strip().lower()
|
||||||
return re.sub("[-\s]+", "-", value)
|
return re.sub(r"[-\s]+", "-", value)
|
||||||
|
|
||||||
|
|
||||||
def read_content(filename, params):
|
def read_content(filename, params):
|
||||||
|
@ -173,8 +173,8 @@ def clean_html_tag(text):
|
||||||
"""Remove HTML tags."""
|
"""Remove HTML tags."""
|
||||||
while True:
|
while True:
|
||||||
original_text = text
|
original_text = text
|
||||||
text = re.sub("<\w+.*?>", "", text)
|
text = re.sub(r"<\w+.*?>", "", text)
|
||||||
text = re.sub("<\/\w+>", "", text)
|
text = re.sub(r"<\/\w+>", "", text)
|
||||||
if original_text == text:
|
if original_text == text:
|
||||||
break
|
break
|
||||||
return text
|
return text
|
||||||
|
|
Loading…
Add table
Reference in a new issue