From ec60646b361add5a3eec72bbf89cd75de36e4e8c Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Wed, 24 Nov 2021 09:18:58 +0100 Subject: [PATCH] fixed #144, added test --- docs/djlint/changelog.rst | 4 ++++ src/djlint/settings.py | 10 ++++++---- tests/test_django.py | 26 ++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/docs/djlint/changelog.rst b/docs/djlint/changelog.rst index 3d18d85..a39a55c 100644 --- a/docs/djlint/changelog.rst +++ b/docs/djlint/changelog.rst @@ -1,6 +1,10 @@ Changelog ========= +next release +------------ +- Added support for django `blocktrans` tag + 0.6.2 ----- - Bug fixes diff --git a/src/djlint/settings.py b/src/djlint/settings.py index dfff3ff..0779ff0 100644 --- a/src/djlint/settings.py +++ b/src/djlint/settings.py @@ -636,8 +636,9 @@ class Config: | {{-?\s*/\*\s*djlint\:off\s*\*/\s*-?}}.*?{{-?\s*/\*\s*djlint\:on\s*\*/\s*-?}} | | <\?php.*?\?> - | {%[ ]*?blocktranslate[ ]+?((?!%}|trimmed).)*?%}.*?{%[ ]*?endblocktranslate[ ]*?%} - | {%[ ]*?comment[ ]+?[^(?:%})]*?%}.*?{%[ ]*?endcomment[ ]*?%} + | {%[ ]*?blocktranslate\b((?!%}|trimmed).)*?%}.*?{%[ ]*?endblocktranslate[ ]*?%} + | {%[ ]*?blocktrans\b((?!%}|trimmed).)*?%}.*?{%[ ]*?endblocktrans[ ]*?%} + | {%[ ]*?comment\b[^(?:%})]*?%}.*?{%[ ]*?endcomment[ ]*?%} """ self.ignored_inline_blocks: str = r""" @@ -645,8 +646,9 @@ class Config: | {\*.*?\*} | {\#.*?\#} | <\?php.*?\?> - | {%[ ]*?comment[ ]+?[^(?:%})]*?%}.*?{%[ ]*?endcomment[ ]*?%} - | {%[ ]*?blocktranslate[ ]+?((?!%}|trimmed).)*?%}.*?{%[ ]*?endblocktranslate[ ]*?%} + | {%[ ]*?comment\b[^(?:%})]*?%}.*?{%[ ]*?endcomment[ ]*?%} + | {%[ ]*?blocktranslate\b((?!%}|trimmed).)*?%}.*?{%[ ]*?endblocktranslate[ ]*?%} + | {%[ ]*?blocktrans\b((?!%}|trimmed).)*?%}.*?{%[ ]*?endblocktrans[ ]*?%} """ self.optional_single_line_html_tags: str = r""" diff --git a/tests/test_django.py b/tests/test_django.py index ff51047..e909a83 100644 --- a/tests/test_django.py +++ b/tests/test_django.py @@ -254,6 +254,32 @@ def test_blocktranslate(runner: CliRunner, tmp_file: TextIO) -> None: """ ) + output = reformat( + tmp_file, + runner, + b"""{% blocktrans %}The width is: {{ width }}{% endblocktrans %}""", + ) + assert output["exit_code"] == 0 + assert ( + output["text"] + == r"""{% blocktrans %}The width is: {{ width }}{% endblocktrans %} +""" + ) + + output = reformat( + tmp_file, + 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 %} +""" + ) + def test_trans(runner: CliRunner, tmp_file: TextIO) -> None: output = reformat(