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] Formatting breaks if/else chains in html attributes #195
Comments
I have similar problem with Django templates: - <img
- {% if value.image.file.url|split:"."|last|lower == "gif" %}
- src="{{value.image.file.url}}"
- {% else %}
- {% image value.image fill-640x360 as block_image_640 %}
- {% image value.image fill-768x432 as block_image_768 %}
- {% image value.image fill-1024x576 as block_image_1024 %}
- {% image value.image fill-1600x900 as block_image_1600 %}
- data-src="{{ block_image_640.url }}"
- data-srcset="
- {{ block_image_640.url }} 640w,
- {{ block_image_768.url }} 768w,
- {{ block_image_1024.url }} 1024w,
- {{ block_image_1600.url }} 1600w
- "
- sizes="(min-width: 1200px) 458px, (min-width: 992px) 374px, (min-width: 768px) 720px, calc(100vw - 30px)"
- {% endif %}
- class="richtext-image imageblock overflow {{ value.image_position }} lazy"
- title="{{ value.image.title }}"
- alt="Block image"
- />
+ <img {% if value.image.file.url|split:"."|last|lower == "gif" %} src="{{ value.image.file.url }}" {% else %} {% image value.image fill-640x360 as block_image_640 %} {% image value.image fill-768x432 as block_image_768 %} {% image value.image fill-1024x576 as block_image_1024 %} {% image value.image fill-1600x900 as block_image_1600 %} data-src="{{ block_image_640.url }}" data-srcset=" {{ block_image_640.url }} 640w, {{ block_image_768.url }} 768w, {{ block_image_1024.url }} 1024w, {{ block_image_1600.url }} 1600w " sizes="(min-width: 1200px) 458px, (min-width: 992px) 374px, (min-width: 768px) 720px, calc(100vw - 30px)" {% endif %}
+ class="richtext-image imageblock overflow {{ value.image_position }} lazy"
+ title="{{ value.image.title }}"
+ alt="Block image"/> I am not sure why it does that, while on most other places it splits the long lines rather nicely. |
I am experiencing this bug as well and were able to construct a minimal example.
the nested ifs break the code:
Configuration with pyproject.toml:
With
|
Thanks, I'm putting a release that updates how attributes are parsed and will fix this issue. However, in this update, we will no longer be splitting href's into multiple lines per #427, but if you were have syntax like this in other attributes it will be fixed. @Kakadus thanks, the nested if statements is a separate problem, I'll open a new issue for that. |
@PetrDlouhy Thanks! I will open a separate issue for this. |
## [1.19.4](v1.19.3...v1.19.4) (2022-11-03) ### Bug Fixes * **attributes:** fixed poor django attribute parsing ([bd90f08](bd90f08)), closes [#427](#427) [#438](#438) * **attributes:** prevented attribute indentation for url type attributes ([907a1bf](907a1bf)), closes [#320](#320) [#86](#86) [#195](#195) * **image tag:** added image tag to template break tag list. srcset formatting ([0d170aa](0d170aa)), closes [#444](#444)
🎉 This issue has been resolved in version 1.19.4 🎉 The release is available on: Your semantic-release bot 📦🚀 |
System Info
Issue
The formatted is breaking attributes containing templates including more double quotes.
Sample HTML to reproduce is
The result I get is
Additionally, when formatting the following with or without
format_attribute_template_tags
enabled, the reformatting will collapse the template into one lineHow To Reproduce
format either provided template
Our settings
The text was updated successfully, but these errors were encountered: