简体   繁体   English

Prettier 没有在 Visual Studio Code 中格式化 HTML

[英]Prettier not formatting HTML in Visual Studio Code

All I want to do is for Prettier to work on Visual Studio Code whenever I'm working on my HTML files, but nothing seems to work.我只想让 Prettier 在我处理 HTML 文件时处理 Visual Studio Code,但似乎没有任何效果。

I made my default formatter Prettier.我让我的默认格式化程序更漂亮。

I enabled Format on Save, Paste, and Type.我在保存、粘贴和键入时启用了格式。

Whenever I use HTML files, I see that Prettier has the two double checkmarks on the bottom right of the screen.每当我使用 HTML 文件时,我都会看到 Prettier 在屏幕右下角有两个双复选标记。

However, my HTML content still remains unformatted.但是,我的 HTML 内容仍未格式化。

Currently, my settings.json looks like this:目前,我的 settings.json 看起来像这样:

{
  "workbench.colorTheme": "Tomorrow Night Blue",
  "liveServer.settings.donotShowInfoMsg": true,
  "workbench.iconTheme": "material-icon-theme",
  "editor.formatOnType": true,
  "git.branchSortOrder": "alphabetically",
  "editor.formatOnSave": true,
  "editor.formatOnPaste": true,
  "editor.defaultFormatter": "esbenp.prettier-vscode"
}

I tried doing this:我试过这样做:

{
  "workbench.colorTheme": "Tomorrow Night Blue",
  "liveServer.settings.donotShowInfoMsg": true,
  "workbench.iconTheme": "material-icon-theme",
  "editor.formatOnType": true,
  "git.branchSortOrder": "alphabetically",
  "editor.formatOnSave": true,
  "editor.formatOnPaste": true,
  "editor.defaultFormatter": "esbenp.prettier-vscode"

  "[HTML]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
  },

}

but whenever I do that, the "[HTML]" is underlined in red and the file itself is shown to have a problem.但每当我这样做时,“[HTML]”都会带有红色下划线,并且文件本身会显示有问题。

I'm a complete beginner, and I know almost nothing about coding or Visual Studio code.我是一个完全的初学者,我对编码或 Visual Studio 代码几乎一无所知。 If anyone can help me, I'll be very thankful.如果有人可以帮助我,我将非常感激。

it seems working fine on my end with every settings you mentioned, try double checking your code first if you miss any closing tags because most of the time missing closing tag is the source of the problem.在我看来,您提到的每个设置都可以正常工作,如果您错过任何结束标记,请先尝试仔细检查您的代码,因为大多数时候缺少结束标记是问题的根源。

On the other hand you could try using the default formatter rather than the prettier extension.另一方面,您可以尝试使用默认格式化程序而不是更漂亮的扩展。

Right click --> Format Document with... --> HTML Language Features右键单击 --> 使用...格式化文档 --> HTML 语言功能

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

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