| 115 | } |
| 116 | |
| 117 | function highlight(string, mode) { |
| 118 | var state = mode.startState(); |
| 119 | |
| 120 | var lines = string.replace(/\r\n/g,'\n').split('\n'); |
| 121 | var st = [], pos = 0; |
| 122 | for (var i = 0; i < lines.length; ++i) { |
| 123 | var line = lines[i], newLine = true; |
| 124 | if (mode.indent) { |
| 125 | var ws = line.match(/^\s*/)[0]; |
| 126 | var indent = mode.indent(state, line.slice(ws.length), line); |
| 127 | if (indent != CodeMirror.Pass && indent != ws.length) |
| 128 | (st.indentFailures || (st.indentFailures = [])).push( |
| 129 | "Indentation of line " + (i + 1) + " is " + indent + " (expected " + ws.length + ")"); |
| 130 | } |
| 131 | var stream = new CodeMirror.StringStream(line, 4, { |
| 132 | lookAhead: function(n) { return lines[i + n] } |
| 133 | }); |
| 134 | if (line == "" && mode.blankLine) mode.blankLine(state); |
| 135 | /* Start copied code from CodeMirror.highlight */ |
| 136 | while (!stream.eol()) { |
| 137 | for (var j = 0; j < 10 && stream.start >= stream.pos; j++) |
| 138 | var compare = mode.token(stream, state); |
| 139 | if (j == 10) |
| 140 | throw new Failure("Failed to advance the stream." + stream.string + " " + stream.pos); |
| 141 | var substr = stream.current(); |
| 142 | if (compare && compare.indexOf(" ") > -1) compare = compare.split(' ').sort().join(' '); |
| 143 | stream.start = stream.pos; |
| 144 | if (pos && st[pos-1].style == compare && !newLine) { |
| 145 | st[pos-1].text += substr; |
| 146 | } else if (substr) { |
| 147 | st[pos++] = {style: compare, text: substr, state: stringify(state)}; |
| 148 | } |
| 149 | // Give up when line is ridiculously long |
| 150 | if (stream.pos > 5000) { |
| 151 | st[pos++] = {style: null, text: this.text.slice(stream.pos)}; |
| 152 | break; |
| 153 | } |
| 154 | newLine = false; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | return st; |
| 159 | } |
| 160 | |
| 161 | function highlightOutputsDifferent(o1, o2) { |
| 162 | var minLen = Math.min(o1.length, o2.length); |