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

Support unquoted attr value recovery for jinja interpolated variables #23

Closed UnknownPlatypus closed 3 months ago

UnknownPlatypus commented 3 months ago

Hello !

This is an attempt to solve an issue I encountered when using your formatter on a template with unquoted interpolated attribute value. The recovery was slightly wrong, my code was reformated this way resulting in a template rendering issue:

-<h4 id={{ component.id }}></h4>
+<h4 id="{{" component.id }}></h4>

The whole interpolated value should be quoted because I believe this is what actually happens after a value get's interpolated and finally rendered by a browser.

# `template.jinja`
<h4 id={{ component.id }}></h4>

# `rendered_template.html` with component.id=3
<h4 id=3></h4>

# Resulting html after browser parsing
<h4 id="3"></h4>

PS: I'm quite new to rust and your codebase in general so I'll happily update this pr following any suggestion you would make.

PS2: This is part of a bigger effort of making your wonderful formatter compliant with Django template too, If you're open to such improvement, I'll happily open an issue about that. I already started to identify deviations with jinja templates but the syntax is quite similar.

g-plane commented 3 months ago

I can't push to your repository so I edited and merged locally and closed this PR.

UnknownPlatypus commented 3 months ago

I can't push to your repository so I edited and merged locally and closed this PR.

The Allow edits by maintainers checkbox seems to be a little bugged. It doesn't do anything, event if I check it now :/

Anyway, thanks for the followup! Looking good