simplified regex to improve speed

This commit is contained in:
Christopher Pickering 2021-10-06 16:02:30 +02:00
parent 2029496854
commit 1c70ea624c
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
2 changed files with 3 additions and 3 deletions

View file

@ -85,7 +85,7 @@ def compress_html(html: str, config: Config) -> str:
# put short single line tags on one line
html = re.sub(
re.compile(
fr"(<({config.single_line_html_tags})(?:[^<>])*>)\s*([^<\n]{{,80}})\s*?(</(\2)>)",
fr"(<({config.single_line_html_tags})(?:\s(?:(?:{{%[^(?:%}}]*?%}})|(?:{{{{[^(?:}}}})]*?}}}})|[^<>])*)?>)\s*([^<\n]{{,80}})\s*?(</(\2)>)",
re.IGNORECASE | re.MULTILINE | re.DOTALL | re.VERBOSE,
),
r"\1\3\4",

View file

@ -69,7 +69,7 @@ def expand_html(html: str, config: Config) -> str:
# html tags - break before
html = re.sub(
re.compile(
fr"{break_char}\K(</?(?:{html_tags})(?:[^<>])*>)",
fr"{break_char}\K(</?(?:{html_tags})(?:\s((?:{{%[^(?:%}}]*?%}})|(?:{{{{[^(?:}}}})]*?}}}})|[^<>])*)?>)",
flags=re.IGNORECASE | re.VERBOSE,
),
add_left,
@ -79,7 +79,7 @@ def expand_html(html: str, config: Config) -> str:
# html tags - break after
html = re.sub(
re.compile(
fr"(</?(?:{html_tags})(?:[^<>])*>)(?=[^\n])",
fr"(</?(?:{html_tags})(?:\s((?:{{%[^(?:%}}]*?%}})|(?:{{{{[^(?:}}}})]*?}}}})|[^<>])*)?>)(?=[^\n])",
flags=re.IGNORECASE | re.VERBOSE,
),
add_right,