mirror of
https://github.com/Hopiu/djLint.git
synced 2026-03-16 21:40:24 +00:00
fix(alpine js): fix incorrect indent on alpinejs attribs w/ nested HTML
closes #381
This commit is contained in:
parent
0111619870
commit
f0d37a59d1
4 changed files with 33 additions and 3 deletions
|
|
@ -63,7 +63,7 @@ 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,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -746,18 +746,29 @@ class Config:
|
|||
"""
|
||||
)
|
||||
|
||||
# either a template tag at the start of a line,
|
||||
# a html tag at the start of a line,
|
||||
# or an html tag as the end of a line.
|
||||
# Nothing in between!
|
||||
self.tag_unindent: str = (
|
||||
r"""
|
||||
^
|
||||
"""
|
||||
+ self.template_unindent
|
||||
+ """
|
||||
| (?:</
|
||||
| (?:^</
|
||||
(?:
|
||||
"""
|
||||
+ self.indent_html_tags
|
||||
+ """
|
||||
)\\b
|
||||
)
|
||||
| (?:</
|
||||
(?:
|
||||
"""
|
||||
+ self.indent_html_tags
|
||||
+ """
|
||||
)>$
|
||||
)
|
||||
"""
|
||||
)
|
||||
|
|
|
|||
|
|
@ -27,3 +27,22 @@ def test_alpine_js(runner: CliRunner, tmp_file: TextIO) -> None:
|
|||
)
|
||||
|
||||
assert output.exit_code == 0
|
||||
|
||||
|
||||
def test_alpine_nested_html(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<html lang="en">
|
||||
<body>
|
||||
<!-- x-data , x-text , x-html -->
|
||||
<div x-data="{key:'value',message:'hello <b>world</b> '}">
|
||||
<p x-text="key"></p>
|
||||
<p x-html="message"></p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 0
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ run:
|
|||
pytest tests/test_html/test_tag_textarea.py --cov=src/djlint --cov-branch \
|
||||
--cov-report xml:coverage.xml --cov-report term-missing
|
||||
|
||||
pytest tests/test_html/test_tag_textarea.py::test_textarea_tag
|
||||
pytest tests/test_html/test_tag_textarea.py::test_a_tag
|
||||
|
||||
|
||||
"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue