简体   繁体   English

将超链接放置在CodeMirror文本区域中

[英]Place hyperlinks in CodeMirror textarea

I am new to codemirror. 我是Codemirror的新手。

I have a string in CodeMirror textarea. 我在CodeMirror textarea中有一个字符串。 I want my text to be hyperlinked and it goes to a jsp page and fetch answers and append it back in the codemirror textarea. 我希望我的文本超链接,然后转到jsp页面并获取答案并将其附加回codemirror textarea中。

I have tried using <a href="abc.com">hyperlink </a> . 我尝试使用<a href="abc.com">hyperlink </a> .

It prints everything along with the tags. 它会打印所有内容以及标签。

How to place hyperlinks in codemirror text area. 如何在Codemirror文本区域中放置超链接。 A code snippet is really helpful. 代码段确实很有帮助。

Thanks in advance 提前致谢

Sorry, for a very very delay update. 抱歉,更新非常延迟。 Had got a work around at that time. 当时已经解决了。 Thought of sharing it. 想共享它。

Since I was looking at some code functions in this edtitor, on double click a function name I am able to append that code definition at the end of the editor. 由于我正在查看此编辑器中的一些代码函数,因此双击函数名称,就可以在编辑器的末尾附加该代码定义。

Below is the example on how I have achieved: 以下是有关我如何实现的示例:

// setup and fetched the editor earlier.
var editor = CodeMirror.fromTextArea(document.getElementById(key)); // Got my editor


// Later on placed a double click logic:
editor.on("dblclick", function(){    
    if(editor.somethingSelected()){
        var from = editor.getCursor("from"), to = editor.getCursor("to");
        if( from.line!=to.line){
            alert("No word");
        }
        else{
            var word = editor.getRange(from, to);
            $.ajax({
                url : "hyperlink.jsp",
                data:{
                    keyword1 : word,
                },
                success: function(response){
                    if(response.length>6){
                        editor.setValue(editor.getValue()+"\n\n\n#"+word+":\n"+response);
                        var line = maxLineNumber;
                        formatMyEditor(); // Formatting my new code
                        editor.indentLine(maxLineNumber-5, -3);
                        editor.setCursor(line+2);
                    }
                    else{
                        alert(word+" -- Not in DB");
                    }
                }
           }
     });
}

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

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