diff --git a/src/djlint/formatter/indent.py b/src/djlint/formatter/indent.py index f845ad1..0588892 100644 --- a/src/djlint/formatter/indent.py +++ b/src/djlint/formatter/indent.py @@ -63,7 +63,7 @@ def indent_html(rawcode: str, config: Config) -> str: # if a one-line, inline tag, just process it, only if line starts w/ it elif ( re.findall( - rf"(<({slt_html})>)(.*?)((\2)>[^<]*?$)", + rf"(^<({slt_html})>)(.*?)((\2)>[^<]*?$)", item, re.IGNORECASE | re.VERBOSE | re.MULTILINE, ) diff --git a/src/djlint/settings.py b/src/djlint/settings.py index ae847a3..66b1e37 100644 --- a/src/djlint/settings.py +++ b/src/djlint/settings.py @@ -746,18 +746,29 @@ class Config: """ ) + # either a template tag at the start of a line, + # a html tag at the start of a line, + # or an html tag as the end of a line. + # Nothing in between! self.tag_unindent: str = ( r""" ^ """ + self.template_unindent + """ - | (?: + | (?:^ (?: """ + self.indent_html_tags + """ )\\b ) + | (?: + (?: + """ + + self.indent_html_tags + + """ + )>$ + ) """ ) diff --git a/tests/test_html/test_alpinejs.py b/tests/test_html/test_alpinejs.py index 1747e9e..26ee25c 100644 --- a/tests/test_html/test_alpinejs.py +++ b/tests/test_html/test_alpinejs.py @@ -27,3 +27,22 @@ def test_alpine_js(runner: CliRunner, tmp_file: TextIO) -> None: ) assert output.exit_code == 0 + + +def test_alpine_nested_html(runner: CliRunner, tmp_file: TextIO) -> None: + output = reformat( + tmp_file, + runner, + b""" +
+ +