Skip to content

Commit

Permalink
fix(formatter): fixed formatter formatting ignored code
Browse files Browse the repository at this point in the history
closes #655
  • Loading branch information
christopherpickering committed Jun 26, 2023
1 parent a197200 commit 5c75d87
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/djlint/settings.py
Expand Up @@ -760,7 +760,8 @@ def __init__(
# html comment
| <!--\s*djlint\:off\s*-->.*?(?=<!--\s*djlint\:on\s*-->)
# django/jinja/nunjucks
| {\#\s*djlint\:\s*off\s*\#}.*?(?={\#\s*djlint\:\s*on\s*\#})
| {\#\s*djlint\:\s*off\s*\#}(?:(?!{\#\s*djlint\:\s*on\s*\#}).)*
# | {\#\s*djlint\:\s*off\s*\#}.*?(?={\#\s*djlint\:\s*on\s*\#})
| {%\s*comment\s*%\}\s*djlint\:off\s*\{%\s*endcomment\s*%\}.*?(?={%\s*comment\s*%\}\s*djlint\:on\s*\{%\s*endcomment\s*%\})
# inline jinja comments
| {\#(?!\s*djlint\:\s*(?:off|on)).*?\#}
Expand Down
24 changes: 24 additions & 0 deletions tests/test_djlint/test_ignore.py
@@ -0,0 +1,24 @@
"""Test disable.
poetry run pytest tests/test_djlint/test_ignore.py
"""
import pytest

from src.djlint.reformat import formatter
from tests.conftest import printer

test_data = [
pytest.param(
("{# djlint:off #}\n" "<img \n" "/>"),
("{# djlint:off #}\n" "<img \n" "/>\n"),
id="don't compress",
),
]


@pytest.mark.parametrize(("source", "expected"), test_data)
def test_base(source, expected, basic_config):
output = formatter(basic_config, source)

printer(expected, source, output)
assert expected == output

0 comments on commit 5c75d87

Please sign in to comment.