diff options
author | Jose Antonio Marquez | 2012-03-09 13:36:41 -0800 |
---|---|---|
committer | Jose Antonio Marquez | 2012-03-09 13:36:41 -0800 |
commit | 9a03f869ff4520431da3ac8c64b748b5fbb60339 (patch) | |
tree | dad948f012cbc7d65e0dccde273667a389ff1c6d /imports/codemirror/lib/util/runmode.js | |
parent | b0b4a1ee6792d98f06cbd8ecf5291e66db8a4eef (diff) | |
parent | b4eb2f6cc1208fe5c18aa1f02a85adda25075d81 (diff) | |
download | ninja-9a03f869ff4520431da3ac8c64b748b5fbb60339.tar.gz |
Merge branch 'refs/heads/Ninja-Internal' into Color
Diffstat (limited to 'imports/codemirror/lib/util/runmode.js')
-rw-r--r--[-rwxr-xr-x] | imports/codemirror/lib/util/runmode.js | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/imports/codemirror/lib/util/runmode.js b/imports/codemirror/lib/util/runmode.js index de4a7602..fc58d857 100755..100644 --- a/imports/codemirror/lib/util/runmode.js +++ b/imports/codemirror/lib/util/runmode.js | |||
@@ -1,15 +1,37 @@ | |||
1 | CodeMirror.runMode = function(string, modespec, callback) { | 1 | CodeMirror.runMode = function(string, modespec, callback, options) { |
2 | var mode = CodeMirror.getMode({indentUnit: 2}, modespec); | 2 | var mode = CodeMirror.getMode(CodeMirror.defaults, modespec); |
3 | var isNode = callback.nodeType == 1; | 3 | var isNode = callback.nodeType == 1; |
4 | var tabSize = (options && options.tabSize) || CodeMirror.defaults.tabSize; | ||
4 | if (isNode) { | 5 | if (isNode) { |
5 | var node = callback, accum = []; | 6 | var node = callback, accum = [], col = 0; |
6 | callback = function(string, style) { | 7 | callback = function(text, style) { |
7 | if (string == "\n") | 8 | if (text == "\n") { |
8 | accum.push("<br>"); | 9 | accum.push("<br>"); |
9 | else if (style) | 10 | col = 0; |
10 | accum.push("<span class=\"cm-" + CodeMirror.htmlEscape(style) + "\">" + CodeMirror.htmlEscape(string) + "</span>"); | 11 | return; |
12 | } | ||
13 | var escaped = ""; | ||
14 | // HTML-escape and replace tabs | ||
15 | for (var pos = 0;;) { | ||
16 | var idx = text.indexOf("\t", pos); | ||
17 | if (idx == -1) { | ||
18 | escaped += CodeMirror.htmlEscape(text.slice(pos)); | ||
19 | col += text.length - pos; | ||
20 | break; | ||
21 | } else { | ||
22 | col += idx - pos; | ||
23 | escaped += CodeMirror.htmlEscape(text.slice(pos, idx)); | ||
24 | var size = tabSize - col % tabSize; | ||
25 | col += size; | ||
26 | for (var i = 0; i < size; ++i) escaped += " "; | ||
27 | pos = idx + 1; | ||
28 | } | ||
29 | } | ||
30 | |||
31 | if (style) | ||
32 | accum.push("<span class=\"cm-" + CodeMirror.htmlEscape(style) + "\">" + escaped + "</span>"); | ||
11 | else | 33 | else |
12 | accum.push(CodeMirror.htmlEscape(string)); | 34 | accum.push(escaped); |
13 | } | 35 | } |
14 | } | 36 | } |
15 | var lines = CodeMirror.splitLines(string), state = CodeMirror.startState(mode); | 37 | var lines = CodeMirror.splitLines(string), state = CodeMirror.startState(mode); |