4
function copyObj(obj, target, overwrite) {
5
if (!target) { target = {}; }
7
{ if (obj.hasOwnProperty(prop) && (overwrite !== false || !target.hasOwnProperty(prop)))
8
{ target[prop] = obj[prop]; } }
14
function countColumn(string, end, tabSize, startIndex, startValue) {
16
end = string.search(/[^\s\u00a0]/);
17
if (end == -1) { end = string.length; }
19
for (var i = startIndex || 0, n = startValue || 0;;) {
20
var nextTab = string.indexOf("\t", i);
21
if (nextTab < 0 || nextTab >= end)
22
{ return n + (end - i) }
24
n += tabSize - (n % tabSize);
31
function createObj(base, props) {
34
inst = Object.create(base);
36
nothing.prototype = base;
39
if (props) { copyObj(props, inst); }
48
var StringStream = function(string, tabSize, lineOracle) {
49
this.pos = this.start = 0;
51
this.tabSize = tabSize || 8;
52
this.lastColumnPos = this.lastColumnValue = 0;
54
this.lineOracle = lineOracle;
57
StringStream.prototype.eol = function () {return this.pos >= this.string.length};
58
StringStream.prototype.sol = function () {return this.pos == this.lineStart};
59
StringStream.prototype.peek = function () {return this.string.charAt(this.pos) || undefined};
60
StringStream.prototype.next = function () {
61
if (this.pos < this.string.length)
62
{ return this.string.charAt(this.pos++) }
64
StringStream.prototype.eat = function (match) {
65
var ch = this.string.charAt(this.pos);
67
if (typeof match == "string") { ok = ch == match; }
68
else { ok = ch && (match.test ? match.test(ch) : match(ch)); }
69
if (ok) {++this.pos; return ch}
71
StringStream.prototype.eatWhile = function (match) {
73
while (this.eat(match)){}
74
return this.pos > start
76
StringStream.prototype.eatSpace = function () {
78
while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) { ++this.pos; }
79
return this.pos > start
81
StringStream.prototype.skipToEnd = function () {this.pos = this.string.length;};
82
StringStream.prototype.skipTo = function (ch) {
83
var found = this.string.indexOf(ch, this.pos);
84
if (found > -1) {this.pos = found; return true}
86
StringStream.prototype.backUp = function (n) {this.pos -= n;};
87
StringStream.prototype.column = function () {
88
if (this.lastColumnPos < this.start) {
89
this.lastColumnValue = countColumn(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue);
90
this.lastColumnPos = this.start;
92
return this.lastColumnValue - (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0)
94
StringStream.prototype.indentation = function () {
95
return countColumn(this.string, null, this.tabSize) -
96
(this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0)
98
StringStream.prototype.match = function (pattern, consume, caseInsensitive) {
99
if (typeof pattern == "string") {
100
var cased = function (str) { return caseInsensitive ? str.toLowerCase() : str; };
101
var substr = this.string.substr(this.pos, pattern.length);
102
if (cased(substr) == cased(pattern)) {
103
if (consume !== false) { this.pos += pattern.length; }
107
var match = this.string.slice(this.pos).match(pattern);
108
if (match && match.index > 0) { return null }
109
if (match && consume !== false) { this.pos += match[0].length; }
113
StringStream.prototype.current = function (){return this.string.slice(this.start, this.pos)};
114
StringStream.prototype.hideFirstChars = function (n, inner) {
116
try { return inner() }
117
finally { this.lineStart -= n; }
119
StringStream.prototype.lookAhead = function (n) {
120
var oracle = this.lineOracle;
121
return oracle && oracle.lookAhead(n)
123
StringStream.prototype.baseToken = function () {
124
var oracle = this.lineOracle;
125
return oracle && oracle.baseToken(this.pos)
129
var modes = {}, mimeModes = {};
134
function defineMode(name, mode) {
135
if (arguments.length > 2)
136
{ mode.dependencies = Array.prototype.slice.call(arguments, 2); }
140
function defineMIME(mime, spec) {
141
mimeModes[mime] = spec;
146
function resolveMode(spec) {
147
if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) {
148
spec = mimeModes[spec];
149
} else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) {
150
var found = mimeModes[spec.name];
151
if (typeof found == "string") { found = {name: found}; }
152
spec = createObj(found, spec);
153
spec.name = found.name;
154
} else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) {
155
return resolveMode("application/xml")
156
} else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+json$/.test(spec)) {
157
return resolveMode("application/json")
159
if (typeof spec == "string") { return {name: spec} }
160
else { return spec || {name: "null"} }
165
function getMode(options, spec) {
166
spec = resolveMode(spec);
167
var mfactory = modes[spec.name];
168
if (!mfactory) { return getMode(options, "text/plain") }
169
var modeObj = mfactory(options, spec);
170
if (modeExtensions.hasOwnProperty(spec.name)) {
171
var exts = modeExtensions[spec.name];
172
for (var prop in exts) {
173
if (!exts.hasOwnProperty(prop)) { continue }
174
if (modeObj.hasOwnProperty(prop)) { modeObj["_" + prop] = modeObj[prop]; }
175
modeObj[prop] = exts[prop];
178
modeObj.name = spec.name;
179
if (spec.helperType) { modeObj.helperType = spec.helperType; }
180
if (spec.modeProps) { for (var prop$1 in spec.modeProps)
181
{ modeObj[prop$1] = spec.modeProps[prop$1]; } }
188
var modeExtensions = {};
189
function extendMode(mode, properties) {
190
var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {});
191
copyObj(properties, exts);
194
function copyState(mode, state) {
195
if (state === true) { return state }
196
if (mode.copyState) { return mode.copyState(state) }
198
for (var n in state) {
200
if (val instanceof Array) { val = val.concat([]); }
208
function innerMode(mode, state) {
210
while (mode.innerMode) {
211
info = mode.innerMode(state);
212
if (!info || info.mode == mode) { break }
216
return info || {mode: mode, state: state}
219
function startState(mode, a1, a2) {
220
return mode.startState ? mode.startState(a1, a2) : true
226
mimeModes: mimeModes,
227
defineMode: defineMode,
228
defineMIME: defineMIME,
229
resolveMode: resolveMode,
231
modeExtensions: modeExtensions,
232
extendMode: extendMode,
233
copyState: copyState,
234
innerMode: innerMode,
235
startState: startState
241
var root = typeof globalThis !== 'undefined' ? globalThis : window;
242
root.CodeMirror = {};
245
CodeMirror.StringStream = StringStream;
246
for (var exported in modeMethods) { CodeMirror[exported] = modeMethods[exported]; }
249
CodeMirror.defineMode("null", function () { return ({token: function (stream) { return stream.skipToEnd(); }}); });
250
CodeMirror.defineMIME("text/plain", "null");
252
CodeMirror.registerHelper = CodeMirror.registerGlobalHelper = Math.min;
253
CodeMirror.splitLines = function(string) { return string.split(/\r?\n|\r/) };
254
CodeMirror.countColumn = countColumn;
256
CodeMirror.defaults = { indentUnit: 2 };
262
if (typeof exports == "object" && typeof module == "object")
263
{ mod(require("../../lib/codemirror")); }
264
else if (typeof define == "function" && define.amd)
265
{ define(["../../lib/codemirror"], mod); }
268
})(function(CodeMirror) {
270
CodeMirror.runMode = function(string, modespec, callback, options) {
271
var mode = CodeMirror.getMode(CodeMirror.defaults, modespec);
272
var tabSize = (options && options.tabSize) || CodeMirror.defaults.tabSize;
275
if (callback.appendChild) {
276
var ie = /MSIE \d/.test(navigator.userAgent);
277
var ie_lt9 = ie && (document.documentMode == null || document.documentMode < 9);
278
var node = callback, col = 0;
280
callback = function(text, style) {
284
node.appendChild(document.createTextNode(ie_lt9 ? '\r' : text));
290
for (var pos = 0;;) {
291
var idx = text.indexOf("\t", pos);
293
content += text.slice(pos);
294
col += text.length - pos;
298
content += text.slice(pos, idx);
299
var size = tabSize - col % tabSize;
301
for (var i = 0; i < size; ++i) { content += " "; }
307
var sp = node.appendChild(document.createElement("span"));
308
sp.className = "cm-" + style.replace(/ +/g, " cm-");
309
sp.appendChild(document.createTextNode(content));
311
node.appendChild(document.createTextNode(content));
316
var lines = CodeMirror.splitLines(string), state = (options && options.state) || CodeMirror.startState(mode);
317
for (var i = 0, e = lines.length; i < e; ++i) {
318
if (i) { callback("\n"); }
319
var stream = new CodeMirror.StringStream(lines[i], null, {
320
lookAhead: function(n) { return lines[i + n] },
321
baseToken: function() {}
323
if (!stream.string && mode.blankLine) { mode.blankLine(state); }
324
while (!stream.eol()) {
325
var style = mode.token(stream, state);
326
callback(stream.current(), style, i, stream.start, state, mode);
327
stream.start = stream.pos;