mirror of
https://github.com/Hopiu/djLint.git
synced 2026-05-19 18:31:54 +00:00
parent
a1451fc78e
commit
6e8230eee8
4 changed files with 73 additions and 30 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ date: Last Modified
|
|||
|
||||
<p class="story my-5 has-text-left">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. <i>The cool kids on the block.</i><br>
|
||||
HTML templates were left out there on their own, in the cold, unformatted and unlinted :( The dirty corner in your repository. <i>Something had to change.</i><br>
|
||||
Welcome djLint, the free cleaning service for html templates!</p>
|
||||
Welcome djLint, the free cleaning service for html templates!<br>And the html templates lived happily ever after.</p>
|
||||
|
||||
<h2 class="title is-2 has-text-centered mb-5">find your favorite template language!</h2>
|
||||
<div class="columns is-multiline">
|
||||
|
|
|
|||
|
|
@ -299,6 +299,7 @@ class Config:
|
|||
| [^\{]{\#
|
||||
| <pre
|
||||
| <textarea
|
||||
| {%[ ]*?blocktrans(?:late)?[^(?:%})]*?%}
|
||||
| {\#\s*djlint\:\s*off\s*\#}
|
||||
| {%[ ]+?comment[ ]+?[^(?:%})]*?%}
|
||||
| {{!--\s*djlint\:off\s*--}}
|
||||
|
|
@ -311,13 +312,14 @@ class Config:
|
|||
| \?>
|
||||
| </script
|
||||
| -->
|
||||
| \#}
|
||||
# | \#}
|
||||
| </pre
|
||||
| </textarea
|
||||
| {\#\s*djlint\:\s*on\s*\#}
|
||||
| {%[ ]+?endcomment[ ]+?%}
|
||||
| {{!--\s*djlint\:on\s*--}}
|
||||
| {{-?\s*/\*\s*djlint\:on\s*\*/\s*-?}}
|
||||
| {%[ ]*?endblocktrans(?:late)?[^(?:%})]*?%}
|
||||
"""
|
||||
|
||||
# ignored block closing tags that
|
||||
|
|
@ -325,6 +327,10 @@ class Config:
|
|||
self.safe_closing_tag: str = r"""
|
||||
</script
|
||||
| </style
|
||||
| {\#\s*djlint\:\s*on\s*\#}
|
||||
| {%[ ]+?endcomment[ ]+?%}
|
||||
| {{!--\s*djlint\:on\s*--}}
|
||||
| {{-?\s*/\*\s*djlint\:on\s*\*/\s*-?}}
|
||||
"""
|
||||
|
||||
# all html tags possible
|
||||
|
|
@ -668,29 +674,29 @@ class Config:
|
|||
<(pre|textarea).*?</(\1)>
|
||||
| <(script|style).*?(?=(\</(?:\3)>))
|
||||
# html comment
|
||||
| <!--\s*djlint\:off\s*-->.*?<!--\s*djlint\:on\s*-->
|
||||
| <!--\s*djlint\:off\s*-->.*?(?=<!--\s*djlint\:on\s*-->)
|
||||
# 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"""
|
||||
|
|
|
|||
|
|
@ -80,6 +80,52 @@ def test_comment(runner: CliRunner, tmp_file: TextIO) -> None:
|
|||
"""
|
||||
)
|
||||
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<div class="hi">
|
||||
<div class="poor">
|
||||
<p class="format">
|
||||
Lorem ipsum dolor
|
||||
<span class="bold">sit</span>
|
||||
amet
|
||||
</p>
|
||||
<img src="./pic.jpg">
|
||||
</div>
|
||||
<script src="file1.js"></script>
|
||||
{% comment %} <script src="file2.js"></script>
|
||||
<script src="file3.js"></script> {% endcomment %}
|
||||
<script src="file4.js"></script>
|
||||
</div>""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 0
|
||||
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<div class="hi">
|
||||
<div class="poor">
|
||||
{# djlint:off #}
|
||||
<p class="format">
|
||||
Lorem ipsum dolor <span class="bold">sit</span> amet
|
||||
</p>
|
||||
{# djlint:on #}
|
||||
<img src="./pic.jpg">
|
||||
</div>
|
||||
<ul>
|
||||
{% for i in items %}
|
||||
<li>item {{i}}</li>
|
||||
{% if i > 10 %}{% endif %}
|
||||
<li>item {{i}}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
""",
|
||||
)
|
||||
|
||||
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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue