Skip to content

Commit e2d6d62

Browse files
committed
Fix formatting on "/>" in HTML attributes
1 parent 0925564 commit e2d6d62

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

djlint/formatter/indent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,15 @@ def fix_handlebars_template_tags(
125125
re.search(
126126
rf"""^(?:[^<\s].*?)? # start of a line, optionally with some text
127127
(?:
128-
<({slt_html})(?:(?:>|\b[^>]+?>)(?:.*?)(?:</(?:\1)>)|\b[^>]*?/>) # <span stuff-or-not>stuff</span> or <img stuff /> >>> match 1
128+
<({slt_html})(?:(?:>|\b[^>]+?>)(?:.*?)(?:</(?:\1)>)|\b(?:[^>"']|"[^"]*"|'[^']*')*?\/>) # <span stuff-or-not>stuff</span> or <img stuff /> >>> match 1
129129
|(?:<(?:{always_self_closing_html})\b[^>]*?/?>) # <img stuff />
130130
|(?:{{%[ ]*?({slt_template})[ ]+?.*?%}})(?:.*?)(?:{{%[ ]+?end(?:\2)[ ]+?.*?%}}) # >>> match 2
131131
|{config.ignored_inline_blocks}
132132
)[ \t]*?
133133
(?:
134134
.*? # anything
135135
(?: # followed by another slt
136-
<({slt_html})(?:(?:>|\b[^>]+?>)(?:.*?)(?:</(?:\3)>)|\b[^>]*?/>) # <span stuff-or-not>stuff</span> or <img stuff /> >>> match 3
136+
<({slt_html})(?:(?:>|\b[^>]+?>)(?:.*?)(?:</(?:\3)>)|\b(?:[^>"']|"[^"]*"|'[^']*')*?\/>) # <span stuff-or-not>stuff</span> or <img stuff /> >>> match 3
137137
|(?:<(?:{always_self_closing_html})\b[^>]*?/?>) # <img stuff />
138138
|(?:{{%[ ]*?({slt_template})[ ]+?.*?%}})(?:.*?)(?:{{%[ ]+?end(?:\4)[ ]+?.*?%}}) # >>> match 4
139139
|{config.ignored_inline_blocks}

tests/test_html/test_hyperscript.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""Test for _hyperscript.
2+
3+
uv run pytest tests/test_html/test_hyperscript.py
4+
"""
5+
6+
from __future__ import annotations
7+
8+
from typing import TYPE_CHECKING
9+
10+
import pytest
11+
12+
from djlint.reformat import formatter
13+
from tests.conftest import printer
14+
15+
if TYPE_CHECKING:
16+
from djlint.settings import Config
17+
18+
test_data = [
19+
pytest.param(
20+
(
21+
"<div _='on click increment :x then put it into the <output/> in me'>\n"
22+
' Clicks:\n'
23+
' <output>0</output>\n'
24+
'</div>\n'
25+
),
26+
(
27+
"<div _='on click increment :x then put it into the <output/> in me'>\n"
28+
' Clicks:\n'
29+
' <output>0</output>\n'
30+
'</div>\n'
31+
),
32+
id="html_tags_in_attributes",
33+
),
34+
]
35+
36+
37+
@pytest.mark.parametrize(("source", "expected"), test_data)
38+
def test_base(source: str, expected: str, basic_config: Config) -> None:
39+
output = formatter(basic_config, source)
40+
41+
printer(expected, source, output)
42+
assert expected == output

0 commit comments

Comments
 (0)