markup_fmt icon indicating copy to clipboard operation
markup_fmt copied to clipboard

Invalid offset when formatting multiline attr value

Open UnknownPlatypus opened this issue 1 year ago • 2 comments
trafficstars

Hi!

This mostly fix the issue I currently have with multiline style attribute getting weirdly indented.

<div class="ds-flex ds-flex-col ds-items-center ds-absolute ds-z-10 {% if title|length > 30 %}ds-w-4/5{% else %}ds-w-1/2{% endif %}"
     style="top:60%;
            transform:translate(0,-50%)">
</div>

is changed to

<div
  class="ds-flex ds-flex-col ds-items-center ds-absolute ds-z-10 {% if title|length > 30 %}ds-w-4/5{% else %}ds-w-1/2{% endif %}"
  style="top:60%;
            transform:translate(0,-50%)"
>
</div>

Every time some kind of wrapping occurred, and the attr value is on multiple lines, the indent is not preserved.

I also tried to avoid disruption for another common style of multiline style attribute (Prettier for ex)

<div
    class="ds-flex ds-flex-col ds-items-center ds-absolute ds-z-10 {% if title|length > 30 %}ds-w-4/5{% else %}ds-w-1/2{% endif %}"
    style="
        top: 60%;
        transform: translate(0, -50%);
    "
></div>

I'm marking this as draft because it's not actually addressing the problem, it's a workaround. I was not able to find the offset between the initial indent level and the formatted indent level :/ .

I think the issue could probably be solved by proper value formatting using malva maybe ? This would be awesome:

  • we could detect invalid css directive at parsing time and raise errors
  • formatting would be consistant, using a single line when possible, or multiline (with configurable style maybe?)

UnknownPlatypus avatar Aug 06 '24 16:08 UnknownPlatypus

Maybe using with Malva should be better. I'll do it.

g-plane avatar Aug 07 '24 03:08 g-plane

Maybe using with Malva should be better. I'll do it.

Thanks! Would be awesome :raised_hands:

UnknownPlatypus avatar Aug 07 '24 09:08 UnknownPlatypus