如何将 TextMate 语法注入 VS Code 中的 Markdown 标题?

问题描述

我想在 VS Code 的 Markdown 文件中选择 [ ] 进行语法高亮显示

我可以使用以下 [ ] 定位 regex(?<=\s)\]|\[(?=\s)。 但是,当 [ ]标题的一部分时,它不会匹配。

作为一个最小的例子,在 package.json 中,我有以下内容

"contributes": {
    "grammars": [
        {
            "scopeName": "markdown.todo","path": "./Syntaxes/todo.markdown.json","injectTo": ["text.html.markdown"]
        }
    ]
}

然后,在 todo.markdown.json 我有

{
    "scopeName": "markdown.todo","injectionSelector": "L:text.html.markdown","patterns": [
        { "include": "#item-todo" }
    ],"repository": {
        "item-todo": {
            "name": "item.todo","match": "(?<=\\s)\\]|\\[(?=\\s)"
        }
    }
}

最后,在 VS Code settings.json 中,我使用以下方法应用颜色:

"editor.tokenColorCustomizations": {
    "textMateRules": [
        {
            "scope": "item.todo","settings": {
                "foreground": "#FF0000"
            }
        }
    ]
}

我可以在下面看到 [ ] 被选中,但当它位于标题内时不会。

enter image description here

当我检查令牌和范围时,我看到几个 textmate scopes。 我不确定这是否相关,但似乎 VS Code 正在根据 markup.heading 范围突出显示降价标题。但是,markup.heading 不存在于 textmate scopes 数组中。

enter image description here

我尝试更改为 "injectionSelector": "L:heading.1.markdown" 和/或 "injectTo": ["heading.1.markdown"],但无论我指定什么选择器,我似乎都无法在标题中匹配 [ ]

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)