admin管理员组

文章数量:1316511

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

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

Share Improve this question asked Nov 10, 2011 at 3:47 uu 9211 gold badge11 silver badges29 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

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 */
});

本文标签: javascriptApply CodeMirror to preexisting divStack Overflow