fix(formatter): fixed indent on inline block followed by inline template block

closes #425
This commit is contained in:
Christopher Pickering 2022-10-13 12:20:40 +02:00
parent b4cbcb45cd
commit 4a0bee6dc2
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
3 changed files with 21 additions and 1 deletions

View file

@ -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(
@ -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
""",

View file

@ -11,7 +11,6 @@ run::
# pylint: disable=C0116
import os
from pathlib import Path
from click.testing import CliRunner

View file

@ -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 %}
"""
)