Markdown模式代码镜像正在创建

Markdown mode codemirror creating

本文关键字:创建 镜像 模式 代码 Markdown      更新时间:2023-09-26

有人能帮我创建代码镜像的新模式吗?

我需要将{>1<}![title](site)的这部分{>1<}放在不可见的范围内(与特定类一起放在跨度内)

我该怎么做?

我试过这样的东西:

CodeMirror.defineSimpleMode("imageID", {
    start: [
       {regex: /(?:'{'>([^<]*)'<'})/gmi, token: "imageID"}
    ]
});

但它不起作用。。。有什么想法吗?

解决方案:

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