From 6e8230eee841af0a7020c1ce07b0d408943d0941 Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Fri, 7 Jan 2022 08:49:00 -0600 Subject: [PATCH] fix for #166 and #167. added tests --- docs/src/docs/changelog.md | 7 ++++- docs/src/index.njk | 2 +- src/djlint/settings.py | 30 +++++++++++------- tests/test_django.py | 64 ++++++++++++++++++++++++++++---------- 4 files changed, 73 insertions(+), 30 deletions(-) diff --git a/docs/src/docs/changelog.md b/docs/src/docs/changelog.md index a622bc5..bad6168 100644 --- a/docs/src/docs/changelog.md +++ b/docs/src/docs/changelog.md @@ -8,9 +8,14 @@ keywords: template linter, template formatter, djLint, HTML, templates, formatte # Changelog +## Next Release +::: content +- Bug fixes [#167](https://github.com/Riverside-Healthcare/djLint/issues/167), [#166](https://github.com/Riverside-Healthcare/djLint/issues/166) +::: + ## 0.7.1 ::: content -- Bug fixes +- Bug fixes [#166](https://github.com/Riverside-Healthcare/djLint/issues/166) ::: ## 0.7.0 diff --git a/docs/src/index.njk b/docs/src/index.njk index 2246d8b..cabcb43 100644 --- a/docs/src/index.njk +++ b/docs/src/index.njk @@ -13,7 +13,7 @@ date: Last Modified

Once upon a time all the other programming languages had a formatter and linter. Css, javascript, python, the c suite, typescript, ruby, php, go, swift, and you know the others. The cool kids on the block.
HTML templates were left out there on their own, in the cold, unformatted and unlinted :( The dirty corner in your repository. Something had to change.
-Welcome djLint, the free cleaning service for html templates!

+Welcome djLint, the free cleaning service for html templates!
And the html templates lived happily ever after.

find your favorite template language!

diff --git a/src/djlint/settings.py b/src/djlint/settings.py index 52e7251..5940dd7 100644 --- a/src/djlint/settings.py +++ b/src/djlint/settings.py @@ -299,6 +299,7 @@ class Config: | [^\{]{\# |
             | 
-            | \#}
+            # | \#}
             | 
| <(script|style).*?(?=(\)) # html comment - | .*? + | .*?(?=) # django/jinja/nunjucks - | {\#\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*%\} + | {\#\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*%\}) # handlebars - | {{!--\s*djlint\:off\s*--}}.*?{{!--\s*djlint\:on\s*--}} + | {{!--\s*djlint\:off\s*--}}.*?(?={{!--\s*djlint\:on\s*--}}) # golang - | {{-?\s*/\*\s*djlint\:off\s*\*/\s*-?}}.*?{{-?\s*/\*\s*djlint\:on\s*\*/\s*-?}} + | {{-?\s*/\*\s*djlint\:off\s*\*/\s*-?}}.*?(?={{-?\s*/\*\s*djlint\:on\s*\*/\s*-?}}) | | <\?php.*?\?> - | {%[ ]*?blocktranslate\b((?!%}|trimmed).)*?%}.*?{%[ ]*?endblocktranslate[ ]*?%} - | {%[ ]*?blocktrans\b((?!%}|trimmed).)*?%}.*?{%[ ]*?endblocktrans[ ]*?%} - | {%[ ]*?comment\b[^(?:%})]*?%}.*?{%[ ]*?endcomment[ ]*?%} + | {%[ ]*?blocktranslate\b[^(?:%})]*?%}.*?{%[ ]*?endblocktranslate[ ]*?%} + | {%[ ]*?blocktrans\b[^(?:%})]*?%}.*?{%[ ]*?endblocktrans[ ]*?%} + | {%[ ]*?comment\b[^(?:%})]*?%}.*?(?={%[ ]*?endcomment[ ]*?%}) """ self.ignored_inline_blocks: str = r""" | {\*.*?\*} - | {\#.*?\#} + | {\#(?!.*djlint:[ ]*?(?:off|on)\b).*\#} | <\?php.*?\?> | {%[ ]*?comment\b[^(?:%})]*?%}.*?{%[ ]*?endcomment[ ]*?%} - | {%[ ]*?blocktranslate\b((?!%}|trimmed).)*?%}.*?{%[ ]*?endblocktranslate[ ]*?%} - | {%[ ]*?blocktrans\b((?!%}|trimmed).)*?%}.*?{%[ ]*?endblocktrans[ ]*?%} + | {%[ ]*?blocktranslate\b[^(?:%})]*?%}.*?{%[ ]*?endblocktranslate[ ]*?%} + | {%[ ]*?blocktrans\b[^(?:%})]*?%}.*?{%[ ]*?endblocktrans[ ]*?%} """ self.optional_single_line_html_tags: str = r""" diff --git a/tests/test_django.py b/tests/test_django.py index b2f4a10..b372f93 100644 --- a/tests/test_django.py +++ b/tests/test_django.py @@ -80,6 +80,52 @@ def test_comment(runner: CliRunner, tmp_file: TextIO) -> None: """ ) + output = reformat( + tmp_file, + runner, + b"""
+
+

+ Lorem ipsum dolor + sit + amet +

+ +
+ + {% comment %} + {% endcomment %} + +
""", + ) + + assert output.exit_code == 0 + + output = reformat( + tmp_file, + runner, + b"""
+
+ {# djlint:off #} +

+ Lorem ipsum dolor sit amet +

+ {# djlint:on #} + +
+
    + {% for i in items %} +
  • item {{i}}
  • + {% if i > 10 %}{% endif %} +
  • item {{i}}
  • + {% endfor %} +
+
+""", + ) + + assert output.exit_code == 0 + def test_inline_comment(runner: CliRunner, tmp_file: TextIO) -> None: output = reformat( @@ -243,14 +289,7 @@ def test_blocktranslate(runner: CliRunner, tmp_file: TextIO) -> None: runner, b"""{% blocktranslate trimmed %}The width is: {{ width }}{% endblocktranslate %}""", ) - assert output.exit_code == 1 - assert ( - output.text - == r"""{% blocktranslate trimmed %} - The width is: {{ width }} -{% endblocktranslate %} -""" - ) + assert output.exit_code == 0 output = reformat( tmp_file, @@ -269,14 +308,7 @@ def test_blocktranslate(runner: CliRunner, tmp_file: TextIO) -> None: runner, b"""{% blocktrans trimmed %}The width is: {{ width }}{% endblocktrans %}""", ) - assert output.exit_code == 1 - assert ( - output.text - == r"""{% blocktrans trimmed %} - The width is: {{ width }} -{% endblocktrans %} -""" - ) + assert output.exit_code == 0 output = reformat( tmp_file,