简体   繁体   English

降价模式代码镜像创建

[英]Markdown mode codemirror creating

anyone can help me to create new mode to codemirror? 任何人都可以帮助我为Codemirror创建新模式吗?

I need to put this part {>1<} of {>1<}![title](site) invisible (into span with specific class) 我需要把{>1<}的这部分{>1<} {>1<}![title](site)不可见(进入特定类的范围)

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();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM