stex.js 2.06 KB
CodeMirror.defineMode("stex",function(t,e){function n(t,e){t.cmdState.push(e)}function r(t){return t.cmdState.length>0?t.cmdState[t.cmdState.length-1]:null}function a(t){if(t.cmdState.length>0){var e=t.cmdState.pop();e.closeBracket()}}function c(t){for(var e=t.cmdState,n=e.length-1;n>=0;n--){var r=e[n];if("DEFAULT"!=r.name)return r.styleIdentifier()}return null}function i(t,e,n,r){return function(){this.name=t,this.bracketNo=0,this.style=e,this.styles=r,this.brackets=n,this.styleIdentifier=function(t){return this.bracketNo<=this.styles.length?this.styles[this.bracketNo-1]:null},this.openBracket=function(t){return this.bracketNo++,"bracket"},this.closeBracket=function(t){}}}function o(t,e){t.f=e}function s(t,e){if(t.match(/^\\[a-zA-Z@]+/)){var a=t.current();a=a.substr(1,a.length-1);var i;return i=f.hasOwnProperty(a)?f[a]:f.DEFAULT,i=new i,n(e,i),o(e,l),i.style}if(t.match(/^\\[$&%#{}_]/))return"tag";if(t.match(/^\\[,;!\/]/))return"tag";var s=t.next();return"%"==s?(t.eol()||o(e,u),"comment"):"}"==s||"]"==s?(i=r(e))?(i.closeBracket(s),o(e,l),"bracket"):"error":"{"==s||"["==s?(i=f.DEFAULT,i=new i,n(e,i),"bracket"):/\d/.test(s)?(t.eatWhile(/[\w.%]/),"atom"):(t.eatWhile(/[\w-_]/),c(e))}function u(t,e){return t.skipToEnd(),o(e,s),"comment"}function l(t,e){var n=t.peek();if("{"==n||"["==n){var c=r(e);c.openBracket(n);return t.eat(n),o(e,s),"bracket"}return/[ \t\r]/.test(n)?(t.eat(n),null):(o(e,s),c=r(e),c&&a(e),s(t,e))}var f=new Array;return f.importmodule=i("importmodule","tag","{[",["string","builtin"]),f.documentclass=i("documentclass","tag","{[",["","atom"]),f.usepackage=i("documentclass","tag","[",["atom"]),f.begin=i("documentclass","tag","[",["atom"]),f.end=i("documentclass","tag","[",["atom"]),f.DEFAULT=function(){this.name="DEFAULT",this.style="tag",this.styleIdentifier=function(t){},this.openBracket=function(t){},this.closeBracket=function(t){}},{startState:function(){return{f:s,cmdState:[]}},copyState:function(t){return{f:t.f,cmdState:t.cmdState.slice(0,t.cmdState.length)}},token:function(t,e){var n=e.f(t,e);t.current();return n}}}),CodeMirror.defineMIME("text/x-stex","stex");