trivago / prettier-plugin-twig-melody

Code formatting plugin for Prettier which can handle Twig/Melody templates
Apache License 2.0
155 stars 35 forks source link

Prevent newlines to be added inside a <textarea> element #107

Closed electrotype closed 1 year ago

electrotype commented 1 year ago

I see this plugin doesn't seem to be maintained anymore, but in case someone knows how to fix my issue:

Using parser: "melody" on my HTML files will add newlines inside <textarea> elements. For example:

<textarea>{{ myValue }}</textarea>

will become:

<textarea>
  {{ myValue }}
</textarea>

Of course this is not desired, as the newlines are then visible to the user in the textareas.

Any options/idea on how to fix this?

karlschwaier commented 1 year ago

Yes, that's easy to fix with Twig's whitespace control, see https://twig.symfony.com/doc/3.x/templates.html#whitespace-control.

<textarea>
  {{- myValue -}}
</textarea>
electrotype commented 1 year ago

I didn't know that trick, it works! Thanks!