var s={addition:"inserted",attributes:"propertyName",bold:"strong",cite:"keyword",code:"monospace",definitionList:"list",deletion:"deleted",div:"punctuation",em:"emphasis",footnote:"variable",footCite:"qualifier",header:"heading",html:"comment",image:"atom",italic:"emphasis",link:"link",linkDefinition:"link",list1:"list",list2:"list.special",list3:"list",notextile:"string.special",pre:"operator",p:"content",quote:"bracket",span:"quote",specialChar:"character",strong:"strong",sub:"content.special",sup:"content.special",table:"variableName.special",tableHeading:"operator"};function b(e,t){t.mode=l.newLayout,t.tableHeading=!1,t.layoutType==="definitionList"&&t.spanningLayout&&e.match(r("definitionListEnd"),!1)&&(t.spanningLayout=!1)}function d(e,t,n){if(n==="_")return e.eat("_")?u(e,t,"italic",/__/,2):u(e,t,"em",/_/,1);if(n==="*")return e.eat("*")?u(e,t,"bold",/\*\*/,2):u(e,t,"strong",/\*/,1);if(n==="[")return e.match(/\d+\]/)&&(t.footCite=!0),o(t);if(n==="("){var i=e.match(/^(r|tm|c)\)/);if(i)return s.specialChar}if(n==="<"&&e.match(/(\w+)[^>]+>[^<]+<\/\1>/))return s.html;if(n==="?"&&e.eat("?"))return u(e,t,"cite",/\?\?/,2);if(n==="="&&e.eat("="))return u(e,t,"notextile",/==/,2);if(n==="-"&&!e.eat("-"))return u(e,t,"deletion",/-/,1);if(n==="+")return u(e,t,"addition",/\+/,1);if(n==="~")return u(e,t,"sub",/~/,1);if(n==="^")return u(e,t,"sup",/\^/,1);if(n==="%")return u(e,t,"span",/%/,1);if(n==="@")return u(e,t,"code",/@/,1);if(n==="!"){var c=u(e,t,"image",/(?:\([^\)]+\))?!/,1);return e.match(/^:\S+/),c}return o(t)}function u(e,t,n,i,c){var m=e.pos>c?e.string.charAt(e.pos-c-1):null,p=e.peek();if(t[n]){if((!p||/\W/.test(p))&&m&&/\S/.test(m)){var h=o(t);return t[n]=!1,h}}else(!m||/\W/.test(m))&&p&&/\S/.test(p)&&e.match(new RegExp("^.*\\S"+i.source+"(?:\\W|$)"),!1)&&(t[n]=!0,t.mode=l.attributes);return o(t)}function o(e){var t=f(e);if(t)return t;var n=[];return e.layoutType&&n.push(s[e.layoutType]),n=n.concat(y(e,"addition","bold","cite","code","deletion","em","footCite","image","italic","link","span","strong","sub","sup","table","tableHeading")),e.layoutType==="header"&&n.push(s.header+"-"+e.header),n.length?n.join(" "):null}function f(e){var t=e.layoutType;switch(t){case"notextile":case"code":case"pre":return s[t];default:return e.notextile?s.notextile+(t?" "+s[t]:""):null}}function y(e){for(var t=[],n=1;n]+)?>(?:[^<]+<\/\1>)?/,link:/[^"]+":\S/,linkDefinition:/\[[^\s\]]+\]\S+/,list:/(?:#+|\*+)/,notextile:"notextile",para:"p",pre:"pre",table:"table",tableCellAttributes:/[\/\\]\d+/,tableHeading:/\|_\./,tableText:/[^"_\*\[\(\?\+~\^%@|-]+/,text:/[^!"_=\*\[\(<\?\+~\^%@-]+/},attributes:{align:/(?:<>|<|>|=)/,selector:/\([^\(][^\)]+\)/,lang:/\[[^\[\]]+\]/,pad:/(?:\(+|\)+){1,2}/,css:/\{[^\}]+\}/},createRe:function(e){switch(e){case"drawTable":return a.makeRe("^",a.single.drawTable,"$");case"html":return a.makeRe("^",a.single.html,"(?:",a.single.html,")*","$");case"linkDefinition":return a.makeRe("^",a.single.linkDefinition,"$");case"listLayout":return a.makeRe("^",a.single.list,r("allAttributes"),"*\\s+");case"tableCellAttributes":return a.makeRe("^",a.choiceRe(a.single.tableCellAttributes,r("allAttributes")),"+\\.");case"type":return a.makeRe("^",r("allTypes"));case"typeLayout":return a.makeRe("^",r("allTypes"),r("allAttributes"),"*\\.\\.?","(\\s+|$)");case"attributes":return a.makeRe("^",r("allAttributes"),"+");case"allTypes":return a.choiceRe(a.single.div,a.single.foot,a.single.header,a.single.bc,a.single.bq,a.single.notextile,a.single.pre,a.single.table,a.single.para);case"allAttributes":return a.choiceRe(a.attributes.selector,a.attributes.css,a.attributes.lang,a.attributes.align,a.attributes.pad);default:return a.makeRe("^",a.single[e])}},makeRe:function(){for(var e="",t=0;t