PHP/HTML 的 VSCode 格式代码命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32236030/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VSCode Format code command for PHP/HTML
提问by steakoverflow
Is to possible to get VSCode to format mixed html/php code on Windows VSCode v0.7.1?
是否可以让 VSCode 在 Windows VSCode v0.7.1 上格式化混合的 html/php 代码?
采纳答案by Zenexer
As of v0.7.10, not yet. It only works for some languages. Once there's more integration for PHP, the shortcut will be Alt+ Shift+ F(??Fon Mac).
从 v0.7.10 开始,还没有。它仅适用于某些语言。一旦有更多的集成PHP,快捷将是Alt+ Shift+ F(??F在Mac)。
Update 2016-05-30: Visual Studio Code has pretty awesome PHP supportnow. What it lacks is covered by extensions. A quick search reveals at least three (1, 2, 3) that claim to support PHP formatting. They mostly seem to use the standard shortcut of Alt+ Shift+ Fon Windows/Linux, with varying shortcuts on Mac. If you're on Mac, give ??Fa try.
2016 年 5 月 30 日更新:Visual Studio Code现在有非常棒的 PHP 支持。它缺少的东西被扩展覆盖了。快速搜索会发现至少三个(1、2、3)声称支持 PHP 格式。他们大多似乎使用的标准快捷键Alt+ Shift+ FWindows / Linux上,兼容Mac不同的快捷方式。如果您使用的是 Mac,请??F尝试一下。
回答by rifi2k
So the problem with most of the solutions is that they all are registered as formatting providers and within VSCode you can only one run formatter on a save for a specific file type. So one may get you all the HTML, CSS, JS but leave out the PHP. Or if you use a regular PHP formatter there isn't one that exists that does the HTML correctly.
因此,大多数解决方案的问题在于它们都注册为格式化提供程序,并且在 VSCode 中,您只能在保存特定文件类型时运行一个格式化程序。所以你可能会得到所有的 HTML、CSS、JS,但忽略了 PHP。或者,如果您使用常规 PHP 格式化程序,则不存在可以正确处理 HTML 的格式化程序。
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.
我继续制作了一个在保存挂钩之前运行的扩展,并且没有注册为 PHP 格式化程序,因此它将使用 js-beautify 处理所有 HTML,然后您可以使用 PHPCS + PHPCBF 之类的东西来格式化 HTML。因此,就我而言,这基本上是目前可用的最佳解决方案。
Format HTML in PHPon the VScode marketplace.
在 VScode 市场上用 PHP 格式化 HTML。
回答by Mete YILMAZ
I'm coding in Laravel and using "Format HTML In PHP" for formatting the html codes in php code lines. It's working perfect. Here is the link. Format HTML In PHP
我在 Laravel 中编码并使用“在 PHP 中格式化 HTML”来格式化 php 代码行中的 html 代码。它工作完美。链接在这里。 在 PHP 中格式化 HTML
回答by Bagaskara
Best format setting for mixed PHP, HTML, JS code. Just use 'PHP CS FIXER', then use this simple config on yout setting.json
混合 PHP、HTML、JS 代码的最佳格式设置。只需使用'PHP CS FIXER',然后在你身上使用这个简单的配置setting.json
"php-cs-fixer.executablePath": "${extensionPath}\php-cs-fixer.phar",
"[php]": {
"editor.defaultFormatter": "junstyle.php-cs-fixer",
"editor.formatOnSave": true
},
"php-cs-fixer.rules": "@PSR2",
"php-cs-fixer.formatHtml": true,
回答by RahmanRezaee
add this extension on your vscode https://marketplace.visualstudio.com/items?itemName=rifi2k.format-html-in-phpor search in extension "format html in php" after reload use shift+alt+f
将此扩展添加到您的 vscode https://marketplace.visualstudio.com/items?itemName=rifi2k.format-html-in-php或在重新加载后使用 shift+alt+f 在扩展中搜索“format html in php”
enjoy it
好好享受
回答by vscody
I've tried just about every formatting extension for VS Code and I don't think there is a single one that can handle correctly/consistently formatting of mixed PHP/HTML pages
我已经尝试了 VS Code 的几乎所有格式扩展,但我认为没有一个可以正确/一致地处理混合 PHP/HTML 页面的格式