function inBlock(t,e,n){return function(r,i){for(;!r.eol();){if(r.match(e)){i.tokenize=inText;break}r.next();}return n&&(i.tokenize=n),t}}function inLine(t){return function(e,n){for(;!e.eol();)e.next();return n.tokenize=inText,t}}function inText(t,e){function n(n){return e.tokenize=n,n(t,e)}var r=t.sol(),i=t.next();switch(i){case"{":return t.eat("/"),t.eatSpace(),t.eatWhile(/[^\s\u00a0=\"\'\/?(}]/),e.tokenize=inPlugin,"tag";case"_":if(t.eat("_"))return n(inBlock("strong","__",inText));break;case"'":if(t.eat("'"))return n(inBlock("em","''",inText));break;case"(":if(t.eat("("))return n(inBlock("link","))",inText));break;case"[":return n(inBlock("url","]",inText));case"|":if(t.eat("|"))return n(inBlock("comment","||"));break;case"-":if(t.eat("="))return n(inBlock("header string","=-",inText));if(t.eat("-"))return n(inBlock("error tw-deleted","--",inText));break;case"=":if(t.match("=="))return n(inBlock("tw-underline","===",inText));break;case":":if(t.eat(":"))return n(inBlock("comment","::"));break;case"^":return n(inBlock("tw-box","^"));case"~":if(t.match("np~"))return n(inBlock("meta","~/np~"))}if(r)switch(i){case"!":return t.match("!!!!!")||t.match("!!!!")||t.match("!!!")||t.match("!!"),n(inLine("header string"));case"*":case"#":case"+":return n(inLine("tw-listitem bracket"))}return null}var pluginName,type,curState,setStyle;function inPlugin(t,e){var n=t.next(),r=t.peek();return "}"==n?(e.tokenize=inText,"tag"):"("==n||")"==n?"bracket":"="==n?(type="equals",">"==r&&(t.next(),r=t.peek()),/[\'\"]/.test(r)||(e.tokenize=inAttributeNoQuote()),"operator"):/[\'\"]/.test(n)?(e.tokenize=inAttribute(n),e.tokenize(t,e)):(t.eatWhile(/[^\s\u00a0=\"\'\/?]/),"keyword")}function inAttribute(t){return function(e,n){for(;!e.eol();)if(e.next()==t){n.tokenize=inPlugin;break}return "string"}}function inAttributeNoQuote(){return function(t,e){for(;!t.eol();){var n=t.next(),r=t.peek();if(" "==n||","==n||/[ )}]/.test(r)){e.tokenize=inPlugin;break}}return "string"}}function pass(){for(var t=arguments.length-1;t>=0;t--)curState.cc.push(arguments[t]);}function cont(){return pass.apply(null,arguments),!0}function pushContext(t,e){var n=curState.context&&curState.context.noIndent;curState.context={prev:curState.context,pluginName:t,indent:curState.indented,startOfLine:e,noIndent:n};}function popContext(){curState.context&&(curState.context=curState.context.prev);}function element(t){if("openPlugin"==t)return curState.pluginName=pluginName,cont(attributes,endplugin(curState.startOfLine));if("closePlugin"==t){var e=!1;return curState.context?(e=curState.context.pluginName!=pluginName,popContext()):e=!0,e&&(setStyle="error"),cont(endcloseplugin(e))}return "string"==t?(curState.context&&"!cdata"==curState.context.name||pushContext("!cdata"),curState.tokenize==inText&&popContext(),cont()):cont()}function endplugin(t){return function(e){return "selfclosePlugin"==e||"endPlugin"==e?cont():"endPlugin"==e?(pushContext(curState.pluginName,t),cont()):cont()}}function endcloseplugin(t){return function(e){return t&&(setStyle="error"),"endPlugin"==e?cont():pass()}}function attributes(t){return "keyword"==t?(setStyle="attribute",cont(attributes)):"equals"==t?cont(attvalue,attributes):pass()}function attvalue(t){return "keyword"==t?(setStyle="string",cont()):"string"==t?cont(attvaluemaybe):pass()}function attvaluemaybe(t){return "string"==t?cont(attvaluemaybe):pass()}const tiki={startState:function(){return {tokenize:inText,cc:[],indented:0,startOfLine:!0,pluginName:null,context:null}},token:function(t,e){if(t.sol()&&(e.startOfLine=!0,e.indented=t.indentation()),t.eatSpace())return null;setStyle=type=pluginName=null;var n=e.tokenize(t,e);if((n||type)&&"comment"!=n)for(curState=e;;){if((e.cc.pop()||element)(type||n))break}return e.startOfLine=!1,setStyle||n},indent:function(t,e,n){var r=t.context;if(r&&r.noIndent)return 0;for(r&&/^{\//.test(e)&&(r=r.prev);r&&!r.startOfLine;)r=r.prev;return r?r.indent+n.unit:0}};

export { tiki };
