使用 CodeMirror 突出显示文本区域中的文本?
Using CodeMirror to highlight text in textarea?
我有一个文本区域,单击按钮时将填充某个文件的内容。我正在尝试实现 CodeMirror,它将自动突出显示加载到文本区域中的代码的语法。
您必须确保加载了正确模式的 js 文件(查看 fiddle 中的外部资源),然后就像 setValue
调用一样简单。
http://jsfiddle.net/blaird/mssrahz1/1/
var myCodeMirror = CodeMirror.fromTextArea(document.getElementById("editor"), {
lineNumbers: true,
mode: "htmlmixed"
});
var loadButton = document.getElementById("load");
loadButton.onclick = function () {
// here you'd load your file and then call setValue with the result
myCodeMirror.setValue("<div>Hi There</div>\n<ul>\n\t<li>one</li>\n</ul>");
};
我有一个文本区域,单击按钮时将填充某个文件的内容。我正在尝试实现 CodeMirror,它将自动突出显示加载到文本区域中的代码的语法。
您必须确保加载了正确模式的 js 文件(查看 fiddle 中的外部资源),然后就像 setValue
调用一样简单。
http://jsfiddle.net/blaird/mssrahz1/1/
var myCodeMirror = CodeMirror.fromTextArea(document.getElementById("editor"), {
lineNumbers: true,
mode: "htmlmixed"
});
var loadButton = document.getElementById("load");
loadButton.onclick = function () {
// here you'd load your file and then call setValue with the result
myCodeMirror.setValue("<div>Hi There</div>\n<ul>\n\t<li>one</li>\n</ul>");
};