var e={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 t(e,t){t.mode=u.newLayout,t.tableHeading=!1,t.layoutType===`definitionList`&&t.spanningLayout&&e.match(l(`definitionListEnd`),!1)&&(t.spanningLayout=!1)}function n(t,n,a){if(a===`_`)return t.eat(`_`)?r(t,n,`italic`,/__/,2):r(t,n,`em`,/_/,1);if(a===`*`)return t.eat(`*`)?r(t,n,`bold`,/\*\*/,2):r(t,n,`strong`,/\*/,1);if(a===`[`)return t.match(/\d+\]/)&&(n.footCite=!0),i(n);if(a===`(`&&t.match(/^(r|tm|c)\)/))return e.specialChar;if(a===`<`&&t.match(/(\w+)[^>]+>[^<]+<\/\1>/))return e.html;if(a===`?`&&t.eat(`?`))return r(t,n,`cite`,/\?\?/,2);if(a===`=`&&t.eat(`=`))return r(t,n,`notextile`,/==/,2);if(a===`-`&&!t.eat(`-`))return r(t,n,`deletion`,/-/,1);if(a===`+`)return r(t,n,`addition`,/\+/,1);if(a===`~`)return r(t,n,`sub`,/~/,1);if(a===`^`)return r(t,n,`sup`,/\^/,1);if(a===`%`)return r(t,n,`span`,/%/,1);if(a===`@`)return r(t,n,`code`,/@/,1);if(a===`!`){var o=r(t,n,`image`,/(?:\([^\)]+\))?!/,1);return t.match(/^:\S+/),o}return i(n)}function r(e,t,n,r,a){var o=e.pos>a?e.string.charAt(e.pos-a-1):null,s=e.peek();if(t[n]){if((!s||/\W/.test(s))&&o&&/\S/.test(o)){var c=i(t);return t[n]=!1,c}}else (!o||/\W/.test(o))&&s&&/\S/.test(s)&&e.match(RegExp(`^.*\\S`+r.source+`(?:\\W|$)`),!1)&&(t[n]=!0,t.mode=u.attributes);return i(t)}function i(t){var n=a(t);if(n)return n;var r=[];return t.layoutType&&r.push(e[t.layoutType]),r=r.concat(o(t,`addition`,`bold`,`cite`,`code`,`deletion`,`em`,`footCite`,`image`,`italic`,`link`,`span`,`strong`,`sub`,`sup`,`table`,`tableHeading`)),t.layoutType===`header`&&r.push(e.header+`-`+t.header),r.length?r.join(` `):null}function a(t){var n=t.layoutType;switch(n){case`notextile`:case`code`:case`pre`:return e[n];default:return t.notextile?e.notextile+(n?` `+e[n]:``):null}}function o(t){for(var n=[],r=1;r]+)?>(?:[^<]+<\/\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 c.makeRe(`^`,c.single.drawTable,`$`);case`html`:return c.makeRe(`^`,c.single.html,`(?:`,c.single.html,`)*`,`$`);case`linkDefinition`:return c.makeRe(`^`,c.single.linkDefinition,`$`);case`listLayout`:return c.makeRe(`^`,c.single.list,l(`allAttributes`),`*\\s+`);case`tableCellAttributes`:return c.makeRe(`^`,c.choiceRe(c.single.tableCellAttributes,l(`allAttributes`)),`+\\.`);case`type`:return c.makeRe(`^`,l(`allTypes`));case`typeLayout`:return c.makeRe(`^`,l(`allTypes`),l(`allAttributes`),`*\\.\\.?`,`(\\s+|$)`);case`attributes`:return c.makeRe(`^`,l(`allAttributes`),`+`);case`allTypes`:return c.choiceRe(c.single.div,c.single.foot,c.single.header,c.single.bc,c.single.bq,c.single.notextile,c.single.pre,c.single.table,c.single.para);case`allAttributes`:return c.choiceRe(c.attributes.selector,c.attributes.css,c.attributes.lang,c.attributes.align,c.attributes.pad);default:return c.makeRe(`^`,c.single[e])}},makeRe:function(){for(var e=``,t=0;t