diff --git a/djlint/formatter/indent.py b/djlint/formatter/indent.py
index cf395765..7803eb6b 100644
--- a/djlint/formatter/indent.py
+++ b/djlint/formatter/indent.py
@@ -68,7 +68,7 @@ def fix_handlebars_template_tags(
# handlebars templates
rawcode = regex_utils.sub(r"({{#(?:each|if).+?[^ ])(}})", func, rawcode)
- rawcode_flat_list = regex_utils.split("\n", rawcode)
+ rawcode_flat_list = rawcode.split("\n")
indent = config.indent
@@ -123,7 +123,7 @@ def fix_handlebars_template_tags(
) or (
not is_block_raw
and (
- regex_utils.search(
+ regex_utils.search_cached(
rf"""^(?:[^<\s].*?)? # start of a line, optionally with some text
(?:
<({slt_html})(?:(?:>|\b[^>]+?>)(?:.*?)(?:(?:\1)>)|\b[^>]*?/>) # stuff or
>>> match 1
@@ -237,12 +237,12 @@ def fix_handlebars_template_tags(
flags=RE_FLAGS_IMX,
)
) or (
- regex_utils.search(
+ not is_block_raw
+ and regex_utils.search(
r"^(?:" + str(config.tag_indent) + r")",
item,
flags=RE_FLAGS_IMX,
)
- and not is_block_raw
):
tmp = (indent * indent_level) + item + "\n"
indent_level += 1
diff --git a/djlint/helpers.py b/djlint/helpers.py
index 37bd43e3..febbf525 100644
--- a/djlint/helpers.py
+++ b/djlint/helpers.py
@@ -55,7 +55,7 @@ def is_ignored_block_opening(config: Config, item: str) -> bool:
else 0
)
return bool(
- regex_utils.search(
+ regex_utils.search_cached(
config.ignored_block_opening, item[last_index:], flags=RE_FLAGS_IX
)
)
@@ -95,6 +95,8 @@ def inside_protected_trans_block(
True = non indentable > inside ignored trans block
False = indentable > either inside a trans trimmed block, or somewhere else, but not a trans non trimmed :)
"""
+ if "endblocktrans" not in match.group():
+ return False
close_block = regex_utils.search(
config.ignored_trans_blocks_closing, match.group(), flags=RE_FLAGS_IX
)
@@ -173,7 +175,7 @@ def is_ignored_block_closing(config: Config, item: str) -> bool:
else 0
)
return bool(
- regex_utils.search(
+ regex_utils.search_cached(
config.ignored_block_closing, item[last_index:], flags=RE_FLAGS_IX
)
)
diff --git a/djlint/regex_utils.py b/djlint/regex_utils.py
index 07b74708..2d29fa4a 100644
--- a/djlint/regex_utils.py
+++ b/djlint/regex_utils.py
@@ -23,6 +23,13 @@ def search(
return _compile_cached(pattern, flags=flags).search(string)
+@cache
+def search_cached(
+ pattern: str, string: str, /, *, flags: int = 0
+) -> re.Match[str] | None:
+ return _compile_cached(pattern, flags=flags).search(string)
+
+
def sub(
pattern: str,
repl: str | Callable[[re.Match[str]], str],
diff --git a/djlint/rules/H025.py b/djlint/rules/H025.py
index cff2e230..22502cfe 100644
--- a/djlint/rules/H025.py
+++ b/djlint/rules/H025.py
@@ -37,7 +37,7 @@ def run(
orphan_tags: list[re.Match[str]] = []
regex_str = r"<(/?(\w+))\s*(" + config.attribute_pattern + r"|\s*)*\s*?>"
for match in regex_utils.finditer(regex_str, html, flags=re.X):
- if match.group(1) and not regex_utils.search(
+ if match.group(1) and not regex_utils.search_cached(
rf"^/?{config.always_self_closing_html_tags}\b",
match.group(1),
flags=RE_FLAGS_IX,