CodeMirror でオーバーレイを作成するために RegEx マッチを使用している例を見つけることができないようです。一度に 1 つのものに一致するMustachesの例は十分に単純に見えますが、API では、RegEx 一致は一致の配列を返し、口ひげの構造のコンテキストでそれをどうするかわかりません。例。
強調表示する必要があるすべての要素を見つける正規表現があります。テストしたところ、機能しました。
トークン関数の外側で配列をロードしてから、それぞれを照合する必要がありますか? または、配列を操作する方法はありますか?
もう1つの問題は、正規表現の (biz|cms) オプションに応じて異なるスタイリングを適用したいということです.1つは「biz」用、もう1つは「cms」用です。他にもありますが、シンプルにまとめてみました。
これは私が持っている限りです。コメントは私の混乱を示しています。
CodeMirror.defineMode("tbs", function(config, parserConfig) {
var tbsOverlay = {
token: function(stream, state) {
tbsArray = match("^<(biz|cms).([a-zA-Z0-9.]*)(\s)?(\/)?>");
if (tbsArray != null) {
for (i = 0; i < tbsArray.length; i++) {
var result = tbsArray[i];
//Do I need to stream.match each element now to get hold of each bit of text?
//Or is there some way to identify and tag all the matches?
}
}
//Obviously this bit won't work either now - even with regex
while (stream.next() != null && !stream.match("<biz.", false)) {}
return null;
}
};
return CodeMirror.overlayMode(CodeMirror.getMode(config, parserConfig.backdrop || "text/html"), tbsOverlay);
});