更新时间:2023-01-18 18:12:13
在Mustache示例中有特殊处理,因为它需要处理2个字符的分隔符(例如,在'{{'
和'}}'
中有两个字符。我以前从未使用过CodeMirror,所以这只是一个猜测,不过请尝试这样的事情:
There is special handling in the Mustache example because it needs to handle 2-character delimiters (e.g. there are two characters in '{{'
and '}}'
). I've never used CodeMirror before, so this is just a guess, but try something like this:
CodeMirror.defineMode("mymode", function(config, parserConfig) {
var mymodeOverlay = {
token: function(stream, state) {
if (stream.match("{")) {
while ((ch = stream.next()) != null)
if (ch == "}") break;
return "mymode";
}
while (stream.next() != null && !stream.match("{", false)) {}
return null;
}
};
return CodeMirror.overlayParser(CodeMirror.getMode(config, parserConfig.backdrop || "text/html"), mymodeOverlay);
});
有效(尽管它也突出显示小写字母的单词)
it works (though it highlights words with lowercase letters too)
此应该有效:
token: function(stream, state) {
if (stream.match("{")) {
while ((ch = stream.next()) != null && ch === ch.toUpperCase())
if (ch == "}") break;
return "mymode";
}
while (stream.next() != null && !stream.match("{", false)) {}
return null;
}