fix(formatter): fixed formatting on nested inline comments

closes #423
This commit is contained in:
Christopher Pickering 2022-10-12 08:49:55 +02:00
parent 400639d607
commit a86df438b5
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
2 changed files with 23 additions and 3 deletions

View file

@ -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

View file

@ -5,7 +5,7 @@ run::
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 == """{# <div></div> #}\n{% if this %}<div></div>{% endif %}\n"""
assert output.exit_code == 0
def test_nested_inline_comment(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
b"""<div>
{% if 1 %}
<div class="{% if 1 %}class {% else %} class {% endif %}">
<div class="class"
data-parameters="{#?@ViewBag.DefaultFilters#}"
data-target="profile-{{ profile_type }}-{{ profile_id }}">
</div>
</div>
{% endif %}
""",
)
assert output.exit_code == 0