From 6e8230eee841af0a7020c1ce07b0d408943d0941 Mon Sep 17 00:00:00 2001
From: Christopher Pickering 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!
And the html templates lived happily ever after.
|
- | \#}
+ # | \#}
|
| <(script|style).*?(?=(\(?:\3)>))
# 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 +
+
+ + Lorem ipsum dolor sit amet +
+ {# djlint:on #} +
+