diff --git a/src/djlint/formatter/expand.py b/src/djlint/formatter/expand.py index 76d20a0..85470f9 100644 --- a/src/djlint/formatter/expand.py +++ b/src/djlint/formatter/expand.py @@ -33,7 +33,6 @@ def expand_html(html: str, config: Config) -> str: break_char = config.break_before # html tags - break before - html = re.sub( re.compile( rf"{break_char}\K(?(?:{html_tags})\b(\"[^\"]*\"|'[^']*'|{{[^}}]*}}|[^'\">{{}}])*>)", diff --git a/src/djlint/formatter/indent.py b/src/djlint/formatter/indent.py index 16cf3b6..cf8e1ca 100644 --- a/src/djlint/formatter/indent.py +++ b/src/djlint/formatter/indent.py @@ -63,13 +63,13 @@ 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, ) or re.findall( re.compile( - rf"(<({slt_html})\b.+?>)(.*?)((\2)>$)", + rf"(<({slt_html})\b.+?>)(.*?)((\2)>[^<]*?$)", re.IGNORECASE | re.VERBOSE | re.MULTILINE, ), item, diff --git a/src/djlint/settings.py b/src/djlint/settings.py index aedd156..e478e0e 100644 --- a/src/djlint/settings.py +++ b/src/djlint/settings.py @@ -530,36 +530,6 @@ class Config: ) """ - # the contents of these tag blocks will be indented, then unindented - self.tag_indent: str = ( - self.template_indent - + """ - | (?:< - (?: - """ - + self.indent_html_tags - + """ - )\\b - ) - """ - ) - - self.tag_unindent: str = ( - r""" - ^ - """ - + self.template_unindent - + """ - | (?: - (?: - """ - + self.indent_html_tags - + """ - )\\b - ) - """ - ) - # these tags should be unindented and next line will be indented self.tag_unindent_line: str = r""" (?:\{%-?[ ]*?(?:elif|else|empty)) @@ -835,3 +805,33 @@ class Config: + """ """ ) + + # the contents of these tag blocks will be indented, then unindented + self.tag_indent: str = ( + self.template_indent + + """ + | (?:< + (?: + """ + + self.indent_html_tags + + """ + )\\b + ) + """ + ) + + self.tag_unindent: str = ( + r""" + ^ + """ + + self.template_unindent + + """ + | (?: + (?: + """ + + self.indent_html_tags + + """ + )\\b + ) + """ + ) diff --git a/tests/test_html.py b/tests/test_html.py index 103f7ed..7be665b 100644 --- a/tests/test_html.py +++ b/tests/test_html.py @@ -33,6 +33,18 @@ layout:
a b
+