Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [Formatter] In a file starting with {# djlint:off #}, the formatter still does some modifications #703

Open
3 tasks done
malo-malo opened this issue Jun 28, 2023 · 4 comments
Labels
🦠 bug Something isn't working 🧽 formatter

Comments

@malo-malo
Copy link

System Info

- OS: ubuntu 20.04
- Python Version 3.8.10
- djLint Version 1.31.1
- template language: django templates

Issue

Followup on this issue #655
Most cases have been fixed, but some parts of supposedly ignored templates are still being formatted.

How To Reproduce

Here is a list of the problems I have encountered and that I reproduced in the online version, with the default configuration:

Initial Formatted
{# djlint:off #}
<div>
    <div class=""
         id=""></div>
    <style>
    </style>
    <script>
    </script>
    {% comment %}
    {% endcomment %}
</div>

<a href="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" target="_blank" rel="noopener"></a>
{% blocktranslate trimmed %}{% endblocktranslate %}
<a href="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" target="_blank" rel="noopener"></a>
{# djlint:off #}
<div>
    <div class="" id=""></div>
    <style>
</style>
    <script>
</script>
    {% comment %}
{% endcomment %}
</div>

<a href="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" target="_blank" rel="noopener"></a>
{% blocktranslate trimmed %}{% endblocktranslate %}
<a href="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
   target="_blank"
   rel="noopener"></a>
  1. Some multi-line tags are being collapsed
  2. Any line with a </style> or </script> tag gets un-indented
  3. Any line with a {% endcomment %} get un-indented
  4. The presence of a blocktranslate trimmed seems to have an influence on the formatting of following lines, in the entire file (the blocktranslate and <a> lines are a minimal reproduction)
  5. An extra line is added at the end of the file (or some are removed if there are several)
@malo-malo malo-malo added 🦠 bug Something isn't working 🧽 formatter labels Jun 28, 2023
@malo-malo
Copy link
Author

The </script> part seems to be similar to this issue #697

@christopherpickering
Copy link
Contributor

Note to self for future fix..

the error is coming in formatter/condense.py. The strip_space function allows updates if we are a safe closing tag. This should only happen if we are not inside another ignored...

@we684123
Copy link

Add old example from #569 😢

and after enable {% comment %} djlint:on {% endcomment %} , something html tag will be abnormally indented

System Info

https://djlint.com/demo/
Python 3.10.2;
djLint 1.31.1

<nav class="navbar navbar-expand-lg navbar-light bg-light main-nav p-3">
    <div class="collapse navbar-collapse" id="navBar">
        <div class="navbar-nav ml-auto">
            <ul class="navbar-nav mb-2 mb-lg-0">
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle mr-4"
                       href="#"
                       id="navbarDropdownMenuLink"
                       data-bs-toggle="dropdown"
                       aria-haspopup="true"
                       aria-expanded="false">
                        {{ request.user.name }}
                    </a>
                    <div class="dropdown-menu"
                         style="min-width: 105px;
                                width: 105px"
                         aria-labelledby="navbarDropdownMenuLink">
                        {% comment %} djlint:off {% endcomment %}
                        <a class="dropdown-item"
                           href="http://user/login">變更密碼</a>
                        {% comment %} djlint:on {% endcomment %}
                    </div>
                </li>
            </ul>
        </div>
    </div>
</nav>

2023-07-19 09_05_38-HTML Template Linter and Formatter _ djLint — Mozilla Firefox

@christopherpickering
Copy link
Contributor

I reopened the other as this is probably more relevant there 👍🏼 thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🦠 bug Something isn't working 🧽 formatter
Projects
None yet
Development

No branches or pull requests

3 participants