简体   繁体   English

在 VS Code 中为 html 标签指定自定义格式

[英]Specify custom formatting for html tags in VS Code

I like html formatted in a specific way.我喜欢以特定方式格式化的html For example working with Telerik's grid (which can have many attributes) I like it like this:例如使用 Telerik 的网格(它可以有很多属性)我喜欢这样:

 <kendo-grid [data]="myGrid" [height]="510" [pageSize]="prjState.take" [skip]="prjState.skip" [pageable]="true" [sortable]="true" [sort]="prjState.sort" [filter]="prjState.filter" [filterable]="true" (edit)="editHandler('prj',$event)" (cancel)="cancelHandler($event)" (save)="saveHandler('prj',$event)" (dataStateChange)="onPrjStateChange($event)">

If I format it like this in VS Code and hit Shift + Alt + F , the formatter deletes all my custom formatting:如果我在 VS Code 中像这样格式化并点击Shift + Alt + F ,格式化程序会删除我所有的自定义格式:

 <kendo-grid [data]="myGrid" [pageSize]="prjState.take" [skip]="prjState.skip" [pageable]="true" (edit)="editHandler('prj',$event)" (cancel)="cancelHandler($event)" (save)="saveHandler('prj',$event)" [sortable]="true" [height]="510" [sort]="prjState.sort" [filter]="prjState.filter" [filterable]="true" (dataStateChange)="onPrjStateChange($event)">

2 questions: 2个问题:

  1. Is it possible to stop VS Code from reformatting my kendo-grid tag?是否可以阻止 VS Code 重新格式化我的 kendo-grid 标签?
  2. Is it possible to modify VS Code so it formats kendo-grid tags the way i indicated?是否可以修改 VS Code 以按照我指示的方式格式化剑道网格标签?

What I tried (with no results):我尝试过的(没有结果):

  • adding kendo-grid tag to html.format.contentUnformatted setting in settings.json filekendo -grid标签添加到 settings.json 文件中的html.format.contentUnformatted设置

  • adding kendo-grid tag to html.format.unformatted setting in settings.json filekendo -grid标签添加到 settings.json 文件中的html.format.unformatted设置

Thank you.谢谢你。

In the User settings Preferences > User Settings setting在用户设置Preferences > User Settings设置中

"html.format.wrapAttributes": "force-aligned"

Will make all HTML tags behave like your example.将使所有 HTML 标签的行为都像您的示例。 You can also set你也可以设置

"editor.formatOnSave": true,
"editor.formatOnPaste": true

To make it work automatically on save and paste.使其在保存和粘贴时自动工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM