Skip to content

Commit

Permalink
fix(formatter): fixed formatting on nested inline comments
Browse files Browse the repository at this point in the history
closes #423
  • Loading branch information
christopherpickering committed Oct 12, 2022
1 parent 400639d commit a86df43
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/djlint/formatter/indent.py
Expand Up @@ -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
):
Expand Down Expand Up @@ -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

Expand Down
21 changes: 20 additions & 1 deletion tests/test_django/test_comments.py
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit a86df43

Please sign in to comment.