Skip to content

Commit

Permalink
fix(ignored code): fixed formatting of ignore code inside django comm…
Browse files Browse the repository at this point in the history
…ent blocks

closes #569
  • Loading branch information
christopherpickering committed Apr 4, 2023
1 parent fb8bf5e commit 120460d
Show file tree
Hide file tree
Showing 8 changed files with 397 additions and 378 deletions.
738 changes: 369 additions & 369 deletions docs/package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/package.json
Expand Up @@ -19,7 +19,7 @@
"@fontsource/crimson-pro": "^4.5.11",
"@fontsource/rasa": "^4.5.14",
"@quasibit/eleventy-plugin-schema": "^1.11.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-node-resolve": "^15.0.2",
"@sindresorhus/slugify": "^2.2.0",
"animate-sass": "^0.8.2",
"animate.css": "github:animate-css/animate.css",
Expand All @@ -37,15 +37,15 @@
"@fortawesome/fontawesome-free": "^6.4.0",
"@fullhuman/postcss-purgecss": "5.0.0",
"@toycode/markdown-it-class": "1.2.4",
"algoliasearch": "^4.16.0",
"algoliasearch": "^4.17.0",
"autoprefixer": "^10.4.14",
"bulma": "0.9.4",
"bulma-pricingtable": "0.2.0",
"cssnano": "^6.0.0",
"cz-conventional-changelog": "3.3.0",
"eleventy-plugin-edit-on-github": "1.1.0",
"eleventy-plugin-metagen": "1.7.11",
"esbuild": "^0.17.14",
"esbuild": "^0.17.15",
"eslint": "^8.36.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-plugin-import": "2.27.5",
Expand Down
5 changes: 5 additions & 0 deletions docs/src/_data/i18n/index.js
Expand Up @@ -151,4 +151,9 @@ module.exports = {
fr: 'djLint a été créé à l\'origine pour être utilisé dans les projets <a href="https://atlas.bi" target="_blank">Atlas</a> par l\'équipe <a href="https://github.com/riverside-Healthcare/" target="_blank">Riverside Healthcare Analytics</a>.',
ru: 'Изначально djLint был создан для использования в проектах <a href="https://atlas.bi" target="_blank">Atlas</a> командой <a href="https://github.com/riverside-Healthcare/" target="_blank">Riverside Healthcare Analytics</a>.',
},
site_analytics: {
'en-US': 'Site Analytics',
fr: 'Site Analytics',
ru: 'Аналитика сайта',
},
};
3 changes: 3 additions & 0 deletions docs/src/_includes/foot.njk
Expand Up @@ -17,6 +17,9 @@
<p class="has-text-grey-dark has-text-right mt-2">
<small>{{ "footer_credits" | i18n | safe }}</small>
</p>
<p class="has-text-right pt-3">
<a href="https://analytics.djlint.com/share/fdd3vGz2/djlint.com" target="_blank"><small>{{ "site_analytics" | i18n }}</small></a>
</p>
</div>
</div>
</div>
Expand Down
7 changes: 6 additions & 1 deletion src/djlint/formatter/compress.py
Expand Up @@ -5,6 +5,7 @@

import regex as re

from ..helpers import child_of_ignored_block
from ..settings import Config


Expand All @@ -18,8 +19,12 @@ def _flatten_attributes(match: re.Match) -> str:
Attribute name can be in group one or group 2.
for now, skipping if they are anywhere
even ignored blocks attributes can be formatted.
tags starting ignored blocks can have their attributes formatted,
for example <textarea class="..." id="..."> can be formatted.
"""
if child_of_ignored_block(config, html, match):
return match.group()

# pylint: disable=C0209
return "{} {}{}".format(
match.group(1),
Expand Down
5 changes: 3 additions & 2 deletions src/djlint/reformat.py
Expand Up @@ -26,8 +26,9 @@ def reformat_file(config: Config, this_file: Path) -> dict:

condensed = clean_whitespace(expanded, config)

beautified_code = indent_html(condensed, config)
beautified_code = condense_html(beautified_code, config)
indented_code = indent_html(condensed, config)

beautified_code = condense_html(indented_code, config)

if config.format_css:
beautified_code = format_css(beautified_code, config)
Expand Down
6 changes: 3 additions & 3 deletions src/djlint/settings.py
Expand Up @@ -405,7 +405,7 @@ def __init__(
| </pre
| </textarea
| {\#\s*djlint\:\s*on\s*\#}
| {%[ ]+?endcomment[ ]+?%}
| (?<!djlint:off\s*?){%[ ]+?endcomment[ ]+?%}
| {{!--\s*djlint\:on\s*--}}
| {{-?\s*/\*\s*djlint\:on\s*\*/\s*-?}}
| {%[ ]*?endblocktrans(?:late)?[^(?:%})]*?%}
Expand Down Expand Up @@ -646,7 +646,7 @@ def __init__(
| <\?php.*?\?>
| {%[ ]*?blocktranslate\b[^(?:%})]*?%}.*?{%[ ]*?endblocktranslate[ ]*?%}
| {%[ ]*?blocktrans\b[^(?:%})]*?%}.*?{%[ ]*?endblocktrans[ ]*?%}
| {%[ ]*?comment\b[^(?:%})]*?%}.*?(?={%[ ]*?endcomment[ ]*?%})
| {%[ ]*?comment\b[^(?:%})]*?%}(?:(?!djlint:(?:off|on)).)*?(?={%[ ]*?endcomment[ ]*?%})
| ^---[\s\S]+?---
"""

Expand All @@ -669,7 +669,7 @@ def __init__(
| {\*.*?\*}
| {\#(?!.*djlint:[ ]*?(?:off|on)\b).*\#}
| <\?php.*?\?>
| {%[ ]*?comment\b[^(?:%})]*?%}.*?{%[ ]*?endcomment[ ]*?%}
| {%[ ]*?comment\b[^(?:%})]*?%}(?:(?!djlint:(?:off|on)).)*?{%[ ]*?endcomment[ ]*?%}
| {%[ ]*?blocktranslate\b[^(?:%})]*?%}.*?{%[ ]*?endblocktranslate[ ]*?%}
| {%[ ]*?blocktrans\b[^(?:%})]*?%}.*?{%[ ]*?endblocktrans[ ]*?%}
"""
Expand Down
5 changes: 5 additions & 0 deletions tests/test_config/test_ignores/html_two.html
Expand Up @@ -5,3 +5,8 @@
</div>
</div>
{# djlint:on #}

{% comment %} djlint:a {% endcomment %}
<a class="a"
href="b">變更密碼</a>
{% comment %} djlint:on {% endcomment %}

0 comments on commit 120460d

Please sign in to comment.