anyone can help me to create new mode to codemirror?
I need to put this part {>1<}
of {>1<}
invisible (into span with specific class)
How I can do that?
I tryed something like that:
CodeMirror.defineSimpleMode("imageID", {
start: [
{regex: /(?:\{\>([^<]*)\<\})/gmi, token: "imageID"}
]
});
but it doesn't work... any ideas why?
Solution:
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();
}