LaravelTest
76 строк · 2.7 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5if (typeof exports == "object" && typeof module == "object") // CommonJS6mod(require("../../lib/codemirror"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14CodeMirror.runMode = function(string, modespec, callback, options) {15var mode = CodeMirror.getMode(CodeMirror.defaults, modespec);16var tabSize = (options && options.tabSize) || CodeMirror.defaults.tabSize;17
18// Create a tokenizing callback function if passed-in callback is a DOM element.19if (callback.appendChild) {20var ie = /MSIE \d/.test(navigator.userAgent);21var ie_lt9 = ie && (document.documentMode == null || document.documentMode < 9);22var node = callback, col = 0;23node.innerHTML = "";24callback = function(text, style) {25if (text == "\n") {26// Emitting LF or CRLF on IE8 or earlier results in an incorrect display.27// Emitting a carriage return makes everything ok.28node.appendChild(document.createTextNode(ie_lt9 ? '\r' : text));29col = 0;30return;31}32var content = "";33// replace tabs34for (var pos = 0;;) {35var idx = text.indexOf("\t", pos);36if (idx == -1) {37content += text.slice(pos);38col += text.length - pos;39break;40} else {41col += idx - pos;42content += text.slice(pos, idx);43var size = tabSize - col % tabSize;44col += size;45for (var i = 0; i < size; ++i) content += " ";46pos = idx + 1;47}48}49// Create a node with token style and append it to the callback DOM element.50if (style) {51var sp = node.appendChild(document.createElement("span"));52sp.className = "cm-" + style.replace(/ +/g, " cm-");53sp.appendChild(document.createTextNode(content));54} else {55node.appendChild(document.createTextNode(content));56}57};58}59
60var lines = CodeMirror.splitLines(string), state = (options && options.state) || CodeMirror.startState(mode);61for (var i = 0, e = lines.length; i < e; ++i) {62if (i) callback("\n");63var stream = new CodeMirror.StringStream(lines[i], null, {64lookAhead: function(n) { return lines[i + n] },65baseToken: function() {}66});67if (!stream.string && mode.blankLine) mode.blankLine(state);68while (!stream.eol()) {69var style = mode.token(stream, state);70callback(stream.current(), style, i, stream.start, state, mode);71stream.start = stream.pos;72}73}74};75
76});77