简体   繁体   中英

Apply CodeMirror to pre-existing div

I have a div called content_editable. I am making a code editing application. So there are certain css dimensions it needs to follow. But I want to be able to add the code mirror syntax highlighting script to it. But when I do it the way the documentation says to do it, nothing happens. At all. My div to be edited is called #editable_content . How do I add the CodeMirror capabilities to it?

EDIT

link to the site documentation CodeMirror Documentation Also, a link to a JSFiddle or a JSBin would be greatly appreciated for example reasons

Something like this (untested) should do the trick

var ce = document.getElementById("content_editable");
// Probably needs more kludges to be portable... you get the idea
var text = ce.textContent || ce.innerText;
var editor = CodeMirror(function(node){ce.parentNode.replaceChild(node, ce);}, {
  value: text
  /* , your options */
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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