我的语法突出显示语法注入有什么问题? [英] What's wrong with my syntax highlighting grammar injection?

查看:113
本文介绍了我的语法突出显示语法注入有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注

I am following this example for a simple grammar injection in markdown.

{
    "fileTypes": [],
    "injectionSelector": "L:markup.fenced_code.block.markdown",
    "patterns": [
        {
            "include": "#superjs-code-block"
        }
    ],
    "repository": {
        "superjs-code-block": {
            "begin": "superjs",
            "end": "(^|\\G)(?=\\s*[`~]{3,}\\s*$)",
            "contentName": "meta.embedded.block.superjs",
            "patterns": [
                {
                    "include": "source.js"
                }
            ]
        }
    },
    "scopeName": "markdown.superjs.codeblock"
}

上面的代码有一个小问题-只要在受防护的代码块中出现一个字符串superjs,其余的将始终呈现为superjs,这将破坏受防护的代码块语法在其他嵌入式代码中的突出显示语言.

There is a small problem with the above code - As long as there is a string superjs appear in the fenced code block, the remaining would always be rendered as superjs, which would break fenced code block syntax highlighting for other embedded languages.

{
   "foo": "superjs"
}

我想通过遵循

但是它不起作用,我也不知道如何调试它.

However it doesn't work, and I don't know how to debug it either.

推荐答案

这是规则优先级问题.

我必须在"injectionSelector": "L:text.html.markdown"中使用L:前缀,而不是在此处记录:

I have to use the L: prefix in "injectionSelector": "L:text.html.markdown" instead as documented here:

注入选择器中的L:意味着将注入添加到现有语法规则的左侧.这基本上意味着我们的注入语法规则将在任何现有语法规则之前应用.

The L: in the injection selector means that the injection is added to the left of existing grammar rules. This basically means that our injected grammar's rules will be applied before any existing grammar rules.

这篇关于我的语法突出显示语法注入有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆