【问题标题】:Code formatting break Jekyll YAML front matter directives in VS code代码格式化打破了 VS 代码中的 Jekyll YAML 前端指令
【发布时间】:2019-12-20 05:38:29
【问题描述】:

自动代码格式化(操作editor.action.format)会破坏Jekyll (aka Github 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 代码格式规则?

【问题讨论】:

    标签: jekyll visual-studio-code


    【解决方案1】:

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

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

      "html.format.enable": false
      

      这会关闭 HTML 文件的格式设置。不理想,但可以完成工作。有一个 GitHub Issue for this,不过好像已经关闭了。

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

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

    这已经为我解决了这个问题。

    【讨论】:

      【解决方案2】:

      Jekyll Snippets 扩展使 VS Code 能够理解大多数文件类型的前端问题。

      但是,扩展程序不知道 SCSS。一个重要的解决方法是在settings.json 中关闭 SCSS 验证:

      "scss.validate": false
      

      【讨论】:

        【解决方案3】:

        我也有同样的问题。确保您将此设置设置为 false: "editor.formatOnSave": false

        【讨论】:

        • 感谢@yviedev,虽然我知道。这并不能解决问题,因为我想为我的其他文件自动格式化代码。
        猜你喜欢
        • 2020-09-30
        • 2017-01-01
        • 2018-09-28
        • 1970-01-01
        • 2021-08-23
        • 2016-10-11
        • 2013-05-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多