代码格式化破坏了 VS 代码中的 Jekyll YAML 前端指令

Code formatting break Jekyll YAML front matter directives in VS code

自动代码格式化(操作 editor.action.format)中断 Jekyll (aka Github Pages) pages YAML front matter

index.html 自动格式化前:

--- 
layout: default 
title: Awesome page
bodyClass: homepage 
permalink: /
---
(rest of the content)

index.html 自动格式化后:

--- layout: default title: Awesome page bodyClass: homepage permalink: / ---
(rest of the content is formatted ok, regular html syntax)

如何调整 VS 代码格式化规则?

我遇到了同样的问题。确保将此设置设置为 false: "editor.formatOnSave": false

要解决此问题,您有两种选择:

  1. 关闭 settings.json 文件中 HTML 文件的格式化:

    "html.format.enable": false
    

    这将关闭 HTML 文件的格式设置。不理想,但可以完成工作。有个GitHubIssue for this,不过好像关门了

  2. 考虑安装 Liquid Languages Support 扩展,然后将其添加到您的 settings.json:

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

这已经解决了我的问题。

Jekyll Snippets 扩展使 VS Code 能够理解大多数文件类型的前面内容。

但是,该扩展不知道 SCSS。 big-hammer 解决方法是在 settings.json:

中关闭 SCSS 验证
"scss.validate": false