Sha256: 2036ab672c5d0d2c0064c07869029d4f9d3d4caad7cf87bb34d5d69b3c26a038

Contents?: true

Size: 1.63 KB

Versions: 160

Compression:

Stored size: 1.63 KB

Contents

CodeMirror.runMode = function(string, modespec, callback, options) {
  function esc(str) {
    return str.replace(/[<&]/, 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("");
};

Version data entries

160 entries across 160 versions & 4 rubygems

Version Path
marty-2.4.7 app/components/marty/script_form/client/util/runmode.js
marty-2.4.6 app/components/marty/script_form/client/util/runmode.js
marty-2.4.5 app/components/marty/script_form/client/util/runmode.js
marty-2.4.4 app/components/marty/script_form/client/util/runmode.js
marty-2.4.3 app/components/marty/script_form/client/util/runmode.js
marty-2.4.2 app/components/marty/script_form/client/util/runmode.js
marty-2.4.1 app/components/marty/script_form/client/util/runmode.js
marty-2.4.0 app/components/marty/script_form/client/util/runmode.js
marty-2.3.15 app/components/marty/script_form/client/util/runmode.js
marty-2.3.14 app/components/marty/script_form/client/util/runmode.js
marty-2.3.13 app/components/marty/script_form/client/util/runmode.js
marty-2.3.12 app/components/marty/script_form/client/util/runmode.js
marty-2.3.11 app/components/marty/script_form/client/util/runmode.js
marty-2.3.10 app/components/marty/script_form/client/util/runmode.js
marty-2.3.9 app/components/marty/script_form/client/util/runmode.js
marty-2.3.8 app/components/marty/script_form/client/util/runmode.js
marty-2.3.7 app/components/marty/script_form/client/util/runmode.js
marty-2.3.5 app/components/marty/script_form/client/util/runmode.js
marty-2.3.4 app/components/marty/script_form/client/util/runmode.js
marty-2.1.5 app/components/marty/script_form/client/util/runmode.js