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
100 stars 9 forks source link

Avoid wrapping for multiple text-like nodes #28

Closed UnknownPlatypus closed 4 months ago

UnknownPlatypus commented 4 months ago

Hi!

markup_fmt seems to force wrapping when there are more than 2 non-text element in an html element. This introduces some unusual wrapping when there are 2+ jinja interpolation inside an element (which is actually quite common).

-<div>Hello {{ user.first_name }} {{ user.last_name }}!</div>
+<div>
+  Hello {{ user.first_name }}
+  {{ user.last_name }}!
+</div>

This MR changes the behavior slightly to check for text-like nodes (reusing existing logic to identify them).

You should probably review this commit per commit because I also did some small refactoring along the way when I was trying to figure out the leading/trailing ws handling. I made sure every commit was always passing the test suite. Only the last commit introduces the behavior change described above.

I'll be happy to make any changes if my implementation doesn't satisfy your needs. Cheers