summaryrefslogtreecommitdiff
path: root/public/vendor/codemirror/addon/mode
diff options
context:
space:
mode:
authorWu Cheng-Han2015-05-04 15:53:29 +0800
committerWu Cheng-Han2015-05-04 15:53:29 +0800
commit4b0ca55eb79e963523eb6c8197825e9e8ae904e2 (patch)
tree574f3923af77b37b41dbf1b00bcd7827ef724a28 /public/vendor/codemirror/addon/mode
parent61eb11d23c65c9e5c493c67d055f785cbec139e2 (diff)
First commit, version 0.2.7
Diffstat (limited to 'public/vendor/codemirror/addon/mode')
-rwxr-xr-xpublic/vendor/codemirror/addon/mode/loadmode.js64
-rwxr-xr-xpublic/vendor/codemirror/addon/mode/multiplex.js123
-rwxr-xr-xpublic/vendor/codemirror/addon/mode/multiplex_test.js33
-rwxr-xr-xpublic/vendor/codemirror/addon/mode/overlay.js85
-rwxr-xr-xpublic/vendor/codemirror/addon/mode/simple.js213
5 files changed, 518 insertions, 0 deletions
diff --git a/public/vendor/codemirror/addon/mode/loadmode.js b/public/vendor/codemirror/addon/mode/loadmode.js
new file mode 100755
index 00000000..10117ec2
--- /dev/null
+++ b/public/vendor/codemirror/addon/mode/loadmode.js
@@ -0,0 +1,64 @@
+// CodeMirror, copyright (c) by Marijn Haverbeke and others
+// Distributed under an MIT license: http://codemirror.net/LICENSE
+
+(function(mod) {
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
+ mod(require("../../lib/codemirror"), "cjs");
+ else if (typeof define == "function" && define.amd) // AMD
+ define(["../../lib/codemirror"], function(CM) { mod(CM, "amd"); });
+ else // Plain browser env
+ mod(CodeMirror, "plain");
+})(function(CodeMirror, env) {
+ if (!CodeMirror.modeURL) CodeMirror.modeURL = "../mode/%N/%N.js";
+
+ var loading = {};
+ function splitCallback(cont, n) {
+ var countDown = n;
+ return function() { if (--countDown == 0) cont(); };
+ }
+ function ensureDeps(mode, cont) {
+ var deps = CodeMirror.modes[mode].dependencies;
+ if (!deps) return cont();
+ var missing = [];
+ for (var i = 0; i < deps.length; ++i) {
+ if (!CodeMirror.modes.hasOwnProperty(deps[i]))
+ missing.push(deps[i]);
+ }
+ if (!missing.length) return cont();
+ var split = splitCallback(cont, missing.length);
+ for (var i = 0; i < missing.length; ++i)
+ CodeMirror.requireMode(missing[i], split);
+ }
+
+ CodeMirror.requireMode = function(mode, cont) {
+ if (typeof mode != "string") mode = mode.name;
+ if (CodeMirror.modes.hasOwnProperty(mode)) return ensureDeps(mode, cont);
+ if (loading.hasOwnProperty(mode)) return loading[mode].push(cont);
+
+ var file = CodeMirror.modeURL.replace(/%N/g, mode);
+ if (env == "plain") {
+ var script = document.createElement("script");
+ script.src = file;
+ var others = document.getElementsByTagName("script")[0];
+ var list = loading[mode] = [cont];
+ CodeMirror.on(script, "load", function() {
+ ensureDeps(mode, function() {
+ for (var i = 0; i < list.length; ++i) list[i]();
+ });
+ });
+ others.parentNode.insertBefore(script, others);
+ } else if (env == "cjs") {
+ require(file);
+ cont();
+ } else if (env == "amd") {
+ requirejs([file], cont);
+ }
+ };
+
+ CodeMirror.autoLoadMode = function(instance, mode) {
+ if (!CodeMirror.modes.hasOwnProperty(mode))
+ CodeMirror.requireMode(mode, function() {
+ instance.setOption("mode", instance.getOption("mode"));
+ });
+ };
+});
diff --git a/public/vendor/codemirror/addon/mode/multiplex.js b/public/vendor/codemirror/addon/mode/multiplex.js
new file mode 100755
index 00000000..fe48c7fb
--- /dev/null
+++ b/public/vendor/codemirror/addon/mode/multiplex.js
@@ -0,0 +1,123 @@
+// CodeMirror, copyright (c) by Marijn Haverbeke and others
+// Distributed under an MIT license: http://codemirror.net/LICENSE
+
+(function(mod) {
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
+ mod(require("../../lib/codemirror"));
+ else if (typeof define == "function" && define.amd) // AMD
+ define(["../../lib/codemirror"], mod);
+ else // Plain browser env
+ mod(CodeMirror);
+})(function(CodeMirror) {
+"use strict";
+
+CodeMirror.multiplexingMode = function(outer /*, others */) {
+ // Others should be {open, close, mode [, delimStyle] [, innerStyle]} objects
+ var others = Array.prototype.slice.call(arguments, 1);
+
+ function indexOf(string, pattern, from, returnEnd) {
+ if (typeof pattern == "string") {
+ var found = string.indexOf(pattern, from);
+ return returnEnd && found > -1 ? found + pattern.length : found;
+ }
+ var m = pattern.exec(from ? string.slice(from) : string);
+ return m ? m.index + from + (returnEnd ? m[0].length : 0) : -1;
+ }
+
+ return {
+ startState: function() {
+ return {
+ outer: CodeMirror.startState(outer),
+ innerActive: null,
+ inner: null
+ };
+ },
+
+ copyState: function(state) {
+ return {
+ outer: CodeMirror.copyState(outer, state.outer),
+ innerActive: state.innerActive,
+ inner: state.innerActive && CodeMirror.copyState(state.innerActive.mode, state.inner)
+ };
+ },
+
+ token: function(stream, state) {
+ if (!state.innerActive) {
+ var cutOff = Infinity, oldContent = stream.string;
+ for (var i = 0; i < others.length; ++i) {
+ var other = others[i];
+ var found = indexOf(oldContent, other.open, stream.pos);
+ if (found == stream.pos) {
+ if (!other.parseDelimiters) stream.match(other.open);
+ state.innerActive = other;
+ state.inner = CodeMirror.startState(other.mode, outer.indent ? outer.indent(state.outer, "") : 0);
+ return other.delimStyle;
+ } else if (found != -1 && found < cutOff) {
+ cutOff = found;
+ }
+ }
+ if (cutOff != Infinity) stream.string = oldContent.slice(0, cutOff);
+ var outerToken = outer.token(stream, state.outer);
+ if (cutOff != Infinity) stream.string = oldContent;
+ return outerToken;
+ } else {
+ var curInner = state.innerActive, oldContent = stream.string;
+ if (!curInner.close && stream.sol()) {
+ state.innerActive = state.inner = null;
+ return this.token(stream, state);
+ }
+ var found = curInner.close ? indexOf(oldContent, curInner.close, stream.pos, curInner.parseDelimiters) : -1;
+ if (found == stream.pos && !curInner.parseDelimiters) {
+ stream.match(curInner.close);
+ state.innerActive = state.inner = null;
+ return curInner.delimStyle;
+ }
+ if (found > -1) stream.string = oldContent.slice(0, found);
+ var innerToken = curInner.mode.token(stream, state.inner);
+ if (found > -1) stream.string = oldContent;
+
+ if (found == stream.pos && curInner.parseDelimiters)
+ state.innerActive = state.inner = null;
+
+ if (curInner.innerStyle) {
+ if (innerToken) innerToken = innerToken + ' ' + curInner.innerStyle;
+ else innerToken = curInner.innerStyle;
+ }
+
+ return innerToken;
+ }
+ },
+
+ indent: function(state, textAfter) {
+ var mode = state.innerActive ? state.innerActive.mode : outer;
+ if (!mode.indent) return CodeMirror.Pass;
+ return mode.indent(state.innerActive ? state.inner : state.outer, textAfter);
+ },
+
+ blankLine: function(state) {
+ var mode = state.innerActive ? state.innerActive.mode : outer;
+ if (mode.blankLine) {
+ mode.blankLine(state.innerActive ? state.inner : state.outer);
+ }
+ if (!state.innerActive) {
+ for (var i = 0; i < others.length; ++i) {
+ var other = others[i];
+ if (other.open === "\n") {
+ state.innerActive = other;
+ state.inner = CodeMirror.startState(other.mode, mode.indent ? mode.indent(state.outer, "") : 0);
+ }
+ }
+ } else if (state.innerActive.close === "\n") {
+ state.innerActive = state.inner = null;
+ }
+ },
+
+ electricChars: outer.electricChars,
+
+ innerMode: function(state) {
+ return state.inner ? {state: state.inner, mode: state.innerActive.mode} : {state: state.outer, mode: outer};
+ }
+ };
+};
+
+});
diff --git a/public/vendor/codemirror/addon/mode/multiplex_test.js b/public/vendor/codemirror/addon/mode/multiplex_test.js
new file mode 100755
index 00000000..d3394342
--- /dev/null
+++ b/public/vendor/codemirror/addon/mode/multiplex_test.js
@@ -0,0 +1,33 @@
+// CodeMirror, copyright (c) by Marijn Haverbeke and others
+// Distributed under an MIT license: http://codemirror.net/LICENSE
+
+(function() {
+ CodeMirror.defineMode("markdown_with_stex", function(){
+ var inner = CodeMirror.getMode({}, "stex");
+ var outer = CodeMirror.getMode({}, "markdown");
+
+ var innerOptions = {
+ open: '$',
+ close: '$',
+ mode: inner,
+ delimStyle: 'delim',
+ innerStyle: 'inner'
+ };
+
+ return CodeMirror.multiplexingMode(outer, innerOptions);
+ });
+
+ var mode = CodeMirror.getMode({}, "markdown_with_stex");
+
+ function MT(name) {
+ test.mode(
+ name,
+ mode,
+ Array.prototype.slice.call(arguments, 1),
+ 'multiplexing');
+ }
+
+ MT(
+ "stexInsideMarkdown",
+ "[strong **Equation:**] [delim $][inner&tag \\pi][delim $]");
+})();
diff --git a/public/vendor/codemirror/addon/mode/overlay.js b/public/vendor/codemirror/addon/mode/overlay.js
new file mode 100755
index 00000000..e1b9ed37
--- /dev/null
+++ b/public/vendor/codemirror/addon/mode/overlay.js
@@ -0,0 +1,85 @@
+// CodeMirror, copyright (c) by Marijn Haverbeke and others
+// Distributed under an MIT license: http://codemirror.net/LICENSE
+
+// Utility function that allows modes to be combined. The mode given
+// as the base argument takes care of most of the normal mode
+// functionality, but a second (typically simple) mode is used, which
+// can override the style of text. Both modes get to parse all of the
+// text, but when both assign a non-null style to a piece of code, the
+// overlay wins, unless the combine argument was true and not overridden,
+// or state.overlay.combineTokens was true, in which case the styles are
+// combined.
+
+(function(mod) {
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
+ mod(require("../../lib/codemirror"));
+ else if (typeof define == "function" && define.amd) // AMD
+ define(["../../lib/codemirror"], mod);
+ else // Plain browser env
+ mod(CodeMirror);
+})(function(CodeMirror) {
+"use strict";
+
+CodeMirror.overlayMode = function(base, overlay, combine) {
+ return {
+ startState: function() {
+ return {
+ base: CodeMirror.startState(base),
+ overlay: CodeMirror.startState(overlay),
+ basePos: 0, baseCur: null,
+ overlayPos: 0, overlayCur: null,
+ streamSeen: null
+ };
+ },
+ copyState: function(state) {
+ return {
+ base: CodeMirror.copyState(base, state.base),
+ overlay: CodeMirror.copyState(overlay, state.overlay),
+ basePos: state.basePos, baseCur: null,
+ overlayPos: state.overlayPos, overlayCur: null
+ };
+ },
+
+ token: function(stream, state) {
+ if (stream != state.streamSeen ||
+ Math.min(state.basePos, state.overlayPos) < stream.start) {
+ state.streamSeen = stream;
+ state.basePos = state.overlayPos = stream.start;
+ }
+
+ if (stream.start == state.basePos) {
+ state.baseCur = base.token(stream, state.base);
+ state.basePos = stream.pos;
+ }
+ if (stream.start == state.overlayPos) {
+ stream.pos = stream.start;
+ state.overlayCur = overlay.token(stream, state.overlay);
+ state.overlayPos = stream.pos;
+ }
+ stream.pos = Math.min(state.basePos, state.overlayPos);
+
+ // state.overlay.combineTokens always takes precedence over combine,
+ // unless set to null
+ if (state.overlayCur == null) return state.baseCur;
+ else if (state.baseCur != null &&
+ state.overlay.combineTokens ||
+ combine && state.overlay.combineTokens == null)
+ return state.baseCur + " " + state.overlayCur;
+ else return state.overlayCur;
+ },
+
+ indent: base.indent && function(state, textAfter) {
+ return base.indent(state.base, textAfter);
+ },
+ electricChars: base.electricChars,
+
+ innerMode: function(state) { return {state: state.base, mode: base}; },
+
+ blankLine: function(state) {
+ if (base.blankLine) base.blankLine(state.base);
+ if (overlay.blankLine) overlay.blankLine(state.overlay);
+ }
+ };
+};
+
+});
diff --git a/public/vendor/codemirror/addon/mode/simple.js b/public/vendor/codemirror/addon/mode/simple.js
new file mode 100755
index 00000000..795328b8
--- /dev/null
+++ b/public/vendor/codemirror/addon/mode/simple.js
@@ -0,0 +1,213 @@
+// CodeMirror, copyright (c) by Marijn Haverbeke and others
+// Distributed under an MIT license: http://codemirror.net/LICENSE
+
+(function(mod) {
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
+ mod(require("../../lib/codemirror"));
+ else if (typeof define == "function" && define.amd) // AMD
+ define(["../../lib/codemirror"], mod);
+ else // Plain browser env
+ mod(CodeMirror);
+})(function(CodeMirror) {
+ "use strict";
+
+ CodeMirror.defineSimpleMode = function(name, states) {
+ CodeMirror.defineMode(name, function(config) {
+ return CodeMirror.simpleMode(config, states);
+ });
+ };
+
+ CodeMirror.simpleMode = function(config, states) {
+ ensureState(states, "start");
+ var states_ = {}, meta = states.meta || {}, hasIndentation = false;
+ for (var state in states) if (state != meta && states.hasOwnProperty(state)) {
+ var list = states_[state] = [], orig = states[state];
+ for (var i = 0; i < orig.length; i++) {
+ var data = orig[i];
+ list.push(new Rule(data, states));
+ if (data.indent || data.dedent) hasIndentation = true;
+ }
+ }
+ var mode = {
+ startState: function() {
+ return {state: "start", pending: null,
+ local: null, localState: null,
+ indent: hasIndentation ? [] : null};
+ },
+ copyState: function(state) {
+ var s = {state: state.state, pending: state.pending,
+ local: state.local, localState: null,
+ indent: state.indent && state.indent.slice(0)};
+ if (state.localState)
+ s.localState = CodeMirror.copyState(state.local.mode, state.localState);
+ if (state.stack)
+ s.stack = state.stack.slice(0);
+ for (var pers = state.persistentStates; pers; pers = pers.next)
+ s.persistentStates = {mode: pers.mode,
+ spec: pers.spec,
+ state: pers.state == state.localState ? s.localState : CodeMirror.copyState(pers.mode, pers.state),
+ next: s.persistentStates};
+ return s;
+ },
+ token: tokenFunction(states_, config),
+ innerMode: function(state) { return state.local && {mode: state.local.mode, state: state.localState}; },
+ indent: indentFunction(states_, meta)
+ };
+ if (meta) for (var prop in meta) if (meta.hasOwnProperty(prop))
+ mode[prop] = meta[prop];
+ return mode;
+ };
+
+ function ensureState(states, name) {
+ if (!states.hasOwnProperty(name))
+ throw new Error("Undefined state " + name + "in simple mode");
+ }
+
+ function toRegex(val, caret) {
+ if (!val) return /(?:)/;
+ var flags = "";
+ if (val instanceof RegExp) {
+ if (val.ignoreCase) flags = "i";
+ val = val.source;
+ } else {
+ val = String(val);
+ }
+ return new RegExp((caret === false ? "" : "^") + "(?:" + val + ")", flags);
+ }
+
+ function asToken(val) {
+ if (!val) return null;
+ if (typeof val == "string") return val.replace(/\./g, " ");
+ var result = [];
+ for (var i = 0; i < val.length; i++)
+ result.push(val[i] && val[i].replace(/\./g, " "));
+ return result;
+ }
+
+ function Rule(data, states) {
+ if (data.next || data.push) ensureState(states, data.next || data.push);
+ this.regex = toRegex(data.regex);
+ this.token = asToken(data.token);
+ this.data = data;
+ }
+
+ function tokenFunction(states, config) {
+ return function(stream, state) {
+ if (state.pending) {
+ var pend = state.pending.shift();
+ if (state.pending.length == 0) state.pending = null;
+ stream.pos += pend.text.length;
+ return pend.token;
+ }
+
+ if (state.local) {
+ if (state.local.end && stream.match(state.local.end)) {
+ var tok = state.local.endToken || null;
+ state.local = state.localState = null;
+ return tok;
+ } else {
+ var tok = state.local.mode.token(stream, state.localState), m;
+ if (state.local.endScan && (m = state.local.endScan.exec(stream.current())))
+ stream.pos = stream.start + m.index;
+ return tok;
+ }
+ }
+
+ var curState = states[state.state];
+ for (var i = 0; i < curState.length; i++) {
+ var rule = curState[i];
+ var matches = (!rule.data.sol || stream.sol()) && stream.match(rule.regex);
+ if (matches) {
+ if (rule.data.next) {
+ state.state = rule.data.next;
+ } else if (rule.data.push) {
+ (state.stack || (state.stack = [])).push(state.state);
+ state.state = rule.data.push;
+ } else if (rule.data.pop && state.stack && state.stack.length) {
+ state.state = state.stack.pop();
+ }
+
+ if (rule.data.mode)
+ enterLocalMode(config, state, rule.data.mode, rule.token);
+ if (rule.data.indent)
+ state.indent.push(stream.indentation() + config.indentUnit);
+ if (rule.data.dedent)
+ state.indent.pop();
+ if (matches.length > 2) {
+ state.pending = [];
+ for (var j = 2; j < matches.length; j++)
+ if (matches[j])
+ state.pending.push({text: matches[j], token: rule.token[j - 1]});
+ stream.backUp(matches[0].length - (matches[1] ? matches[1].length : 0));
+ return rule.token[0];
+ } else if (rule.token && rule.token.join) {
+ return rule.token[0];
+ } else {
+ return rule.token;
+ }
+ }
+ }
+ stream.next();
+ return null;
+ };
+ }
+
+ function cmp(a, b) {
+ if (a === b) return true;
+ if (!a || typeof a != "object" || !b || typeof b != "object") return false;
+ var props = 0;
+ for (var prop in a) if (a.hasOwnProperty(prop)) {
+ if (!b.hasOwnProperty(prop) || !cmp(a[prop], b[prop])) return false;
+ props++;
+ }
+ for (var prop in b) if (b.hasOwnProperty(prop)) props--;
+ return props == 0;
+ }
+
+ function enterLocalMode(config, state, spec, token) {
+ var pers;
+ if (spec.persistent) for (var p = state.persistentStates; p && !pers; p = p.next)
+ if (spec.spec ? cmp(spec.spec, p.spec) : spec.mode == p.mode) pers = p;
+ var mode = pers ? pers.mode : spec.mode || CodeMirror.getMode(config, spec.spec);
+ var lState = pers ? pers.state : CodeMirror.startState(mode);
+ if (spec.persistent && !pers)
+ state.persistentStates = {mode: mode, spec: spec.spec, state: lState, next: state.persistentStates};
+
+ state.localState = lState;
+ state.local = {mode: mode,
+ end: spec.end && toRegex(spec.end),
+ endScan: spec.end && spec.forceEnd !== false && toRegex(spec.end, false),
+ endToken: token && token.join ? token[token.length - 1] : token};
+ }
+
+ function indexOf(val, arr) {
+ for (var i = 0; i < arr.length; i++) if (arr[i] === val) return true;
+ }
+
+ function indentFunction(states, meta) {
+ return function(state, textAfter, line) {
+ if (state.local && state.local.mode.indent)
+ return state.local.mode.indent(state.localState, textAfter, line);
+ if (state.indent == null || state.local || meta.dontIndentStates && indexOf(state.state, meta.dontIndentStates) > -1)
+ return CodeMirror.Pass;
+
+ var pos = state.indent.length - 1, rules = states[state.state];
+ scan: for (;;) {
+ for (var i = 0; i < rules.length; i++) {
+ var rule = rules[i];
+ if (rule.data.dedent && rule.data.dedentIfLineStart !== false) {
+ var m = rule.regex.exec(textAfter);
+ if (m && m[0]) {
+ pos--;
+ if (rule.next || rule.push) rules = states[rule.next || rule.push];
+ textAfter = textAfter.slice(m[0].length);
+ continue scan;
+ }
+ }
+ }
+ break;
+ }
+ return pos < 0 ? 0 : state.indent[pos];
+ };
+ }
+});