topical media & game development

talk show tell print

mobile-query-three-www-vendor-CodeMirror2-lib-util-runmode.js / js



  CodeMirror.runMode = function(string, modespec, callback) {
    var mode = CodeMirror.getMode({indentUnit: 2}, modespec);
    var isNode = callback.nodeType == 1;
    if (isNode) {
      var node = callback, accum = [];
      callback = function(string, style) {
        if (string == "\n")
          accum.push("<br>");
        else if (style)
          accum.push("<span class=\"cm-" + CodeMirror.htmlEscape(style) + "\">" + CodeMirror.htmlEscape(string) + "</span>");
        else
          accum.push(CodeMirror.htmlEscape(string));
      }
    }
    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("");
  };
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.