diff --git a/src/djlint/formatter/indent.py b/src/djlint/formatter/indent.py index df2eaee..c963704 100644 --- a/src/djlint/formatter/indent.py +++ b/src/djlint/formatter/indent.py @@ -61,10 +61,11 @@ def indent_html(rawcode: str, config: Config) -> str: tmp = (indent * indent_level) + item + "\n" # if a one-line, inline tag, just process it, only if line starts w/ it + # or if it is trailing text elif ( ( re.findall( - rf"""^ # start of a line + rf"""^(?:[^<\s].*?)? # start of a line, optionally with some text (?: (?:<({slt_html})>)(?:.*?)(?:[ \t]*?) # stuff >>>> match 1 |(?:<({slt_html})\b[^>]+?>)(?:.*?)(?:[ \t]*?) # stuff >>> match 2 @@ -147,19 +148,9 @@ def indent_html(rawcode: str, config: Config) -> str: ), item, ) - # # and not ending in a slt like . - # and not re.findall( - # rf"(<({slt_html})>)(.*?)([^<]*?$)", - # item, - # re.IGNORECASE | re.VERBOSE | re.MULTILINE, - # ) - # and not re.findall( - # rf"(<({slt_html})\\b.+?>)(.*?)([^<]*?$)", - # item, - # re.IGNORECASE | re.VERBOSE | re.MULTILINE, - # ) and is_block_raw is False ): + tmp = (indent * indent_level) + item + "\n" indent_level = indent_level + 1 diff --git a/tests/test_html/test_tag_span.py b/tests/test_html/test_tag_span.py index 3fef8fb..ab423b6 100644 --- a/tests/test_html/test_tag_span.py +++ b/tests/test_html/test_tag_span.py @@ -86,3 +86,21 @@ def test_nested_string(runner: CliRunner, tmp_file: TextIO) -> None: """ ) + + +def test_span_leading_text(runner: CliRunner, tmp_file: TextIO) -> None: + write_to_file( + tmp_file.name, + b"""{% if this %}

Text text

{% endif %}""", + ) + runner.invoke(djlint, [tmp_file.name, "--reformat"]) + + assert ( + Path(tmp_file.name).read_text(encoding="utf8") + == """{% if this %} +

+ Text text +

+{% endif %} +""" + )