forked from phcode-dev/staging.phcode.dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstex.js
More file actions
1 lines (1 loc) · 4.48 KB
/
Copy pathstex.js
File metadata and controls
1 lines (1 loc) · 4.48 KB
1
!function(mod){"object"==typeof exports&&"object"==typeof module?mod(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],mod):mod(CodeMirror)}(function(CodeMirror){"use strict";CodeMirror.defineMode("stex",function(_config,parserConfig){function pushCommand(state,command){state.cmdState.push(command)}function peekCommand(state){return state.cmdState.length>0?state.cmdState[state.cmdState.length-1]:null}function popCommand(state){var plug=state.cmdState.pop();plug&&plug.closeBracket()}function getMostPowerful(state){for(var context=state.cmdState,i=context.length-1;i>=0;i--){var plug=context[i];if("DEFAULT"!=plug.name)return plug}return{styleIdentifier:function(){return null}}}function addPluginPattern(pluginName,cmdStyle,styles){return function(){this.name=pluginName,this.bracketNo=0,this.style=cmdStyle,this.styles=styles,this.argument=null,this.styleIdentifier=function(){return this.styles[this.bracketNo-1]||null},this.openBracket=function(){return this.bracketNo++,"bracket"},this.closeBracket=function(){}}}var plugins={};function setState(state,f){state.f=f}function normal(source,state){var plug;if(source.match(/^\\[a-zA-Z@]+/)){var cmdName=source.current().slice(1);return pushCommand(state,plug=new(plug=plugins.hasOwnProperty(cmdName)?plugins[cmdName]:plugins.DEFAULT)),setState(state,beginParams),plug.style}if(source.match(/^\\[$&%#{}_]/))return"tag";if(source.match(/^\\[,;!\/\\]/))return"tag";if(source.match("\\["))return setState(state,function(source,state){return inMathMode(source,state,"\\]")}),"keyword";if(source.match("\\("))return setState(state,function(source,state){return inMathMode(source,state,"\\)")}),"keyword";if(source.match("$$"))return setState(state,function(source,state){return inMathMode(source,state,"$$")}),"keyword";if(source.match("$"))return setState(state,function(source,state){return inMathMode(source,state,"$")}),"keyword";var ch=source.next();return"%"==ch?(source.skipToEnd(),"comment"):"}"==ch||"]"==ch?(plug=peekCommand(state))?(plug.closeBracket(ch),setState(state,beginParams),"bracket"):"error":"{"==ch||"["==ch?(pushCommand(state,plug=new(plug=plugins.DEFAULT)),"bracket"):/\d/.test(ch)?(source.eatWhile(/[\w.%]/),"atom"):(source.eatWhile(/[\w\-_]/),"begin"==(plug=getMostPowerful(state)).name&&(plug.argument=source.current()),plug.styleIdentifier())}function inMathMode(source,state,endModeSeq){if(source.eatSpace())return null;if(endModeSeq&&source.match(endModeSeq))return setState(state,normal),"keyword";if(source.match(/^\\[a-zA-Z@]+/))return"tag";if(source.match(/^[a-zA-Z]+/))return"variable-2";if(source.match(/^\\[$&%#{}_]/))return"tag";if(source.match(/^\\[,;!\/]/))return"tag";if(source.match(/^[\^_&]/))return"tag";if(source.match(/^[+\-<>|=,\/@!*:;'"`~#?]/))return null;if(source.match(/^(\d+\.\d*|\d*\.\d+|\d+)/))return"number";var ch=source.next();return"{"==ch||"}"==ch||"["==ch||"]"==ch||"("==ch||")"==ch?"bracket":"%"==ch?(source.skipToEnd(),"comment"):"error"}function beginParams(source,state){var ch=source.peek(),lastPlug;return"{"==ch||"["==ch?((lastPlug=peekCommand(state)).openBracket(ch),source.eat(ch),setState(state,normal),"bracket"):/[ \t\r]/.test(ch)?(source.eat(ch),null):(setState(state,normal),popCommand(state),normal(source,state))}return plugins.importmodule=addPluginPattern("importmodule","tag",["string","builtin"]),plugins.documentclass=addPluginPattern("documentclass","tag",["","atom"]),plugins.usepackage=addPluginPattern("usepackage","tag",["atom"]),plugins.begin=addPluginPattern("begin","tag",["atom"]),plugins.end=addPluginPattern("end","tag",["atom"]),plugins.label=addPluginPattern("label","tag",["atom"]),plugins.ref=addPluginPattern("ref","tag",["atom"]),plugins.eqref=addPluginPattern("eqref","tag",["atom"]),plugins.cite=addPluginPattern("cite","tag",["atom"]),plugins.bibitem=addPluginPattern("bibitem","tag",["atom"]),plugins.Bibitem=addPluginPattern("Bibitem","tag",["atom"]),plugins.RBibitem=addPluginPattern("RBibitem","tag",["atom"]),plugins.DEFAULT=function(){this.name="DEFAULT",this.style="tag",this.styleIdentifier=this.openBracket=this.closeBracket=function(){}},{startState:function(){var f;return{cmdState:[],f:parserConfig.inMathMode?function(source,state){return inMathMode(source,state)}:normal}},copyState:function(s){return{cmdState:s.cmdState.slice(),f:s.f}},token:function(stream,state){return state.f(stream,state)},blankLine:function(state){state.f=normal,state.cmdState.length=0},lineComment:"%"}}),CodeMirror.defineMIME("text/x-stex","stex"),CodeMirror.defineMIME("text/x-latex","stex")});