mirror of
https://github.com/Hopiu/djLint.git
synced 2026-03-16 21:40:24 +00:00
fix(formatter): fixed indent on inline block followed by inline template block
closes #425
This commit is contained in:
parent
b4cbcb45cd
commit
4a0bee6dc2
3 changed files with 21 additions and 1 deletions
|
|
@ -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
|
||||
""",
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ run::
|
|||
# pylint: disable=C0116
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from click.testing import CliRunner
|
||||
|
||||
|
|
|
|||
|
|
@ -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 %}
|
||||
"""
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue