diff --git a/src/djlint/settings.py b/src/djlint/settings.py index eb29fdc..4f7b399 100644 --- a/src/djlint/settings.py +++ b/src/djlint/settings.py @@ -486,22 +486,22 @@ class Config: ) self.attribute_pattern: str = ( r""" - (?:[^\s]+?=(?:\"[^\"]*?""" + (?:[^\s]+?[ ]*?=[ ]*?(?:\"[^\"]*?""" + self.template_if_for_pattern + r"""[^\"]*?\"|\'[^\']*?""" + self.template_if_for_pattern + r"""[^\']*?\')) - | (?:[^\s]+?=(?:\"[^\"]*?{{.*?}}[^\"]*?\"|\'[^\']*?{{.*?}}[^\']*?\')) + | (?:[^\s]+?[ ]*?=[ ]*?(?:\"[^\"]*?{{.*?}}[^\"]*?\"|\'[^\']*?{{.*?}}[^\']*?\')) | """ + self.template_if_for_pattern + r""" - | (?:[^\s]+?=(?:\"(?:[^\"]*?{%[^}]*?%}[^\"]*?)+?\")) - | (?:[^\s]+?=(?:\'(?:[^\']*?{%[^}]*?%}[^\']*?)+?\')) - | (?:[^\s]+?=(?:\".*?\"|\'.*?\')) + | (?:[^\s]+?[ ]*?=[ ]*?(?:\"(?:[^\"]*?{%[^}]*?%}[^\"]*?)+?\")) + | (?:[^\s]+?[ ]*?=[ ]*?(?:\'(?:[^\']*?{%[^}]*?%}[^\']*?)+?\')) + | (?:[^\s]+?[ ]*?=[ ]*?(?:\".*?\"|\'.*?\')) | required | checked | (?:\w|-|\.)+ - | (?:\w|-|\.)+=(?:\w|-)+ + | (?:\w|-|\.)+[ ]*?=[ ]*?(?:\w|-)+ | {{.*?}} | {%.*?%} """ diff --git a/tests/test_html/test_attributes.py b/tests/test_html/test_attributes.py index ce820f8..89ca379 100644 --- a/tests/test_html/test_attributes.py +++ b/tests/test_html/test_attributes.py @@ -83,6 +83,14 @@ def test_long_attributes(runner: CliRunner, tmp_file: TextIO) -> None: ) assert output.exit_code == 0 + # attributes with space around = are not brocken + output = reformat( + tmp_file, + runner, + b"""Test\n""", + ) + assert output.exit_code == 0 + def test_ignored_attributes(runner: CliRunner, tmp_file: TextIO) -> None: output = reformat(