djLint
djLint copied to clipboard
[BUG] [Formatter] Nested if statements in attribute values
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>
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.