diff --git a/djlint/formatter/indent.py b/djlint/formatter/indent.py index 50355f470..7d3af57de 100644 --- a/djlint/formatter/indent.py +++ b/djlint/formatter/indent.py @@ -125,7 +125,7 @@ def fix_handlebars_template_tags( re.search( rf"""^(?:[^<\s].*?)? # start of a line, optionally with some text (?: - <({slt_html})(?:(?:>|\b[^>]+?>)(?:.*?)(?:)|\b[^>]*?/>) # stuff or >>> match 1 + <({slt_html})(?:(?:>|\b[^>]+?>)(?:.*?)(?:)|\b(?:[^>"']|"[^"]*"|'[^']*')*?\/>) # stuff or >>> match 1 |(?:<(?:{always_self_closing_html})\b[^>]*?/?>) # |(?:{{%[ ]*?({slt_template})[ ]+?.*?%}})(?:.*?)(?:{{%[ ]+?end(?:\2)[ ]+?.*?%}}) # >>> match 2 |{config.ignored_inline_blocks} @@ -133,7 +133,7 @@ def fix_handlebars_template_tags( (?: .*? # anything (?: # followed by another slt - <({slt_html})(?:(?:>|\b[^>]+?>)(?:.*?)(?:)|\b[^>]*?/>) # stuff or >>> match 3 + <({slt_html})(?:(?:>|\b[^>]+?>)(?:.*?)(?:)|\b(?:[^>"']|"[^"]*"|'[^']*')*?\/>) # stuff or >>> match 3 |(?:<(?:{always_self_closing_html})\b[^>]*?/?>) # |(?:{{%[ ]*?({slt_template})[ ]+?.*?%}})(?:.*?)(?:{{%[ ]+?end(?:\4)[ ]+?.*?%}}) # >>> match 4 |{config.ignored_inline_blocks} diff --git a/tests/test_html/test_hyperscript.py b/tests/test_html/test_hyperscript.py new file mode 100644 index 000000000..d80c8a946 --- /dev/null +++ b/tests/test_html/test_hyperscript.py @@ -0,0 +1,42 @@ +"""Test for _hyperscript. + +uv run pytest tests/test_html/test_hyperscript.py +""" + +from __future__ import annotations + +from typing import TYPE_CHECKING + +import pytest + +from djlint.reformat import formatter +from tests.conftest import printer + +if TYPE_CHECKING: + from djlint.settings import Config + +test_data = [ + pytest.param( + ( + "
\n" + " Clicks:\n" + " 0\n" + "
\n" + ), + ( + "
\n" + " Clicks:\n" + " 0\n" + "
\n" + ), + id="html_tags_in_attributes", + ) +] + + +@pytest.mark.parametrize(("source", "expected"), test_data) +def test_base(source: str, expected: str, basic_config: Config) -> None: + output = formatter(basic_config, source) + + printer(expected, source, output) + assert expected == output