解決方案:
function findNext(lastPos){
var text = /^\!\[([^\]]*)\]\(([^\)]*)\)+/;
for (cursor = editor.getSearchCursor(text); cursor.findNext();)
editor.replaceRange('{>'+(i++)+'<}',cursor.from(),cursor.from())
cursor = editor.getSearchCursor(text, lastPos || editor.getCursor());
if (!cursor.findNext()){
cursor = editor.getSearchCursor(text);
if (!cursor.findNext()) {return;}
}
lastPos = cursor.to();
}
//------------------------------------
function findAloneIdx(lastPos){
var text = /(\{\>([^<]*)\<\}\!?\[?)+/;
for (cursor = editor.getSearchCursor(text); cursor.findNext();)
if(editor.getRange(cursor.from(), cursor.to()).slice(-2) !== '![')
editor.replaceRange('',cursor.from(),cursor.to())
else
editor.markText(cursor.from(), {line: cursor.to().line, ch: cursor.to().ch-2}, {className: "styled-background"});
cursor = editor.getSearchCursor(text, lastPos || editor.getCursor());
if (!cursor.findNext()){
cursor = editor.getSearchCursor(text);
if (!cursor.findNext()) {return;}
}
lastPos = cursor.to();
}
CodeMirror模式不能讓文字不可見。你必須爲此使用'markText'方法。 – Marijn