mirror of
https://github.com/Hopiu/djLint.git
synced 2026-05-02 02:44:43 +00:00
fix(formatter): fix to prevent formatter from breaking malformed attribute tags
closes #317
This commit is contained in:
parent
69ef16afa8
commit
80263b29bd
2 changed files with 14 additions and 6 deletions
|
|
@ -486,22 +486,22 @@ class Config:
|
||||||
)
|
)
|
||||||
self.attribute_pattern: str = (
|
self.attribute_pattern: str = (
|
||||||
r"""
|
r"""
|
||||||
(?:[^\s]+?=(?:\"[^\"]*?"""
|
(?:[^\s]+?[ ]*?=[ ]*?(?:\"[^\"]*?"""
|
||||||
+ self.template_if_for_pattern
|
+ self.template_if_for_pattern
|
||||||
+ r"""[^\"]*?\"|\'[^\']*?"""
|
+ r"""[^\"]*?\"|\'[^\']*?"""
|
||||||
+ self.template_if_for_pattern
|
+ self.template_if_for_pattern
|
||||||
+ r"""[^\']*?\'))
|
+ r"""[^\']*?\'))
|
||||||
| (?:[^\s]+?=(?:\"[^\"]*?{{.*?}}[^\"]*?\"|\'[^\']*?{{.*?}}[^\']*?\'))
|
| (?:[^\s]+?[ ]*?=[ ]*?(?:\"[^\"]*?{{.*?}}[^\"]*?\"|\'[^\']*?{{.*?}}[^\']*?\'))
|
||||||
| """
|
| """
|
||||||
+ self.template_if_for_pattern
|
+ self.template_if_for_pattern
|
||||||
+ r"""
|
+ r"""
|
||||||
| (?:[^\s]+?=(?:\"(?:[^\"]*?{%[^}]*?%}[^\"]*?)+?\"))
|
| (?:[^\s]+?[ ]*?=[ ]*?(?:\"(?:[^\"]*?{%[^}]*?%}[^\"]*?)+?\"))
|
||||||
| (?:[^\s]+?=(?:\'(?:[^\']*?{%[^}]*?%}[^\']*?)+?\'))
|
| (?:[^\s]+?[ ]*?=[ ]*?(?:\'(?:[^\']*?{%[^}]*?%}[^\']*?)+?\'))
|
||||||
| (?:[^\s]+?=(?:\".*?\"|\'.*?\'))
|
| (?:[^\s]+?[ ]*?=[ ]*?(?:\".*?\"|\'.*?\'))
|
||||||
| required
|
| required
|
||||||
| checked
|
| checked
|
||||||
| (?:\w|-|\.)+
|
| (?:\w|-|\.)+
|
||||||
| (?:\w|-|\.)+=(?:\w|-)+
|
| (?:\w|-|\.)+[ ]*?=[ ]*?(?:\w|-)+
|
||||||
| {{.*?}}
|
| {{.*?}}
|
||||||
| {%.*?%}
|
| {%.*?%}
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,14 @@ def test_long_attributes(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
)
|
)
|
||||||
assert output.exit_code == 0
|
assert output.exit_code == 0
|
||||||
|
|
||||||
|
# attributes with space around = are not brocken
|
||||||
|
output = reformat(
|
||||||
|
tmp_file,
|
||||||
|
runner,
|
||||||
|
b"""<a href = "http://test.test:3000/testtesttesttesttesttesttesttesttesttest">Test</a>\n""",
|
||||||
|
)
|
||||||
|
assert output.exit_code == 0
|
||||||
|
|
||||||
|
|
||||||
def test_ignored_attributes(runner: CliRunner, tmp_file: TextIO) -> None:
|
def test_ignored_attributes(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
output = reformat(
|
output = reformat(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue