tiki.js
3.58 KB
CodeMirror.defineMode("tiki",function(e,t){function n(e,t,n){return function(r,a){for(;!r.eol();){if(r.match(t)){a.tokenize=i;break}r.next()}return n&&(a.tokenize=n),e}}function r(e,t){return function(t,n){for(;!t.eol();)t.next();return n.tokenize=i,e}}function i(e,t){function o(n){return t.tokenize=n,n(e,t)}var u=e.sol(),c=e.next();switch(c){case"{":h=e.eat("/")?"closeTag":"openTag",e.eatSpace(),tagName="";for(var f;f=e.eat(/[^\s\u00a0=\"\'\/?(}]/);)tagName+=f;return t.tokenize=a,"tag";case"_":if(e.eat("_"))return o(n("strong","__",i));break;case"'":if(e.eat("'"))return o(n("em","''",i));break;case"(":if(e.eat("("))return o(n("variable-2","))",i));break;case"[":return o(n("variable-3","]",i));case"|":if(e.eat("|"))return o(n("comment","||"));break;case"-":if(e.eat("="))return o(n("header string","=-",i));if(e.eat("-"))return o(n("error tw-deleted","--",i));break;case"=":if(e.match("=="))return o(n("tw-underline","===",i));break;case":":if(e.eat(":"))return o(n("comment","::"));break;case"^":return o(n("tw-box","^"));case"~":if(e.match("np~"))return o(n("meta","~/np~"))}if(u)switch(c){case"!":return o(e.match("!!!!!")?r("header string"):e.match("!!!!")?r("header string"):e.match("!!!")?r("header string"):e.match("!!")?r("header string"):r("header string"));case"*":case"#":case"+":return o(r("tw-listitem bracket"))}return null}function a(e,t){var n=e.next(),r=e.peek();return"}"==n?(t.tokenize=i,"tag"):"("==n||")"==n?"bracket":"="==n?(h="equals",">"==r&&(n=e.next(),r=e.peek()),/[\'\"]/.test(r)||(t.tokenize=u()),"operator"):/[\'\"]/.test(n)?(t.tokenize=o(n),t.tokenize(e,t)):(e.eatWhile(/[^\s\u00a0=\"\'\/?]/),"keyword")}function o(e){return function(t,n){for(;!t.eol();)if(t.next()==e){n.tokenize=a;break}return"string"}}function u(){return function(e,t){for(;!e.eol();){var n=e.next(),r=e.peek();if(" "==n||","==n||/[ )}]/.test(r)){t.tokenize=a;break}}return"string"}}function c(){for(var e=arguments.length-1;e>=0;e--)b.cc.push(arguments[e])}function f(){return c.apply(null,arguments),!0}function s(e,t){var n=b.context&&b.context.noIndent;b.context={prev:b.context,pluginName:e,indent:b.indented,startOfLine:t,noIndent:n}}function l(){b.context&&(b.context=b.context.prev)}function d(e){if("openPlugin"==e)return b.pluginName=v,f(p,k(b.startOfLine));if("closePlugin"==e){var t=!1;return b.context?(t=b.context.pluginName!=v,l()):t=!0,t&&(z="error"),f(g(t))}return"string"==e?(b.context&&"!cdata"==b.context.name||s("!cdata"),b.tokenize==i&&l(),f()):f()}function k(e){return function(t){return"selfclosePlugin"==t||"endPlugin"==t?f():"endPlugin"==t?(s(b.pluginName,e),f()):f()}}function g(e){return function(t){return e&&(z="error"),"endPlugin"==t?f():c()}}function p(e){return"keyword"==e?(z="attribute",f(p)):"equals"==e?f(m,p):c()}function m(e){return"keyword"==e?(z="string",f()):"string"==e?f(x):c()}function x(e){return"string"==e?f(x):c()}var v,h,b,z,N=e.indentUnit;return{startState:function(){return{tokenize:i,cc:[],indented:0,startOfLine:!0,pluginName:null,context:null}},token:function(e,t){if(e.sol()&&(t.startOfLine=!0,t.indented=e.indentation()),e.eatSpace())return null;z=h=v=null;var n=t.tokenize(e,t);if((n||h)&&"comment"!=n)for(b=t;;){var r=t.cc.pop()||d;if(r(h||n))break}return t.startOfLine=!1,z||n},indent:function(e,t){var n=e.context;if(n&&n.noIndent)return 0;for(n&&/^{\//.test(t)&&(n=n.prev);n&&!n.startOfLine;)n=n.prev;return n?n.indent+N:0},compareStates:function(e,t){if(e.indented!=t.indented||e.pluginName!=t.pluginName)return!1;for(var n=e.context,r=t.context;;n=n.prev,r=r.prev){if(!n||!r)return n==r;if(n.pluginName!=r.pluginName)return!1}},electricChars:"/"}}),CodeMirror.defineMIME("text/tiki","tiki");