diff --git a/src/djlint/formatter/indent.py b/src/djlint/formatter/indent.py index c9637048..989d4e8f 100644 --- a/src/djlint/formatter/indent.py +++ b/src/djlint/formatter/indent.py @@ -54,7 +54,9 @@ def indent_html(rawcode: str, config: Config) -> str: if ( re.findall( - config.ignored_inline_blocks, item, flags=re.IGNORECASE | re.VERBOSE + rf"^\s*?(?:{config.ignored_inline_blocks})", + item, + flags=re.IGNORECASE | re.VERBOSE | re.MULTILINE, ) and is_block_raw is False ): @@ -150,7 +152,6 @@ def indent_html(rawcode: str, config: Config) -> str: ) and is_block_raw is False ): - tmp = (indent * indent_level) + item + "\n" indent_level = indent_level + 1 diff --git a/tests/test_django/test_comments.py b/tests/test_django/test_comments.py index 232751bb..3eb252f2 100644 --- a/tests/test_django/test_comments.py +++ b/tests/test_django/test_comments.py @@ -5,7 +5,7 @@ pytest tests/test_django/test_comments.py --cov=src/djlint --cov-branch \ --cov-report xml:coverage.xml --cov-report term-missing - pytest tests/test_django/test_comments.py::test_comment + pytest tests/test_django/test_comments.py::test_nested_inline_comment """ # pylint: disable=C0116 @@ -133,3 +133,22 @@ def test_inline_comment(runner: CliRunner, tmp_file: TextIO) -> None: ) assert output.text == """{#
#}\n{% if this %}
{% endif %}\n""" assert output.exit_code == 0 + + +def test_nested_inline_comment(runner: CliRunner, tmp_file: TextIO) -> None: + output = reformat( + tmp_file, + runner, + b"""
+ {% if 1 %} +
+
+
+
+ {% endif %} +""", + ) + + assert output.exit_code == 0