我正在制作一个 Adobe Brackets Extension 以添加对 Laravel Blade 语法高亮的支持。
Blade 是一个在 HTML(更具体地说是 .php 文件)之上运行的模板系统,在没有激活我的扩展程序的情况下,我可以对 css 规则名称执行 CTRL+E快速编辑以快速在 stlye.css 文件中找到该规则。但是当我激活扩展时,CTRL+E 不再工作,但 HTML 语法工作正常。
我在 text/html 上使用覆盖模式。
这是 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": ["{{--", "--}}"]
});
});
真正的问题是: 如何在我的自定义模式和 *blade.php 文件中添加对快速编辑的支持?