From 5c75d87a1bcce9189d5b8a561d4ea6a92c1ee1bb Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Mon, 26 Jun 2023 12:43:49 -0500 Subject: [PATCH] fix(formatter): fixed formatter formatting ignored code closes #655 --- src/djlint/settings.py | 3 ++- tests/test_djlint/test_ignore.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/test_djlint/test_ignore.py diff --git a/src/djlint/settings.py b/src/djlint/settings.py index 010a24d1..470c67a2 100644 --- a/src/djlint/settings.py +++ b/src/djlint/settings.py @@ -760,7 +760,8 @@ def __init__( # html comment | .*?(?=) # 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)).*?\#} diff --git a/tests/test_djlint/test_ignore.py b/tests/test_djlint/test_ignore.py new file mode 100644 index 00000000..cd62b67a --- /dev/null +++ b/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" ""), + ("{# djlint:off #}\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