使用安装的 Nunjucks 扩展格式化 HTML

Formatting HTML with Nunjucks extension installed

我有一些 Angular 组件 HTML some.component.html 正在尝试格式化。当我点击 ctrl-shiftp, and selectFormat Document` 时,我收到消息:

There is no document formatter for 'nunjucks'-files installed.

所以 VSCode 认为 .html 文件是 nunjucks 文件。

有没有办法让它认为这是一个 html 文件?

您可以通过单击 VS Code 状态栏中的 "Nunjucks" 一词切换回 HTML。这个 "Language Indicator" 靠近 VS Code 的 window 的右下角。单击它将显示一个 "Select Language Mode" 下拉列表,您可以在其中 select "HTML".

之后,通常适用于 HTML 文件的功能(如格式化文档)将再次适用;但是,像对Nunjuck文件应用特殊语法高亮之类的东西不会,但是你可以根据需要来回切换。

这是 Changing the language for the selected file 的 VS Code 文档。

在settings.json中显式添加一个"file.associations"似乎解决了来回切换的需要。

"files.associations": {
    "*.html": "html",
}