From d288b78a1800a63c4d2cb090ef84507a2b1ca4fd Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Mon, 12 Jun 2023 15:32:52 -0500 Subject: [PATCH] fix(formatter): fixed wild match on template tags closes #686 --- src/djlint/settings.py | 3 ++- tests/test_django/test_for.py | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/djlint/settings.py b/src/djlint/settings.py index 282990930..010a24d12 100644 --- a/src/djlint/settings.py +++ b/src/djlint/settings.py @@ -520,6 +520,7 @@ def __init__( self.indent_template_tags: str = ( (rf"(?!{self.ignore_blocks})" if self.ignore_blocks else "") + r""" (?:if + | ifchanged | for | block(?!trans|translate) | spaceless @@ -540,7 +541,7 @@ def __init__( | set(?!(?:(?!%}).)*=) """ + self.custom_blocks - + r")" + + r")\b" ) self.template_indent: str = ( diff --git a/tests/test_django/test_for.py b/tests/test_django/test_for.py index 77d26c18c..6dfc04442 100644 --- a/tests/test_django/test_for.py +++ b/tests/test_django/test_for.py @@ -23,6 +23,15 @@ ), id="for_tag", ), + pytest.param( + ("{% for i in items %}\n" "
{% formfield i %}
\n" "{% endfor %}"), + ( + "{% for i in items %}\n" + "
{% formfield i %}
\n" + "{% endfor %}\n" + ), + id="test nested formfield", + ), ]