From 1c70ea624c771242183602b425365a2171f49cdb Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Wed, 6 Oct 2021 16:02:30 +0200 Subject: [PATCH] simplified regex to improve speed --- src/djlint/formatter/compress_html.py | 2 +- src/djlint/formatter/expand_html.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/djlint/formatter/compress_html.py b/src/djlint/formatter/compress_html.py index 65c1405..d707c4f 100644 --- a/src/djlint/formatter/compress_html.py +++ b/src/djlint/formatter/compress_html.py @@ -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*?()", + fr"(<({config.single_line_html_tags})(?:\s(?:(?:{{%[^(?:%}}]*?%}})|(?:{{{{[^(?:}}}})]*?}}}})|[^<>])*)?>)\s*([^<\n]{{,80}})\s*?()", re.IGNORECASE | re.MULTILINE | re.DOTALL | re.VERBOSE, ), r"\1\3\4", diff --git a/src/djlint/formatter/expand_html.py b/src/djlint/formatter/expand_html.py index 7fddeb5..8cf6ae9 100644 --- a/src/djlint/formatter/expand_html.py +++ b/src/djlint/formatter/expand_html.py @@ -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(])*>)", + fr"{break_char}\K(])*)?>)", 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"(])*>)(?=[^\n])", + fr"(])*)?>)(?=[^\n])", flags=re.IGNORECASE | re.VERBOSE, ), add_right,