首页 > 解决方案 > Visual Studio Code - 自定义特定 html 标签的颜色

问题描述

在高低搜索之后,我似乎无法找到如何在 Visual Studio Code 中自定义特定 html 标签的颜色。更改它们的颜色很容易,具有以下 textmate 范围:

entity.name.tag.html

这会改变所有标签。但是,如果您只想更改“表单”标签的颜色怎么办?即<form></form> ,例如,如何使“Form”标签与“Div”标签的颜色不同?

检查 VSC 中的编辑器令牌/范围,我可以看到以下范围:

meta.tag.structure.form.start.html

但这会改变其他东西,而不是 Form 标签本身。

标签: visual-studio-code

解决方案


不知道为什么不适合你?这对我有用:

  "editor.tokenColorCustomizations": {
    "textMateRules": [
      {
        "scope": "meta.tag.structure.form.start.html entity.name.tag, meta.tag.structure.form.end.html entity.name.tag",
        "settings": {
          "foreground": "#00ff00",
          "fontStyle": "bold"
        }
      },
    ]
  },

请注意,我必须添加entity.name.tag到每个范围选择器才能使其工作。演示:

html表单颜色变化

你还有其他事情想要完成吗?


推荐阅读