如何在 VScode 中格式化 HTML 代码?

Mar*_*son 5 html formatting visual-studio-code

我想找到一种在 VScode 中格式化 HTML 的方法,例如,如果我有一个像这样的长 div:

<div class="signal-item-icon checkbox-signal signal-icon" [class.selected]="signal.isSelectedCheckSign" (click)="$event.stopPropagation(); onSelectOneShadowSignal(signal);">
Run Code Online (Sandbox Code Playgroud)

当我执行 ctrl+shift+i 时,我希望它像这样显示:

<div class="signal-item-icon checkbox-signal signal-icon" 
     [class.selected]="signal.isSelectedCheckSign" 
     (click)="$event.stopPropagation(); 
     onSelectOneShadowSignal(signal);">
Run Code Online (Sandbox Code Playgroud)

如果可能,你会吗?是否存在针对这种实现的扩展 VScode?

谢谢 !

Yer*_*kon 5

您还可以将其与html.format.wrapLineLength.

"html.format.wrapLineLength": 80,
"html.format.wrapAttributes": "auto",
Run Code Online (Sandbox Code Playgroud)

在这种情况下,当行长度超过 时,属性开始换行80。当您有很多属性并且它会填充右侧的空白时,它非常有用。


Jon*_*eis 4

将 VSCode 首选项设置html.format.wrapAttributesforce将完成示例中的格式化。