[英]VS Code PHP Format Single Attribute Per Line
I'm trying to set VS Code to format the HTML part of the PHP file as signleAttributePerLine
.我正在尝试将 VS Code 设置为将 PHP 文件的 HTML 部分格式化为
signleAttributePerLine
。 My current project settings:我当前的项目设置:
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[PHP]": {
"editor.defaultFormatter": "bmewburn.vscode-intelephense-client"
},
"prettier.singleAttributePerLine": true,
"intelephense.singleAttributePerLine": true,
"editor.formatOnSave": true,
"editor.tabSize": 2,
"html.format.wrapAttributes": "auto",
"prettier.singleQuote": true,
"prettier.semi": false,
"prettier.printWidth": 80,
"cSpell.words": ["gematriya", "roadmap", "WPAPI"]
}
Example:例子:
I want this:我要这个:
<div class="d-flex gap-3 field-control flex-wrap">
<?php
$counter = 0;
foreach ($select_values as ['label' => $label, 'value' => $value]) :
if ($counter >= 10) break;
?>
<div class="small-button" data-post-type="<?= $post_type ?>" data-type="<?= esc_attr($type) ?>" role="button" data-value="<?= esc_attr($value) ?>">
<?= $label ?>
</div>
<?php
$counter++;
endforeach;
?>
</div>
To turn into this (on save):变成这个(保存时):
<div class="d-flex gap-3 field-control flex-wrap">
<?php
$counter = 0;
foreach ($select_values as ['label' => $label, 'value' => $value]) :
if ($counter >= 10) break;
?>
<div
class="small-button"
data-post-type="<?= $post_type ?>"
data-type="<?= esc_attr($type) ?>"
role="button"
data-value="<?= esc_attr($value) ?>"
>
<?= $label ?>
</div>
<?php
$counter++;
endforeach;
?>
</div>
Note - I am happy with the current PHP part formatting, just want to update the HTML part.注意 - 我对当前的 PHP 部分格式很满意,只是想更新 HTML 部分。
HTML > Format: Wrap Attributes
to force-expand-multiline
:HTML > Format: Wrap Attributes
更改为force-expand-multiline
:"html.format.wrapAttributes": "force-expand-multiline", // should be in your settings
settings.json
):settings.json
):"[php]": {
"editor.formatOnSave": true
}
Now when you save a .php
document the html inside it should be formatted according to the html formatting options you set in vscode.现在,当您保存
.php
文档时,其中的 html 应该根据您在 vscode 中设置的 html 格式化选项进行格式化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.