简体   繁体   English

如何使用Prettier在新行上关闭HTML标签?

[英]How can I use Prettier to get closing HTML tags on a new line?

I'm trying to achieve the following output with Prettier when writing plain HTML: 在编写纯HTML时,我试图通过Prettier实现以下输出:

<div class="foo"></div>

<div
  class="foo"
  id="bar"
>
</div>

Note how the closing div tag on a div with multiple attributes is on a separate line (and all container on one line for a div with a single / no attributes). 请注意,具有多个属性的div上的结束div标签是如何在单独的一行上显示的(对于具有单个/无属性的div而言,所有容器都在一行上)。

I believe --jsx-bracket-same-line set to false achieves the desired outcome in JSX, but I'm trying to achieve this in regular HTML. 我相信--jsx-bracket-same-line设置为false可以在JSX中实现所需的结果,但是我正在尝试在常规HTML中实现这一点。

I am open to using other plugins or ESLint settings with Prettier. 我愿意在Prettier中使用其他插件或ESLint设置。

If you only have HTML files, then you can change the default parser to lwc instead of HTML . 如果只有HTML文件,则可以将默认解析器更改为lwc而不是HTML This change will turn all parsers to lwc 此更改会将所有解析器转换为lwc

{
    "parser": "lwc"
}

In the case where you have multiple different filetypes, better to only apply for *.html files then put the following into your .prettierrc. 如果您有多种不同的文件类型,最好只申请*.html文件,然后将以下内容放入.prettierrc.

{
  "overrides": [{ "files": "*.html", "options": { "parser": "lwc" } }]
}

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

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