gfm.js
1.85 KB
CodeMirror.defineMode("gfm",function(t,e){function o(t,e){return t.sol()&&t.match(/^```([\w+#]*)/)?(e.localMode=l(RegExp.$1),e.localMode&&(e.localState=e.localMode.startState()),e.token=r,"code"):a.token(t,e.mdState)}function r(t,e){return t.sol()&&t.match(/^```/)?(e.localMode=e.localState=null,e.token=o,"code"):e.localMode?e.localMode.token(t,e.localState):(t.skipToEnd(),"code")}function n(t,e){var o;if(t.match(/^\w+:\/\/\S+/))return"link";if(t.match(/^[^\[*\\<>` _][^\[*\\<>` ]*[^\[*\\<>` _]/))return a.getType(e);if(o=t.match(/^[^\[*\\<>` ]+/)){var r=o[0];return"_"===r[0]&&"_"===r[r.length-1]?void t.backUp(r.length):a.getType(e)}return t.eatSpace()?null:void 0}var a=CodeMirror.getMode(t,"markdown"),c={html:"htmlmixed",js:"javascript",json:"application/json",c:"text/x-csrc","c++":"text/x-c++src",java:"text/x-java",csharp:"text/x-csharp","c#":"text/x-csharp"},l=function(){var e,o,r={},n={},a=CodeMirror.listModes();for(e=0;e<a.length;e++)r[a[e]]=a[e];var l=CodeMirror.listMIMEs();for(e=0;e<l.length;e++)o=l[e].mime,n[o]=l[e].mime;for(var i in c)(c[i]in r||c[i]in n)&&(r[i]=c[i]);return function(e){return r[e]?CodeMirror.getMode(t,r[e]):null}}();return{startState:function(){var t=a.startState();return t.text=n,{token:o,mode:"markdown",mdState:t,localMode:null,localState:null}},copyState:function(t){return{token:t.token,mode:t.mode,mdState:CodeMirror.copyState(a,t.mdState),localMode:t.localMode,localState:t.localMode?CodeMirror.copyState(t.localMode,t.localState):null}},token:function(t,e){if(void 0!=(ch=t.peek())&&"["==ch){if(t.next(),void 0==(ch=t.peek())||"["!=ch)return t.backUp(1),e.token(t,e);for(;void 0!=(ch=t.next())&&"]"!=ch;);if("]"==ch&&void 0!=(ch=t.next())&&"]"==ch)return"link";t.backUp(1)}return t.match(/^\$[^\$]+\$/)?"string":t.match(/^\\\((.*?)\\\)/)?"string":t.match(/^\$\$[^\$]+\$\$/)?"string":t.match(/^\\\[(.*?)\\\]/)?"string":e.token(t,e)}}},"markdown");