mirror of
https://github.com/Hopiu/djLint.git
synced 2026-05-02 10:54:44 +00:00
fix(formatter): fixed poor indentation on span tags with leading text
closes #398
This commit is contained in:
parent
dd2172f01c
commit
8f36fec142
2 changed files with 21 additions and 12 deletions
|
|
@ -61,10 +61,11 @@ def indent_html(rawcode: str, config: Config) -> str:
|
||||||
tmp = (indent * indent_level) + item + "\n"
|
tmp = (indent * indent_level) + item + "\n"
|
||||||
|
|
||||||
# if a one-line, inline tag, just process it, only if line starts w/ it
|
# if a one-line, inline tag, just process it, only if line starts w/ it
|
||||||
|
# or if it is trailing text
|
||||||
elif (
|
elif (
|
||||||
(
|
(
|
||||||
re.findall(
|
re.findall(
|
||||||
rf"""^ # start of a line
|
rf"""^(?:[^<\s].*?)? # start of a line, optionally with some text
|
||||||
(?:
|
(?:
|
||||||
(?:<({slt_html})>)(?:.*?)(?:</(?:\1)>[ \t]*?) # <span>stuff</span> >>>> match 1
|
(?:<({slt_html})>)(?:.*?)(?:</(?:\1)>[ \t]*?) # <span>stuff</span> >>>> match 1
|
||||||
|(?:<({slt_html})\b[^>]+?>)(?:.*?)(?:</(?:\2)>[ \t]*?) # <span stuff>stuff</span> >>> match 2
|
|(?:<({slt_html})\b[^>]+?>)(?:.*?)(?:</(?:\2)>[ \t]*?) # <span stuff>stuff</span> >>> match 2
|
||||||
|
|
@ -147,19 +148,9 @@ def indent_html(rawcode: str, config: Config) -> str:
|
||||||
),
|
),
|
||||||
item,
|
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,
|
|
||||||
# )
|
|
||||||
and is_block_raw is False
|
and is_block_raw is False
|
||||||
):
|
):
|
||||||
|
|
||||||
tmp = (indent * indent_level) + item + "\n"
|
tmp = (indent * indent_level) + item + "\n"
|
||||||
indent_level = indent_level + 1
|
indent_level = indent_level + 1
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -86,3 +86,21 @@ def test_nested_string(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
</ul>
|
</ul>
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_span_leading_text(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
|
write_to_file(
|
||||||
|
tmp_file.name,
|
||||||
|
b"""{% if this %}<p>Text <span>text</span></p>{% endif %}""",
|
||||||
|
)
|
||||||
|
runner.invoke(djlint, [tmp_file.name, "--reformat"])
|
||||||
|
|
||||||
|
assert (
|
||||||
|
Path(tmp_file.name).read_text(encoding="utf8")
|
||||||
|
== """{% if this %}
|
||||||
|
<p>
|
||||||
|
Text <span>text</span>
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue