diff --git a/src/djlint/formatter/indent.py b/src/djlint/formatter/indent.py index adb3e2d..80e16c2 100644 --- a/src/djlint/formatter/indent.py +++ b/src/djlint/formatter/indent.py @@ -37,6 +37,7 @@ def indent_html(rawcode: str, config: Config) -> str: ignored_level = 0 for item in rawcode_flat_list: + # if a raw tag first line if not is_block_raw and is_ignored_block_opening(config, item): is_raw_first_line = True @@ -68,19 +69,32 @@ def indent_html(rawcode: str, config: Config) -> str: elif ( ( re.findall( - rf"""^(?:[^<\s].*?)? # start of a line, optionally with some text + re.compile( + rf"""^(?:[^<\s].*?)? # start of a line, optionally with some text (?: - (?:<({slt_html})>)(?:.*?)(?:[ \t]*?) # stuff >>>> match 1 - |(?:<({slt_html})\b[^>]+?>)(?:.*?)(?:[ \t]*?) # stuff >>> match 2 - |(?:<(?:{always_self_closing_html})\b[^>]*?/?>[ \t]*?) # - |(?:<(?:{slt_html})\b[^>]*?/>[ \t]*?) # - |(?:{{%[ ]*?({slt_template})[ ]+?.*?%}})(?:.*?)(?:{{%[ ]+?end(\3)[ ]+?.*?%}}[ \t]*?) # >>> match 3 + (?:<({slt_html})>)(?:.*?)(?:) # stuff >>>> match 1 + |(?:<({slt_html})\b[^>]+?>)(?:.*?)(?:) # stuff >>> match 2 + |(?:<(?:{always_self_closing_html})\b[^>]*?/?>) # + |(?:<(?:{slt_html})\b[^>]*?/>) # + |(?:{{%[ ]*?({slt_template})[ ]+?.*?%}})(?:.*?)(?:{{%[ ]+?end(?:\3)[ ]+?.*?%}}) # >>> match 3 |{config.ignored_inline_blocks} - ) - +?[^<]*?$ # with no other tags following until end of line + )[ \t]*? + (?: + .*? # anything + (?: # followed by another slt + (?:<({slt_html})>)(?:.*?)(?:) # stuff >>>> match 1 + |(?:<({slt_html})\b[^>]+?>)(?:.*?)(?:) # stuff >>> match 2 + |(?:<(?:{always_self_closing_html})\b[^>]*?/?>) # + |(?:<(?:{slt_html})\b[^>]*?/>) # + |(?:{{%[ ]*?({slt_template})[ ]+?.*?%}})(?:.*?)(?:{{%[ ]+?end(?:\6)[ ]+?.*?%}}) # >>> match 3 + |{config.ignored_inline_blocks} + )[ \t]*? + )*? # optional of course + [^<]*?$ # with no other tags following until end of line """, + re.IGNORECASE | re.VERBOSE | re.MULTILINE, + ), item, - re.IGNORECASE | re.VERBOSE | re.MULTILINE, ) ) and is_block_raw is False diff --git a/src/djlint/settings.py b/src/djlint/settings.py index d6a34b3..cf43b63 100644 --- a/src/djlint/settings.py +++ b/src/djlint/settings.py @@ -641,7 +641,8 @@ class Config: self.ignored_inline_blocks: str = r""" - | <(script|style).*?\ + | + | | {\*.*?\*} | {\#(?!.*djlint:[ ]*?(?:off|on)\b).*\#} | <\?php.*?\?> diff --git a/tests/test_html/test_tag_span.py b/tests/test_html/test_tag_span.py index 3c6e5db..4b8f7b5 100644 --- a/tests/test_html/test_tag_span.py +++ b/tests/test_html/test_tag_span.py @@ -105,6 +105,22 @@ def test_span_leading_text(runner: CliRunner, tmp_file: TextIO) -> None: """ ) + write_to_file( + tmp_file.name, + b"""

+ New You can now use this feature +

""", + ) + runner.invoke(djlint, [tmp_file.name, "--reformat"]) + + assert ( + Path(tmp_file.name).read_text(encoding="utf8") + == """

+ New You can now use this feature +

+""" + ) + def test_span_and_template(runner: CliRunner, tmp_file: TextIO) -> None: write_to_file(