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] Multi-line {% comment %} has unstable ident #173

Closed
3 tasks done
vchga opened this issue Jan 22, 2022 · 2 comments
Closed
3 tasks done

[BUG] [Formatter] Multi-line {% comment %} has unstable ident #173

vchga opened this issue Jan 22, 2022 · 2 comments
Assignees
Labels

Comments

@vchga
Copy link

vchga commented Jan 22, 2022

System Info

  • OS: ubuntu 20.04
  • Python Version: 3.9.5
  • djLint Version: 0.7.2
  • template language: django

Issue

When using block comment for more than 2 lines, ident is added to the block content with every reformat. I'd like {% comment %} to not change ident of inner content at all (disable formatting, like djlint:off), because comments in general may contain invalid code (e.g. variant of opening html tag and such).

How To Reproduce

This is simple example, where I provide formatted code according to my liking, but reformat is making unwanted indent and is not being idempotent (it changes the file with every re-run - see bellow).

<html>
    <head>
        <script src="file1.js"></script>
        {% comment %}
        <script src="file2.js"></script>
        <script src="file3.js"></script>
        <script src="file4.js"></script>
        {% endcomment %}
        <script src="file5.js"></script>
    </head>
    <body>
    </body>
</html>

After running reformat for the first time:

  • script inside comment is indented (which I prefer not to)
  • endcomment is wrongly underindented
  • rest of the file after endcomment is off
<html>
    <head>
        <script src="file1.js"></script>
        {% comment %}
                <script src="file2.js"></script>
                <script src="file3.js"></script>
                <script src="file4.js"></script>
    {% endcomment %}
    <script src="file5.js"></script>
</head>
<body>
</body>
</html>

Running reformat the second time:

  • more unwanted indent is added to inner content of comment
<html>
    <head>
        <script src="file1.js"></script>
        {% comment %}
                        <script src="file2.js"></script>
                        <script src="file3.js"></script>
                        <script src="file4.js"></script>
    {% endcomment %}
    <script src="file5.js"></script>
</head>
<body>
</body>
</html>

This has similar symptoms as djlint:on/off issue in #166 (comment).

Just for fun I've put djlint:on/off around comment/endcomment and it has no effect :( I'll log it as separate issue.

@christopherpickering
Copy link
Contributor

Thanks! The problem is the nested ignore blocks :/ I'll see what I can do!

@christopherpickering
Copy link
Contributor

🎉 This issue has been resolved in version 1.0.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants