From 4ac5fd0da87bc0bf3ee49c5007db64ea4e34f46d Mon Sep 17 00:00:00 2001
From: Christopher Pickering
Date: Thu, 15 Sep 2022 09:44:21 +0200
Subject: [PATCH] fix(span): fixed indent on nested inline tags on a span
closes #383
---
src/djlint/formatter/indent.py | 11 +++++++++++
tests/test_html/test_tag_span.py | 22 +++++++++++++++++++++-
2 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/src/djlint/formatter/indent.py b/src/djlint/formatter/indent.py
index 0588892..de813d8 100644
--- a/src/djlint/formatter/indent.py
+++ b/src/djlint/formatter/indent.py
@@ -101,6 +101,17 @@ def indent_html(rawcode: str, config: Config) -> str:
)
and is_block_raw is False
and not is_safe_closing_tag(config, item)
+ # and not ending in a slt like .
+ and not re.findall(
+ rf"(<({slt_html})>)(.*?)((\2)>[^<]*?$)",
+ item,
+ re.IGNORECASE | re.VERBOSE | re.MULTILINE,
+ )
+ and not re.findall(
+ rf"(<({slt_html})\\b.+?>)(.*?)((\2)>[^<]*?$)",
+ item,
+ re.IGNORECASE | re.VERBOSE | re.MULTILINE,
+ )
):
# block to catch inline block followed by a non-break tag
if (
diff --git a/tests/test_html/test_tag_span.py b/tests/test_html/test_tag_span.py
index 21433fc..fd98117 100644
--- a/tests/test_html/test_tag_span.py
+++ b/tests/test_html/test_tag_span.py
@@ -5,7 +5,7 @@ run:
pytest tests/test_html/test_tag_span.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
- pytest tests/test_html/test_tag_span.py::test_span_tag
+ pytest tests/test_html/test_tag_span.py::test_nested_string
"""
@@ -45,3 +45,23 @@ def test_span_tag(runner: CliRunner, tmp_file: TextIO) -> None:
""",
) # noqa: E501
assert output.exit_code == 0
+
+
+def test_nested_string(runner: CliRunner, tmp_file: TextIO) -> None:
+ write_to_file(
+ tmp_file.name,
+ b"""asdf
""",
+ )
+ runner.invoke(djlint, [tmp_file.name, "--reformat"])
+
+ assert (
+ Path(tmp_file.name).read_text(encoding="utf8")
+ == """
+
+ asdf
+
+
+
+
+"""
+ )