CodeMirror.runMode = function(string, modespec, callback, options) {
  function esc(str) {
    return str.replace(/[<&]/g, function(ch) { return ch == "<" ? "&lt;" : "&amp;"; });
  }

  var mode = CodeMirror.getMode(CodeMirror.defaults, modespec);
  var isNode = callback.nodeType == 1;
  var tabSize = (options && options.tabSize) || CodeMirror.defaults.tabSize;
  if (isNode) {
    var node = callback, accum = [], col = 0;
    callback = function(text, style) {
      if (text == "\n") {
        accum.push("<br>");
        col = 0;
        return;
      }
      var escaped = "";
      // HTML-escape and replace tabs
      for (var pos = 0;;) {
        var idx = text.indexOf("\t", pos);
        if (idx == -1) {
          escaped += esc(text.slice(pos));
          col += text.length - pos;
          break;
        } else {
          col += idx - pos;
          escaped += esc(text.slice(pos, idx));
          var size = tabSize - col % tabSize;
          col += size;
          for (var i = 0; i < size; ++i) escaped += " ";
          pos = idx + 1;
        }
      }

      if (style) 
        accum.push("<span class=\"cm-" + esc(style) + "\">" + escaped + "</span>");
      else
        accum.push(escaped);
    };
  }
  var lines = CodeMirror.splitLines(string), state = CodeMirror.startState(mode);
  for (var i = 0, e = lines.length; i < e; ++i) {
    if (i) callback("\n");
    var stream = new CodeMirror.StringStream(lines[i]);
    while (!stream.eol()) {
      var style = mode.token(stream, state);
      callback(stream.current(), style, i, stream.start);
      stream.start = stream.pos;
    }
  }
  if (isNode)
    node.innerHTML = accum.join("");
};

@@ -66,123 +66,8 @@
 ) %7B%0A
-  function esc(str) %7B%0A    return str.replace(/%5B%3C&%5D/g, function(ch) %7B return ch == %22%3C%22 ? %22&lt;%22 : %22&amp;%22; %7D);%0A  %7D%0A%0A
   va
@@ -130,23 +130,15 @@
 c);%0A
+%0A
   
-var isNode = 
+if (
 call
@@ -155,18 +155,22 @@
 ype == 1
-;%0A
+) %7B%0A  
   var ta
@@ -242,24 +242,8 @@
 ze;%0A
-  if (isNode) %7B%0A
     
@@ -267,27 +267,40 @@
 ck, 
-accum = %5B%5D, col = 0
+col = 0;%0A    node.innerHTML = %22%22
 ;%0A  
@@ -374,25 +374,53 @@
     
-accum.push
+node.appendChild(document.createElement
 (%22
-%3C
 br
-%3E
 %22
+)
 );%0A 
@@ -469,23 +469,23 @@
     var 
-escaped
+content
  = %22%22;%0A 
@@ -495,24 +495,8 @@
   //
- HTML-escape and
  rep
@@ -607,39 +607,35 @@
 %7B%0A          
-escaped += esc(
+content += 
 text.slice(p
@@ -637,17 +637,16 @@
 ice(pos)
-)
 ;%0A      
@@ -751,23 +751,19 @@
     
-escaped += esc(
+content += 
 text
@@ -778,17 +778,16 @@
 os, idx)
-)
 ;%0A      
@@ -890,23 +890,23 @@
 e; ++i) 
-escaped
+content
  += %22 %22;
@@ -967,16 +967,17 @@
 (style) 
+%7B
 %0A       
@@ -981,41 +981,98 @@
     
-accum.push
+var sp = node.appendChild(document.createElement
 (%22
-%3C
 span
- class=%5C
+%22));%0A        sp.className = 
 %22cm-%22 + 
 esc(
@@ -1071,56 +1071,101 @@
 %22 + 
-esc(
 style
-) + %22%5C%22%3E%22 + escaped + %22%3C/span%3E%22
+.replace(/ +/g, %22 cm-%22);%0A        sp.appendChild(document.createTextNode(content)
 );%0A     
  els
@@ -1160,21 +1160,25 @@
 );%0A     
+ %7D
  else
+ %7B
 %0A       
@@ -1182,28 +1182,67 @@
     
-accum.push(escaped);
+node.appendChild(document.createTextNode(content));%0A      %7D
 %0A   
@@ -1249,16 +1249,17 @@
  %7D;%0A  %7D%0A
+%0A
   var li
@@ -1643,58 +1643,7 @@
   %7D%0A
-  if (isNode)%0A    node.innerHTML = accum.join(%22%22);%0A
 %7D;%0A

Move from innerHTML to document.create*