Adobe括号中的代码镜像简单模式

Code Mirror Simple Mode in Adobe Brackets

本文关键字:镜像 简单 模式 代码 Adobe      更新时间:2023-09-26

我正在尝试创建一个自定义的代码镜像模式,以便与Adobe Brackets代码编辑器一起使用。

目前,我可以突出显示{{code}},但我想使用代码镜像简单模式(更容易理解)。

我的Brackets扩展代码是(main.js):

define(function (require, exports, module) {
    'use strict';
    var LanguageManager = brackets.getModule("language/LanguageManager");

    CodeMirror.defineMode("laravelblade", function (config, parserConfig) {
        var mustacheOverlay = {
            token: function (stream, state) {
                var ch;
                //Highlight Comments {{-- --}}
                if (stream.match("{{--")) {
                    while ((ch = stream.next()) != null)
                        if (ch == "}" && stream.next() == "}") break;
                    stream.eat("}");
                    return "comment";
                }
                //--
                //Highlight {{ $var }})
                if (stream.match("{{")) {
                    while ((ch = stream.next()) != null)
                        if (ch == "}" && stream.next() == "}") break;
                    stream.eat("}");
                    return "def";
                }
                //Highlight {% $var %} (Laravel 5)
                else if (stream.match('{%')) {
                    while ((ch = stream.next()) != null)
                        if (ch == "%" && stream.next() == "}") break;
                    stream.eat("}");
                    return "def";
                }
                //Highlight {% $var %} (Laravel 5)
                else if (stream.match('{%')) {
                    while ((ch = stream.next()) != null)
                        if (ch == "%" && stream.next() == "}") break;
                    stream.eat("}");
                    return "def";
                }
                //Return Null if no condition was met.
                else if (stream.next() != null) {
                    return null;
                }
            }
        };
        return CodeMirror.overlayMode(CodeMirror.getMode(config, parserConfig.backdrop || "php"), mustacheOverlay);
    });

    LanguageManager.defineLanguage("laravelblade", {
        "name": "Laravel Blade",
        "mode": "laravelblade",
        "fileExtensions": ["blade.php"],
        "blockComment": ["{{--", "--}}"]
    });
});

你能为我提供一个代码镜像简单模式的简单例子吗?(我读过codemirror文档,我试着遵循这些例子,但我就是无法让它们使用Brackets语法高亮显示…)

谢谢。

编辑:实际的代码是有效的,但我想使用代码镜像简单模式来实现同样的效果。

我还复制了这个代码,并根据自己的需要进行了更改。但我无法让另一个代码镜像模式从头开始使用括号。。。所以我可能错过了什么。。。

我也遇到了类似的问题。

对于一个工作示例,请检查dockerfile模式(在OSX中,它位于Applications/Brackets/Contents/www/thirdparty/CodeMirror2/mode/dokerfile中)。