g-plane / markup_fmt

Configurable HTML, Vue, Svelte, Astro, Angular, Jinja, Twig, Nunjucks and Vento formatter with dprint integration.
https://dprint.dev/plugins/markup_fmt/
MIT License
91 stars 4 forks source link

feat: improve formatting Jinja blocks in attributes #44

Closed g-plane closed 1 month ago

g-plane commented 1 month ago

Please note that interpolations in attribute name and attribute value won't be formatted. This is expected since they're parsed as plain texts.

cc @UnknownPlatypus

UnknownPlatypus commented 1 month ago

Please note that interpolations in attribute name and attribute value won't be formatted. This is expected since they're parsed as plain texts.

I think it's better like that for now. Parsing and formatting interpolation in attribute value will add complexity and is not always safe if whitespace are important (in href values for example)

UnknownPlatypus commented 4 weeks ago

@g-plane This seems to cause an issue for the following snippet that is not parsing anymore:

<picture
    {% for key, val in attributes.items %} 
        {{ key }}="{{ val }}"
    {% endfor %}
></picture>

I get this Failed to parse "src/t.html" with error Syntax(SyntaxError { kind: ExpectJinjaTag, pos: 61, line: 3, column: 11 }). This is failing to parse {{ key }} because it expect a JinjaTag.