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