fix(span): fixed indent on nested inline tags on a span

closes #383
This commit is contained in:
Christopher Pickering 2022-09-15 09:44:21 +02:00
parent 3c1c125595
commit 4ac5fd0da8
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
2 changed files with 32 additions and 1 deletions

View file

@ -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 <span><strong></strong>.
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 (

View file

@ -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:
</div>""",
) # noqa: E501
assert output.exit_code == 0
def test_nested_string(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(
tmp_file.name,
b"""<p><p><span><strong>asdf</strong><br></span></p></p>""",
)
runner.invoke(djlint, [tmp_file.name, "--reformat"])
assert (
Path(tmp_file.name).read_text(encoding="utf8")
== """<p>
<p>
<span><strong>asdf</strong>
<br>
</span>
</p>
</p>
"""
)