代码之家  ›  专栏  ›  技术社区  ›  taalas

扩展VS代码语法突出显示

  •  0
  • taalas  · 技术社区  · 7 年前

    是否有方法使用用户设置(或不涉及编写扩展的类似方法)扩展特定项的Visual Studio代码语法高亮显示?

    我正在使用颜色主题,但希望更改HTML标记的特定命名空间的语法颜色,例如。

    <div></div> 使用主题的标准颜色

    <ext:div></ext:div>

    2 回复  |  直到 7 年前
        1
  •  2
  •   Scott McPeak    5 年前

    ,VSCode本身(没有扩展)中没有突出显示任意正则表达式的内容。(当然,有搜索功能,但它的突出显示是暂时的。)

    除了编写扩展或使用现有的扩展外,最有能力突出显示自定义的方法是 textMateRules 的机制 editor.tokenCustomizations 在里面 settings.json .

    现在,内置的TextMate语法只是将“ext:div”分类为无法识别的,因此使用这种方法的最好方法是更改所有无法识别的标记的突出显示。看起来是这样的:

        // https://code.visualstudio.com/docs/getstarted/themes
        "editor.tokenColorCustomizations": {
            "textMateRules": [
                {
                    "scope": [
                        "meta.tag.other entity.name.tag",
                    ],
                    "settings": {
                        "foreground": "#080",
                        "fontStyle": "bold",
                    },
                },
            ],
        },
    

    截图:

    Screenshot of using textMateRules to match ext:div tag

    另请参见 this answer 这要经过添加的过程 text材料 更详细一点。

        2
  •  1
  •   Mark    7 年前

    如果您没有找到更好、更标准的方法,那么扩展 TODO Highlight

      "todohighlight.keywordsPattern": "\\s*<\\s*\\/{0,1}ext:.*\\s*>",
    

    然后,您可以按任何方式设置颜色:

    "todohighlight.defaultStyle": {
        "color": "red",
        // "letterSpacing": "1px",
        // "backgroundColor": "rgba(170,102,0,1)",
        "backgroundColor": "transparent"
        // "borderRadius": "4px",
        "isWholeLine": false
    },