fixed issue with dj inline commments begin split up

This commit is contained in:
Christopher Pickering 2021-09-21 12:50:35 +02:00
parent 8db6e65022
commit 0da7612809
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
3 changed files with 16 additions and 17 deletions

View file

@ -23,8 +23,8 @@ def _flatten_attributes(match: re.Match) -> str:
def _should_ignore(config: Config, html: str, match: re.Match) -> bool:
"""Do not add whitespace if the tag is in a non indent block."""
for block in config.ignored_blocks:
return any(
return any(
any(
ignored_match.start() < match.start(1)
and ignored_match.end() > match.end(1)
for ignored_match in re.finditer(
@ -33,8 +33,8 @@ def _should_ignore(config: Config, html: str, match: re.Match) -> bool:
re.DOTALL | re.IGNORECASE | re.VERBOSE,
)
)
return False
for block in config.ignored_blocks
)
def expand_html(html: str, config: Config) -> str:

View file

@ -369,7 +369,7 @@ class Config:
r"<(script|style|pre|textarea).*?(?:%s).*?</(\1)>",
r"<!--.*?(?:%s).*?-->",
r"{\*.*?(?:%s).*?\*}",
r"{\#.*?(?:%s).*?#}",
r"{\#.*?(?:%s).*?\#}",
r"<\?php.*?(?:%s).*?\?>",
]

View file

@ -7,7 +7,7 @@ run::
for a single test, run::
pytest tests/test_django.py::test_complex_attributes --cov=src/djlint \
pytest tests/test_django.py::test_inline_comment --cov=src/djlint \
--cov-branch --cov-report xml:coverage.xml --cov-report term-missing
"""
@ -29,17 +29,6 @@ def test_dj_comments_tag(runner: CliRunner, tmp_file: TextIO) -> None:
assert output["exit_code"] == 0
def test_dj_comments_tag_with_html(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file, runner, b"{# <div></div> #}\n{% if this %}<div></div>{% endif %}"
)
assert (
output["text"] == """{# <div></div> #}\n{% if this %}<div></div>{% endif %}\n"""
)
# no change was required
assert output["exit_code"] == 0
def test_reformat_asset_tag(runner: CliRunner, tmp_file: TextIO) -> None:
# pylint: disable=C0301
output = reformat(
@ -86,6 +75,16 @@ def test_comment(runner: CliRunner, tmp_file: TextIO) -> None:
)
def test_inline_comment(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file, runner, b"{# <div></div> #}\n{% if this %}<div></div>{% endif %}"
)
assert (
output["text"] == """{# <div></div> #}\n{% if this %}<div></div>{% endif %}\n"""
)
assert output["exit_code"] == 0
def test_for_loop(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,