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] Nested if statements in attribute values #443

Open
christopherpickering opened this issue Nov 3, 2022 · 1 comment
Open
Labels

Comments

@christopherpickering
Copy link
Contributor

from @Kakadus in #195
I am experiencing this bug as well and were able to construct a minimal example.
With

<a {% if cond %} class="somelongclass {% if cond2 %}otherlongclass{% endif %} anotherlongclass"{% endif %}></a>

the nested ifs break the code:

<a {% if cond %} class="somelongclass {% if cond2 %}otherlongclass{% endif %}
    anotherlongclass
{% endif %}></a>

Configuration with pyproject.toml:

[tool.djlint]
profile = "django"
format_attribute_template_tags = false

With format_attribute_template_tags = true, everything is reformatted as

<a {% if cond %}
       class="somelongclass
              {% if cond2 %}
                  otherlongclass
              {% endif %}
              anotherlongclass
          {% endif %}></a>
@christopherpickering
Copy link
Contributor Author

I can't come up with a regex to match nested statements properly... I thinking this will need to wait until we have a decent attribute parser working.

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

1 participant