mblode/vscode-twig-language-2

Format Document affecting Twig replace() within HTML tag

AnthonyANI opened this issue · 1 comments

I've identified potentially unwanted behavior when using Format Document that affects the values within a Twig replace() that resides within an HTML tag.

The following code is designed to remove "tabs" (four spaces) from the included twig file:
image

It becomes the following after Format Document:
image

This of course causes the replace to remove every single space rather than four spaces together as originally intended, and breaks the HTML in the included Twig file.

For my current project, I realized I didn't need the replace at all so was able to avoid the issue and continue using Format Document. I also just learned of a Twig filter that can do away with this type of replace altogether: https://twig.symfony.com/doc/2.x/filters/spaceless.html Though I figured it couldn't hurt submitting this since it appears to be unintentional behavior and a fix for it may prevent future issues when replace() is used within HTML tags.

P.S. Funnily enough, the GitHub code formatter also changed four spaces to one space, so I had to use screenshots to illustrate the problem.

Stale issue message