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] attribute formatting for nested {% image tags %} #444

Closed
christopherpickering opened this issue Nov 3, 2022 · 2 comments
Labels

Comments

@christopherpickering
Copy link
Contributor

From Petr Dlouhý in #195
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.

source html

<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"
/>
@christopherpickering christopherpickering added 🦠 bug Something isn't working 🧽 formatter labels Nov 3, 2022
@christopherpickering christopherpickering changed the title [BUG] [Formatter] attribute formatting for nested {% tags %} [BUG] [Formatter] attribute formatting for nested {% image tags %} Nov 3, 2022
@christopherpickering
Copy link
Contributor Author

Changes to make the formatting work:

  • added image as a valid template tag
  • added indentation to srcset, data-srcset, and sizes

(I removed the if statement for now and will handle that in #443 )

The output will be

<img {% 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)"
     class="richtext-image imageblock overflow {{ value.image_position }} lazy"
     title="{{ value.image.title }}"
     alt="Block image"/>

christopherpickering pushed a commit that referenced this issue Nov 3, 2022
## [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)
@christopherpickering
Copy link
Contributor Author

🎉 This issue has been resolved in version 1.19.4 🎉

The release is available on:

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

1 participant