Format code command for PHP/HTML in Visual Studio Code

前端 未结 7 1813
滥情空心
滥情空心 2020-12-29 04:32

Is it possible to get Visual Studio Code to format mixed HTML and PHP code on Windows Visual Studio Code version 0.7.1?

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-29 04:42

    The problem with most of the solutions is that they all are registered as formatting providers and within Visual Studio Code you can only run one formatter on a save for a specific file type.

    So one may get you all the HTML, CSS, JavaScript code, but leave out the PHP code. Or if you use a regular PHP formatter there isn't one that exists that does the HTML correctly.

    I went ahead and made an extension that runs before the save hook and isn't registered as a PHP formatter, so it will do all the HTML with js-beautify and then you can use something like PHPCS + PHPCBF to format the HTML. So it's basically, as far as I'm concerned, the best solution currently available.

    Format HTML in PHP on the Visual Studio Code marketplace.

提交回复
热议问题