1 line
6.6 KiB
JavaScript
1 line
6.6 KiB
JavaScript
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<arguments.length;++r)t[arguments[r]]&&n.push(e[arguments[r]]);return n}function s(e){var t=e.spanningLayout,n=e.layoutType;for(var r in e)e.hasOwnProperty(r)&&delete e[r];e.mode=u.newLayout,t&&(e.layoutType=n,e.spanningLayout=!0)}var c={cache:{},single:{bc:`bc`,bq:`bq`,definitionList:/- .*?:=+/,definitionListEnd:/.*=:\s*$/,div:`div`,drawTable:/\|.*\|/,foot:/fn\d+/,header:/h[1-6]/,html:/\s*<(?:\/)?(\w+)(?:[^>]+)?>(?:[^<]+<\/\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<arguments.length;++t){var n=arguments[t];e+=typeof n==`string`?n:n.source}return new RegExp(e)},choiceRe:function(){for(var e=[arguments[0]],t=1;t<arguments.length;++t)e[t*2-1]=`|`,e[t*2]=arguments[t];return e.unshift(`(?:`),e.push(`)`),c.makeRe.apply(null,e)}};function l(e){return c.cache[e]||(c.cache[e]=c.createRe(e))}var u={newLayout:function(e,t){if(e.match(l(`typeLayout`),!1))return t.spanningLayout=!1,(t.mode=u.blockType)(e,t);var n;return a(t)||(e.match(l(`listLayout`),!1)?n=u.list:e.match(l(`drawTable`),!1)?n=u.table:e.match(l(`linkDefinition`),!1)?n=u.linkDefinition:e.match(l(`definitionList`))?n=u.definitionList:e.match(l(`html`),!1)&&(n=u.html)),(t.mode=n||u.text)(e,t)},blockType:function(e,t){var n,r;if(t.layoutType=null,n=e.match(l(`type`)))r=n[0];else return(t.mode=u.text)(e,t);return(n=r.match(l(`header`)))?(t.layoutType=`header`,t.header=parseInt(n[0][1])):r.match(l(`bq`))?t.layoutType=`quote`:r.match(l(`bc`))?t.layoutType=`code`:r.match(l(`foot`))?t.layoutType=`footnote`:r.match(l(`notextile`))?t.layoutType=`notextile`:r.match(l(`pre`))?t.layoutType=`pre`:r.match(l(`div`))?t.layoutType=`div`:r.match(l(`table`))&&(t.layoutType=`table`),t.mode=u.attributes,i(t)},text:function(e,t){if(e.match(l(`text`)))return i(t);var r=e.next();return r===`"`?(t.mode=u.link)(e,t):n(e,t,r)},attributes:function(t,n){return n.mode=u.layoutLength,t.match(l(`attributes`))?e.attributes:i(n)},layoutLength:function(e,t){return e.eat(`.`)&&e.eat(`.`)&&(t.spanningLayout=!0),t.mode=u.text,i(t)},list:function(e,t){t.listDepth=e.match(l(`list`))[0].length;var n=(t.listDepth-1)%3;return n?n===1?t.layoutType=`list2`:t.layoutType=`list3`:t.layoutType=`list1`,t.mode=u.attributes,i(t)},link:function(t,n){return n.mode=u.text,t.match(l(`link`))?(t.match(/\S+/),e.link):i(n)},linkDefinition:function(t){return t.skipToEnd(),e.linkDefinition},definitionList:function(e,t){return e.match(l(`definitionList`)),t.layoutType=`definitionList`,e.match(/\s*$/)?t.spanningLayout=!0:t.mode=u.attributes,i(t)},html:function(t){return t.skipToEnd(),e.html},table:function(e,t){return t.layoutType=`table`,(t.mode=u.tableCell)(e,t)},tableCell:function(e,t){return e.match(l(`tableHeading`))?t.tableHeading=!0:e.eat(`|`),t.mode=u.tableCellAttributes,i(t)},tableCellAttributes:function(t,n){return n.mode=u.tableText,t.match(l(`tableCellAttributes`))?e.attributes:i(n)},tableText:function(e,t){return e.match(l(`tableText`))?i(t):e.peek()===`|`?(t.mode=u.tableCell,i(t)):n(e,t,e.next())}},d={name:`textile`,startState:function(){return{mode:u.newLayout}},token:function(e,n){return e.sol()&&t(e,n),n.mode(e,n)},blankLine:s};export{d as textile}; |