1
我試圖使用CodeMirror來突出顯示某些文本。 這個項目中的不尋常的事情是,我不得不強調的是,我沒有預先定義,而是我做了一個web服務調用,webserivice的響應給了我應該突出顯示的索引。這是一個NLP項目,Web服務爲我提供了特定於上下文的「知識」,這就是我想強調的。代碼鏡像獲取當前字符位置
簡單地說我得到JSON與表示字符的位置加以強調
繼開始和結束屬性的對象是我至今爲模式的定義,我編着的「差異」模式
CodeMirror.defineMode("diff", function() {
var i=-1;
return {
token: function(stream) {
i++;
// stream.skipToEnd();
var ch = stream.next();
if (bufferedResponse != null && bufferedResponse != "" && bufferedResponse.allergies != null){
$.each(bufferedResponse.allergies, function(key, value)
{
if (key != null && value != null && value != "")
{
if(i<value.start && i>value.end){
return "minus";
}
}
});
}
}
};
});
CodeMirror.defineMIME("text/x-diff", "diff");
我的問題是我怎樣才能得到流的當前相對於字符串(不行)的開始?我的意思是如果stream正在讀取第149個字符,我如何檢索這個數字? 「pos」,「start」和「columns」僅在當前行中給我定位!
這可能使用CodeMirror?