Skip to content

Commit

Permalink
fix(formatter): fixed indent on inline block followed by inline templ…
Browse files Browse the repository at this point in the history
…ate block

closes #425
  • Loading branch information
christopherpickering committed Oct 13, 2022
1 parent b4cbcb4 commit 4a0bee6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/djlint/formatter/indent.py
Expand Up @@ -64,6 +64,7 @@ def indent_html(rawcode: str, config: Config) -> str:

# if a one-line, inline tag, just process it, only if line starts w/ it
# or if it is trailing text

elif (
(
re.findall(
Expand All @@ -74,6 +75,7 @@ def indent_html(rawcode: str, config: Config) -> str:
|(?:<(?:{always_self_closing_html})\b[^>]*?/?>[ \t]*?) # <img stuff />
|(?:<(?:{slt_html})\b[^>]*?/>[ \t]*?) # <img />
|(?:{{%[ ]*?({slt_template})[ ]+?.*?%}})(?:.*?)(?:{{%[ ]+?end(\3)[ ]+?.*?%}}[ \t]*?) # >>> match 3
|{config.ignored_inline_blocks}
)
+?[^<]*?$ # with no other tags following until end of line
""",
Expand Down
1 change: 0 additions & 1 deletion tests/test_config/test_files/test_config.py
Expand Up @@ -11,7 +11,6 @@
# pylint: disable=C0116

import os
from pathlib import Path

from click.testing import CliRunner

Expand Down
19 changes: 19 additions & 0 deletions tests/test_html/test_tag_span.py
Expand Up @@ -104,3 +104,22 @@ def test_span_leading_text(runner: CliRunner, tmp_file: TextIO) -> None:
{% endif %}
"""
)


def test_span_and_template(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(
tmp_file.name,
b"""{% block content %}
<span></span>{% blocktrans %}<div></div>{% endblocktrans %}
{% endblock content %}
""",
)
runner.invoke(djlint, [tmp_file.name, "--reformat"])

assert (
Path(tmp_file.name).read_text(encoding="utf8")
== """{% block content %}
<span></span>{% blocktrans %}<div></div>{% endblocktrans %}
{% endblock content %}
"""
)

0 comments on commit 4a0bee6

Please sign in to comment.