RiFi2k / format-html-in-php

Basically this vscode extension uses all your standard configurations for html formatting, and your standard configurations for format on save, etc. It more or less works exactly how vscode should already work as it pertains to HTML in PHP files.
The Unlicense
33 stars 6 forks source link

PHP inside <script> breaking #46

Closed Sir-Will closed 4 years ago

Sir-Will commented 4 years ago

If you have php in a html <script> element then it breaks the formatting of it:

elitan commented 4 years ago

Same for me. Everything else works perfectly, however this bug makes the extension unusable for me.

elitan commented 4 years ago

For now I added script to this setting:

"html.format.contentUnformatted": "pre,code,textarea,script"

bitwiseman commented 4 years ago

Duplicate of #31

@Sir-Will When reporting formatting issues, providing the actual text instead of an image helps people test fixes.

@RiFi2k @elitan @Sir-Will The reason for this is that, in jsbeautifier templating is turned on by default in HTML and turned off by default in JavaScript. This was done to limit the potential for breaking changes to existing users.

I suppose this default should be changed to on by default inside html <script> tags, but that is longer term discussion.

The fix is to enble php to the settings for jsbeautifier.

{
  "html": {
    "js": {
        "templating": "php"
    }
  }
}

Filed #47 to fix this in this project.

Note: even when you do this, the above would still fail because jsbeautifier currently expects <?php or <?= to start PHP tags. I've opened https://github.com/beautify-web/js-beautify/issues/1840 to track fixing this. Any help would be much appreciated.