UNPKG

textile-js

Version:

A full-featured JavaScript Textile parser

2 lines 22.8 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("textile",[],t):"object"==typeof exports?exports.textile=t():e.textile=t()}(this,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var a=t[r]={i:r,l:!1,exports:{}};return e[r].call(a.exports,a,a.exports,n),a.l=!0,a.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)n.d(r,a,function(t){return e[t]}.bind(null,a));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=10)}([function(e,t){var n={},r=e.exports={pattern:{punct:"[!-/:-@\\[\\\\\\]-`{-~]",space:"\\s"},escape:function(e){return e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")},collapse:function(e){return e.replace(/(?:#.*?(?:\n|$))/g,"").replace(/\s+/g,"")},expandPatterns:function(e){return e.replace(/\[:\s*(\w+)\s*:\]/g,(function(t,n){var a=r.pattern[n];if(a)return r.expandPatterns(a);throw new Error("Pattern "+t+" not found in "+e)}))},isRegExp:function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},compile:function(e,t){r.isRegExp(e)&&(1===arguments.length&&(t=(e.global?"g":"")+(e.ignoreCase?"i":"")+(e.multiline?"m":"")),e=e.source);var a=e+(t||"");if(a in n)return n[a];var c=r.expandPatterns(e);return t&&/x/.test(t)&&(c=r.collapse(c)),t&&/s/.test(t)&&(c=c.replace(/([^\\])\./g,"$1[^\\0]")),t=(t||"").replace(/[^gim]/g,""),n[a]=new RegExp(c,t)}}},function(e,t){e.exports=function(e){var t,n=String(e),r=0,a={index:function(){return r},save:function(){return t=r,a},load:function(){return r=t,e=n.slice(r),a},advance:function(t){return r+="string"==typeof t?t.length:t,e=n.slice(r)},skipWS:function(){var t=/^\s+/.exec(e);return t?(r+=t[0].length,e=n.slice(r),t[0]):""},lookbehind:function(e){return e=null==e?1:e,n.slice(r-e,r)},startsWith:function(t){return e.substring(0,t.length)===t},slice:function(t,n){return null!=n?e.slice(t,n):e.slice(t)},valueOf:function(){return e},toString:function(){return e}};return a}},function(e,t,n){var r=n(0),a=n(1);r.pattern.html_id="[a-zA-Z][a-zA-Z\\d:]*",r.pattern.html_attr="(?:\"[^\"]+\"|'[^']+'|[^>\\s]+)";var c=r.compile(/^\s*([^=\s]+)(?:\s*=\s*("[^"]+"|'[^']+'|[^>\s]+))?/),s=r.compile(/^<!--(.+?)-->/,"s"),i=r.compile(/^<\/([:html_id:])([^>]*)>/),l=r.compile(/^<([:html_id:])((?:\s[^=\s/]+(?:\s*=\s*[:html_attr:])?)+)?\s*(\/?)>/),o=r.compile(/^\s*<([:html_id:](?::[a-zA-Z\d]+)*)((?:\s[^=\s/]+(?:\s*=\s*[:html_attr:])?)+)?\s*(\/?)>/),p={area:1,base:1,br:1,col:1,embed:1,hr:1,img:1,input:1,link:1,meta:1,option:1,param:1,wbr:1};function u(e){return s.exec(e)}function f(e){return l.exec(e)}function d(e){return i.exec(e)}function h(e){for(var t,n={};t=c.exec(e);)n[t[1]]="string"==typeof t[2]?t[2].replace(/^(["'])(.*)\1$/,"$2"):null,e=e.slice(t[0].length);return n}e.exports={singletons:p,tokenize:function(e,t,n){var r,c=[],s=!1,i=function(e){return s?e===s:!t||e in t},l={},o=0;e=a(String(e));do{if((r=u(e))&&i("!"))c.push({type:"COMMENT",data:r[1],pos:e.index(),src:r[0]}),e.advance(r[0]);else if((r=d(e))&&i(r[1])){var g={type:"CLOSE",tag:r[1],pos:e.index(),src:r[0]};if(e.advance(r[0]),c.push(g),l[g.tag]--,o--,n&&(!o||!l[g.tag]<0||isNaN(l[g.tag])))return c;s&&(s=null)}else if((r=f(e))&&i(r[1])){var v={type:r[3]||r[1]in p?"SINGLE":"OPEN",tag:r[1],pos:e.index(),src:r[0]};r[2]&&(v.attr=h(r[2])),"script"!==r[1]&&"code"!==r[1]&&"style"!==r[1]||(s=v.tag),"OPEN"===v.type&&(o++,l[v.tag]=(l[v.tag]||0)+1),c.push(v),e.advance(r[0])}else(r=/([^<]+|[^\0])/.exec(e))&&c.push({type:"TEXT",data:r[0],pos:e.index(),src:r[0]}),e.advance(r&&r[0].length||1)}while(e.valueOf());return c},parseHtml:function(e,t){for(var n,r=[],a=[],c=r,s=0;s<e.length;s++)if("COMMENT"===(n=e[s]).type)c.push(["!",n.data]);else if("TEXT"===n.type||"WS"===n.type)c.push(n.data);else if("SINGLE"===n.type)c.push(n.attr?[n.tag,n.attr]:[n.tag]);else if("OPEN"===n.type){var i=n.attr?[n.tag,n.attr]:[n.tag];c.push(i),a.push(i),c=i}else if("CLOSE"===n.type){if(a.length)for(var l=a.length-1;l>=0;l--){if(a[l][0]===n.tag){a.splice(l),c=a[a.length-1]||r;break}}if(!a.length&&t)return r.sourceLength=n.pos+n.src.length,r}return r.sourceLength=n?n.pos+n.src.length:0,r},parseHtmlAttr:h,testCloseTag:d,testOpenTagBlock:function(e){return o.exec(e)},testOpenTag:f,testComment:u}},function(e,t,n){var r=n(1),a=n(9),c=n(0),s=n(4).parseAttr,i=n(12).parseGlyph,l=n(2),o=l.parseHtml,p=l.parseHtmlAttr,u=l.tokenize,f=l.singletons,d=l.testComment,h=l.testOpenTag,g=n(5),v=g.ucaps,x=g.txattr,m=g.txcite;c.pattern.txattr=x,c.pattern.txcite=m,c.pattern.ucaps=v;var y={"*":"strong","**":"b","??":"cite",_:"em",__:"i","-":"del","%":"span","+":"ins","~":"sub","^":"sup","@":"code"},b=/^([[{]?)(__?|\*\*?|\?\?|[-+^~@%])/,$=c.compile(/^!(?!\s)([:txattr:](?:\.[^\n\S]|\.(?:[^./]))?)([^!\s]+?) ?(?:\(((?:[^()]|\([^()]+\))+)\))?!(?::([^\s]+?(?=[!-.:-@[\\\]-`{-~](?:$|\s)|\s|$)))?/),S=c.compile(/^\[!(?!\s)([:txattr:](?:\.[^\n\S]|\.(?:[^./]))?)([^!\s]+?) ?(?:\(((?:[^()]|\([^()]+\))+)\))?!(?::([^\s]+?(?=[!-.:-@[\\\]-`{-~](?:$|\s)|\s|$)))?\]/),A=c.compile(/^((?!TM\)|tm\))[[:ucaps:]](?:[[:ucaps:]\d]{1,}(?=\()|[[:ucaps:]\d]{2,}))(?:\((.*?)\))?(?=\W|$)/),_=c.compile(/^"(?!\s)((?:[^"]|"(?![\s:])[^\n"]+"(?!:))+)"[:txcite:]/),k=/^\["([^\n]+?)":((?:\[[a-z0-9]*\]|[^\]])+)\]/,O=/\s*\(((?:\([^()]*\)|[^()])+)\)$/,j=/^\[(\d+)(!?)\]/;t.parsePhrase=function e(t,n){t=r(t);var l,g,v=a();do{if(t.save(),t.startsWith("\r\n")&&t.advance(1),t.startsWith("\n"))t.advance(1),t.startsWith(" ")?t.advance(1):n.breaks&&v.add(["br"]),v.add("\n");else if(l=/^==(.*?)==/.exec(t))t.advance(l[0]),v.add(l[1]);else{var x=t.lookbehind(1),m=!x||/^[\s<>.,"'?!;:()[\]%{}]$/.test(x);if((l=b.exec(t))&&(m||l[1])){t.advance(l[0]);var T=l[2],w=l[1],E=y[T],P="code"===E;(g=!P&&s(t,E,T))&&(t.advance(g[0]),g=g[1]);var L=void 0,W=void 0;if("["===w)L="^(.*?)",W="(?:])";else if("{"===w)L="^(.*?)",W="(?:})";else{var M=c.escape(T.charAt(0));L=P?"^(\\S+|\\S+.*?\\S)":"^([^\\s".concat(M,"]+|[^\\s").concat(M,"].*?\\S(").concat(M,"*))"),W="(?=$|[\\s.,\"'!?;:()«»„“”‚‘’<>])"}if((l=c.compile("".concat(L,"(").concat(c.escape(T),")").concat(W)).exec(t))&&l[1]){t.advance(l[0]),P?v.add([E,l[1]]):v.add([E,g].concat(e(l[1],n)));continue}t.load()}if((l=$.exec(t))||(l=S.exec(t))){t.advance(l[0]);var C=(g=l[1]&&s(l[1],"img"))?g[1]:{src:""},z=["img",C];C.src=l[2],C.alt=l[3]?C.title=l[3]:"",l[4]&&(z=["a",{href:l[4]},z]),v.add(z)}else if(l=d(t))t.advance(l[0]),v.add(["!",l[1]]);else{if(l=h(t)){t.advance(l[0]);var H=l[1],N=l[3]||l[1]in f,Z=[H];if(l[2]&&Z.push(p(l[2])),N){v.add(Z).add(t.skipWS());continue}if(l=c.compile("^(.*?)(</".concat(H,"\\s*>)"),"s").exec(t)){if(t.advance(l[0]),"code"===H)Z.push(l[1]);else{if("notextile"===H){v.merge(o(u(l[1])));continue}Z=Z.concat(e(l[1],n))}v.add(Z);continue}t.load()}if((l=j.exec(t))&&/\S/.test(x))t.advance(l[0]),v.add(["sup",{class:"footnote",id:"fnr"+l[1]},"!"===l[2]?l[1]:["a",{href:"#fn"+l[1]},l[1]]]);else if(l=A.exec(t)){t.advance(l[0]);var q=["span",{class:"caps"},l[1]];l[2]&&(q=["acronym",{title:l[2]},q]),v.add(q)}else if(m&&(l=_.exec(t))||(l=k.exec(t))){t.advance(l[0]);var R=l[1].match(O),D=R?l[1].slice(0,l[1].length-R[0].length):l[1];(g=s(D,"a"))?(D=D.slice(g[0]),g=g[1]):g={},R&&!D&&(D=R[0],R=""),g.href=l[2],R&&(g.title=R[1]),"$"===D&&(D=g.href.replace(/^(https?:\/\/|ftps?:\/\/|mailto:)/,"")),v.add(["a",g].concat(e(D.replace(/^(\.?\s*)/,""),n)))}else(l=/([a-zA-Z0-9,.':]+|[ \f\r\t\v\xA0\u2028\u2029]+|[^\0])/.exec(t))&&v.add(l[0]),t.advance(l&&l[0].length||1)}}}while(t.valueOf());return v.get().map(i)}},function(e,t){var n=/^\(([^()\n]+)\)/,r=/^(\(+)/,a=/^(\)+)/,c=/^(<>|<|>|=)/,s=/^(<|>|=)/,i=/^(~|\^|-)/,l=/^\\(\d+)/,o=/^\/(\d+)/,p=/^\{([^}]*)\}/,u=/^\s*([^:\s]+)\s*:\s*(.+)\s*$/,f=/^\[([^[\]\n]+)\]/,d={"<":"left","=":"center",">":"right","<>":"justify"},h={"~":"bottom","^":"top","-":"middle"};e.exports={copyAttr:function(e,t){if(e){var n={};for(var r in e)!(r in e)||t&&r in t||(n[r]=e[r]);return n}},parseAttr:function(e,t,g){if((e=String(e))&&"notextile"!==t){var v,x={},m={style:x},y=e,b=/^(?:table|t[dh]|t(?:foot|head|body)|b[qc]|div|notextile|pre|h[1-6]|fn\\d+|p|###)$/.test(t),$="img"===t,S="li"===t,A=!b&&!$&&"a"!==t,_=$?s:c;do{if(v=p.exec(y))v[1].split(";").forEach((function(e){var t=e.match(u);t&&(x[t[1]]=t[2])})),y=y.slice(v[0].length);else if(v=f.exec(y)){var k=y.slice(v[0].length);!k&&A||g&&g===k.slice(0,g.length)?v=null:(m.lang=v[1],y=y.slice(v[0].length))}else if(v=n.exec(y)){var O=y.slice(v[0].length);if(!O&&A||g&&(" "===O[0]||g===O.slice(0,g.length)))v=null;else{var j=v[1].split("#");j[0]&&(m.class=j[0]),j[1]&&(m.id=j[1]),y=O}}else{if(b||S){if(v=r.exec(y)){x["padding-left"]="".concat(v[1].length,"em"),y=y.slice(v[0].length);continue}if(v=a.exec(y)){x["padding-right"]="".concat(v[1].length,"em"),y=y.slice(v[0].length);continue}}if(($||b||S)&&(v=_.exec(y))){var T=d[v[1]];$?m.align=T:x["text-align"]=T,y=y.slice(v[0].length)}else if("td"!==t&&"tr"!==t||!(v=i.exec(y))){if("td"===t){if(v=l.exec(y)){m.colspan=v[1],y=y.slice(v[0].length);continue}if(v=o.exec(y)){m.rowspan=v[1],y=y.slice(v[0].length);continue}}}else x["vertical-align"]=h[v[1]],y=y.slice(v[0].length)}}while(v);var w=[];for(var E in x)w.push("".concat(E,":").concat(x[E]));return w.length?m.style=w.join(";"):delete m.style,y===e?void 0:[e.length-y.length,m]}}}},function(e,t){t.txblocks="(?:b[qc]|div|notextile|pre|h[1-6]|fn\\d+|p|###)",t.ucaps="A-ZÀ-ÖØ-ÞĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮİIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŸŹŻŽƁƂƄƆƇƉ-ƋƎ-ƑƓƔƖ-ƘƜƝƟƠƢƤƦƧƩƬƮƯƱ-ƳƵƷƸƼDŽLJNJǍǏǑǓǕǗǙǛǞǠǢǤǦǨǪǬǮDZǴǶ-ǸǺǼǾȀȂȄȆȈȊȌȎȐȒȔȖȘȚȜȞȠȢȤȦȨȪȬȮȰȲȺȻȽȾɁɃ-ɆɈɊɌɎḀḂḄḆḈḊḌḎḐḒḔḖḘḚḜḞḠḢḤḦḨḪḬḮḰḲḴḶḸḺḼḾṀṂṄṆṈṊṌṎṐṒṔṖṘṚṜṞṠṢṤṦṨṪṬṮṰṲṴṶṸṺṼṾẀẂẄẆẈẊẌẎẐẒẔẞẠẢẤẦẨẪẬẮẰẲẴẶẸẺẼẾỀỂỄỆỈỊỌỎỐỒỔỖỘỚỜỞỠỢỤỦỨỪỬỮỰỲỴỶỸỺỼỾⱠⱢ-ⱤⱧⱩⱫⱭ-ⱰⱲⱵⱾⱿꜢꜤꜦꜨꜪꜬꜮꜲꜴꜶꜸꜺꜼꜾꝀꝂꝄꝆꝈꝊꝌꝎꝐꝒꝔꝖꝘꝚꝜꝞꝠꝢꝤꝦꝨꝪꝬꝮꝹꝻꝽꝾꞀꞂꞄꞆꞋꞍꞐꞒꞠꞢꞤꞦꞨꞪ",t.txcite=":((?:[^\\s()]|\\([^\\s()]+\\)|[()])+?)(?=[!-\\.:-@\\[\\\\\\]-`{-~]+(?:$|\\s)|$|\\s)";var n=t.attr_class="\\([^\\)]+\\)",r=t.attr_style="\\{[^\\}]+\\}",a=t.attr_lang="\\[[^\\[\\]]+\\]",c=t.attr_align="(?:<>|<|>|=)",s=t.attr_pad="[\\(\\)]+",i=t.txattr="(?:".concat(n,"|").concat(r,"|").concat(a,"|").concat(c,"|").concat(s,")*");t.txlisthd="[\\t ]*(\\*|\\#(?:_|\\d+)?)".concat(i,"(?: +\\S|\\.\\s*(?=\\S|\\n))"),t.txlisthd2="[\\t ]*[\\#\\*]*(\\*|\\#(?:_|\\d+)?)".concat(i,"(?: +\\S|\\.\\s*(?=\\S|\\n))")},function(e,t){e.exports=function(e,t){if(t)for(var n in t)e[n]=t[n];return e}},function(e,t,n){function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var a=n(2).singletons;function c(e,t){return e.replace(/&(?!(#\d{2,}|#x[\da-fA-F]{2,}|[a-zA-Z][a-zA-Z1-4]{1,6});)/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,t?"&quot;":'"').replace(/'/g,t?"&#39;":"'")}e.exports={reIndent:function e(t,n){return n?t.map((function(t){if(/^\n\t+/.test(t))if(n<0)t=t.slice(0,n);else for(var r=0;r<n;r++)t+="\t";else if(Array.isArray(t))return e(t,n);return t})):t},toHTML:function e(t){if("string"==typeof(t=t.concat()))return c(t);var n=t.shift(),s={},i="",l=[];for(t.length&&"object"===r(t[0])&&!Array.isArray(t[0])&&(s=t.shift());t.length;)l.push(e(t.shift()));for(var o in s)i+=null==s[o]?" ".concat(o):" ".concat(o,'="').concat(c(String(s[o]),!0),'"');return"!"===n?"\x3c!--".concat(l.join(""),"--\x3e"):n in a||n.indexOf(":")>-1&&!l.length?"<".concat(n).concat(i," />"):"<".concat(n).concat(i,">").concat(l.join(""),"</").concat(n,">")},escape:c}},function(e,t,n){var r=n(9),a=n(1),c=n(0),s=n(11),i=n(2),l=i.parseHtml,o=i.tokenize,p=i.parseHtmlAttr,u=i.singletons,f=i.testComment,d=i.testOpenTagBlock,h=n(3).parsePhrase,g=n(4),v=g.copyAttr,x=g.parseAttr,m=n(13),y=m.testList,b=m.parseList,$=n(14),S=$.testDefList,A=$.parseDefList,_=n(15),k=_.testTable,O=_.parseTable,j=n(5),T=j.txblocks,w=j.txlisthd,E=j.txattr;c.pattern.txblocks=T,c.pattern.txlisthd=w,c.pattern.txattr=E;var P={p:0,hr:0,ul:1,ol:0,li:0,div:1,pre:0,object:1,script:0,noscript:0,blockquote:1,notextile:1},L=c.compile(/^([:txblocks:])/),W=c.compile(/^(.*?)($|\r?\n(?=[:txlisthd:])|\r?\n(?:\s*\n|$)+)/,"s"),M=c.compile(/^(.*?)($|\r?\n(?=[:txlisthd:])|\r?\n+(?=[:txblocks:][:txattr:]\.))/,"s"),C=c.compile(/^(.*?)($|\r?\n(?:\s*\n|$)+)/,"s"),z=c.compile(/^(.*?)($|\r?\n+(?=[:txblocks:][:txattr:]\.))/,"s"),H=/^(---+|\*\*\*+|___+)(\r?\n\s+|$)/,N=c.compile(/^\[([^\]]+)\]((?:https?:\/\/|\/)\S+)(?:\s*\n|$)/),Z=/^fn\d+$/,q=Object.prototype.hasOwnProperty;function R(e){for(var t=1;t<(arguments.length<=1?0:arguments.length-1);t++){var n=t+1<1||arguments.length<=t+1?void 0:arguments[t+1];if(null!=n)for(var r in n)q.call(n,r)&&(e[r]=n[r])}return e}function D(e,t,n,r,a){t=t||"p";var c=[];return e.split(/(?:\r?\n){2,}/).forEach((function(e,s){"p"===t&&/^\s/.test(e)?(e=e.replace(/\r?\n[\t ]/g," ").trim(),c=c.concat(h(e,a))):(r&&s&&c.push(r),c.push(n?[t,n].concat(h(e,a)):[t].concat(h(e,a))))})),c}t.parseFlow=function e(t,n){var c,i,g=r();for(t=a(t.replace(/^( *\r?\n)+/,""));t.valueOf();)if(t.save(),i=N.exec(t))c||(c={}),t.advance(i[0]),c[i[1]]=i[2];else{if(g.linebreak(),i=L.exec(t)){t.advance(i[0]);var m=i[0],$=x(t,m);if($&&(t.advance($[0]),$=$[1]),i=/^\.(\.?)(?:\s|(?=:))/.exec(t)){var _=!!i[1],j=_?M:W;if("bc"!==m&&"pre"!==m||(j=_?z:C),i=j.exec(t.advance(i[0])),t.advance(i[0]),"bq"===m){var T=i[1];(i=/^:(\S+)\s+/.exec(T))&&($||($={}),$.cite=i[1],T=T.slice(i[0].length));var w=D(T,"p",v($,{cite:1,id:1}),"\n",n);g.add(["blockquote",$,"\n"].concat(w).concat(["\n"]))}else if("bc"===m){var E=$?v($,{id:1}):null;g.add(["pre",$,E?["code",E,i[1]]:["code",i[1]]])}else if("notextile"===m)g.merge(l(o(i[1])));else if("###"===m);else if("pre"===m)g.add(["pre",$,i[1]]);else if(Z.test(m)){var q=m.replace(/\D+/g,"");$||($={}),$.class=($.class?$.class+" ":"")+"footnote",$.id="fn"+q,g.add(["p",$,["a",{href:"#fnr"+q},["sup",q]]," "].concat(h(i[1],n)))}else g.merge(D(i[1],m,$,"\n",n));continue}t.load()}if(i=f(t))t.advance(i[0]+(/(?:\s*\n+)+/.exec(t)||[])[0]),g.add(["!",i[1]]);else{if(i=d(t)){var F=i[1];if(F in P)if(i[3]||F in u){if(t.advance(i[0]),/^\s*(\n|$)/.test(t)){var I=[F];i[2]&&I.push(p(i[2])),g.add(I),t.skipWS();continue}}else if("pre"===F){var G=o(t,{pre:1,code:1},F),B=l(G,!0);if(t.load().advance(B.sourceLength),/^\s*(\n|$)/.test(t)){g.merge(B),t.skipWS();continue}}else if("notextile"===F){for(var X=o(t,null,F),J=1;/^\s+$/.test(X[J].src);)J++;var K=l(X.slice(J,-1),!0),Q=X.pop();if(t.load().advance(Q.pos+Q.src.length),/^\s*(\n|$)/.test(t)){g.merge(K),t.skipWS();continue}}else{t.skipWS();for(var U=o(t,null,F),V=U.pop(),Y=1;U[Y]&&/^[\n\r]+$/.test(U[Y].src);)Y++;if(V.tag===F){var ee=U.length>1?t.slice(U[Y].pos,V.pos):"";if(t.advance(V.pos+V.src.length),/^\s*(\n|$)/.test(t)){var te=[F];if(i[2]&&te.push(p(i[2])),"script"===F||"style"===F)te.push(ee);else{var ne=ee.replace(/^\n+/,"").replace(/\s*$/,""),re=/\n\r?\n/.test(ne)||"ol"===F||"ul"===F,ae=re?e(ne,n):h(ne,R({},n,{breaks:!1}));(re||/^\n/.test(ee))&&te.push("\n"),(re||/\s$/.test(ee))&&ae.push("\n"),te=te.concat(ae)}g.add(te),t.skipWS();continue}}}t.load()}(i=H.exec(t))?(t.advance(i[0]),g.add(["hr"])):(i=y(t))?(t.advance(i[0]),g.add(b(i[0],n))):(i=S(t))?(t.advance(i[0]),g.add(A(i[0],n))):(i=k(t))?(t.advance(i[0]),g.add(O(i[1],n))):(i=W.exec(t),g.merge(D(i[1],"p",void 0,"\n",n)),t.advance(i[0]))}}return c?s(g.get(),c):g.get()}},function(e,t){e.exports=function(e){var t=Array.isArray(e)?e:[];return{add:function(e){return"string"==typeof e&&"string"==typeof t[t.length-1]?t[t.length-1]+=e:Array.isArray(e)?t.push(e.filter((function(e){return void 0!==e}))):e&&t.push(e),this},merge:function(e){for(var t=0,n=e.length;t<n;t++)this.add(e[t]);return this},linebreak:function(){t.length&&this.add("\n")},get:function(){return t}}}},function(e,t,n){var r=n(6),a=n(7).toHTML,c=n(8).parseFlow,s=n(2).parseHtml;function i(e,t){return t=r(r({},i.defaults),t||{}),c(e,t).map(a).join("")}e.exports=i,i.defaults={breaks:!0},i.setOptions=i.setoptions=function(e){return r(i.defaults,e),this},i.parse=i.convert=i,i.html_parser=s,i.jsonml=function(e,t){return t=r(r({},i.defaults),t||{}),["html"].concat(c(e,t))},i.serialize=a},function(e,t){function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}e.exports=function e(t,r){if(Array.isArray(t)){if("a"===t[0]){var a=t[1];"object"===n(a)&&"href"in a&&a.href in r&&(a.href=r[a.href])}for(var c=0,s=t.length;c<s;c++)Array.isArray(t[c])&&e(t[c],r)}return t}},function(e,t,n){var r=n(0),a=/(\w)'(\w)/g,c=/([^-]|^)->/,s=r.compile(/([^\s[(])"(?=$|\s|[:punct:])/g),i=r.compile(/([^\s[(])'(?=$|\s|[:punct:])/g),l=/(\b ?|\s|^)(?:\(C\)|\[C\])/gi,o=/([\d.,]+['"]? ?)x( ?)(?=[\d.,]['"]?)/g,p=r.compile(/(\d*[.,]?\d+)"(?=\s|$|[:punct:])/g),u=/([^.]?)\.{3}/g,f=/(^|[\s\w])--([\s\w]|$)/g,d=/ - /g,h=/"/g,g=/'/g,v=/(\b ?|\s|^)(?:\(R\)|\[R\])/gi,x=r.compile(/(\d*[.,]?\d+)'(?=\s|$|[:punct:])/g),m=/(\b ?|\s|^)(?:\((?:TM|tm)\)|\[(?:TM|tm)\])/g;t.parseGlyph=function(e){return"string"!=typeof e?e:e.replace(c,"$1&#8594;").replace(o,"$1&#215;$2").replace(u,"$1&#8230;").replace(f,"$1&#8212;$2").replace(d," &#8211; ").replace(m,"$1&#8482;").replace(v,"$1&#174;").replace(l,"$1&#169;").replace(p,"$1&#8243;").replace(s,"$1&#8221;").replace(h,"&#8220;").replace(x,"$1&#8242;").replace(a,"$1&#8217;$2").replace(i,"$1&#8217;").replace(g,"&#8216;").replace(/[([]1\/4[\])]/,"&#188;").replace(/[([]1\/2[\])]/,"&#189;").replace(/[([]3\/4[\])]/,"&#190;").replace(/[([]o[\])]/,"&#176;").replace(/[([]\+\/-[\])]/,"&#177;")}},function(e,t,n){var r=n(1),a=n(0),c=n(6),s=n(4).parseAttr,i=n(3).parsePhrase,l=n(5),o=l.txlisthd,p=l.txlisthd2;a.pattern.txlisthd=o,a.pattern.txlisthd2=p;var u=a.compile(/^((?:[:txlisthd:][^\0]*?(?:\r?\n|$))+)(\s*\n|$)/,"s"),f=a.compile(/^([#*]+)([^\0]+?)(\n(?=[:txlisthd2:])|$)/,"s");function d(e){for(var t="\n";e--;)t+="\t";return t}e.exports={testList:function(e){return u.exec(e)},parseList:function(e,t){e=r(e.replace(/(^|\r?\n)[\t ]+/,"$1"));for(var n,a,l,o,p=[],u={},h=t._lst||{},g=0;a=f.exec(e);){var v=["li"],x=a[1].length,m="#"===a[1].substr(-1)?"ol":"ul",y=null,b=void 0,$=void 0,S=void 0,A=void 0;if((l=/^(_|\d+)/.exec(a[2]))&&(g=isFinite(l[1])?parseInt(l[1],10):h[x]||u[x]||1,a[2]=a[2].slice(l[1].length)),(S=s(a[2],"li"))&&(a[2]=a[2].slice(S[0]),S=S[1]),/^\.\s*$/.test(a[2]))n=S||{},e.advance(a[0]);else{for(;p.length<x;)b=[m,{},d(p.length+1),y=["li"]],($=p[p.length-1])&&($.li.push(d(p.length)),$.li.push(b)),p.push({ul:b,li:y,att:0}),u[p.length]=1;for(;p.length>x;)(A=p.pop()).ul.push(d(p.length)),1!==A.att||A.ul[3][1].substr||c(A.ul[1],A.ul[3].splice(1,1)[0]);$=p[p.length-1],g&&($.ul[1].start=g,u[x]=g,g=0),n&&($.att=9,c($.ul[1],n),n=null),y||($.ul.push(d(p.length),v),$.li=v),S&&($.li.push(S),$.att++),Array.prototype.push.apply($.li,i(a[2].trim(),t)),e.advance(a[0]),u[x]=(u[x]||0)+1}}for(t._lst=u;p.length;)(o=p.pop()).ul.push(d(p.length)),1!==o.att||o.ul[3][1].substr||c(o.ul[1],o.ul[3].splice(1,1)[0]);return o.ul}}},function(e,t,n){var r=n(1),a=/^((?:- (?:[^\n]\n?)+?)+:=(?: *\n[^\0]+?=:(?:\n|$)|(?:[^\0]+?(?:$|\n(?=\n|- )))))+/,c=/^((?:- (?:[^\n]\n?)+?)+):=( *\n[^\0]+?=:\s*(?:\n|$)|(?:[^\0]+?(?:$|\n(?=\n|- ))))/;t.testDefList=function(e){return a.exec(e)},t.parseDefList=function(e,t){e=r(e.trim());for(var a,s,i,l=n(3).parsePhrase,o=n(8).parseFlow,p=["dl","\n"];i=c.exec(e);){for(a=i[1].split(/(?:^|\n)- /).slice(1);a.length;)p.push("\t",["dt"].concat(l(a.shift().trim(),t)),"\n");s=i[2].trim(),p.push("\t",["dd"].concat(/=:$/.test(s)?o(s.slice(0,-2).trim(),t):l(s,t)),"\n"),e.advance(i[0])}return p}},function(e,t,n){var r=n(0),a=n(6),c=n(1),s=n(4).parseAttr,i=n(3).parsePhrase,l=n(7).reIndent,o=n(5).txattr;r.pattern.txattr=o;var p=r.compile(/^((?:table[:txattr:]\.(?:\s(.+?))\s*\n)?(?:(?:[:txattr:]\.[^\n\S]*)?\|.*?\|[^\n\S]*(?:\n|$))+)([^\n\S]*\n+)?/,"s"),u=/^table(_?)([^\n]*?)\.(?:[ \t](.+?))?\s*\n/,f=r.compile(/^(?:\|([~^-][:txattr:])\.\s*\n)?([:txattr:]\.[^\n\S]*)?\|(.*?)\|[^\n\S]*(\n|$)/,"s"),d=/^\|=([^\n+]*)\n/,h=/^\|:([^\n+]*)\|[\r\t ]*\n/,g=/^\|([\^\-~])([^\n+]*)\.[ \t\r]*\n/,v={"^":"thead","~":"tfoot","-":"tbody"};function x(e){var t=["colgroup",{}];return e.split("|").forEach((function(e,n){var r,c=n?{}:t[1],i=e.trim();i&&((r=/^\\(\d+)/.exec(i))&&(c.span=+r[1],i=i.slice(r[0].length)),(r=s(i,"col"))&&(a(c,r[1]),i=i.slice(r[0])),(r=/\b\d+\b/.exec(i))&&(c.width=+r[0])),n&&t.push("\n\t\t",["col",c])})),t.concat(["\n\t"])}e.exports={parseColgroup:x,parseTable:function(e,t){e=c(e.trim());var n,r,o,p,m,y,b,$,S=[],A={},_=0,k=function(e,t){o=[e,t||{}],S.push(o)};($=u.exec(e))&&(e.advance($[0]),(y=s($[2],"table"))&&a(A,y[1]),$[3]&&(A.summary=$[3])),($=d.exec(e))&&(r=["caption"],(y=s($[1],"caption"))&&(r.push(y[1]),$[1]=$[1].slice(y[0])),/\./.test($[1])?(r.push($[1].slice(1).replace(/\|\s*$/,"").trim()),_++,e.advance($[0])):r=null);do{if($=h.exec(e))n=x($[1]),_++;else if($=g.exec(e)){var O=v[$[1]]||"tbody";k(O,(y=s("".concat($[2]," "),O))&&y[1]),_++}else if($=f.exec(e)){o||k("tbody"),p=["tr"],$[2]&&(y=s($[2],"tr"))&&p.push(y[1]),o.push("\n\t\t",p),m=c($[3]);do{m.save();var j=m.startsWith("_"),T=[j?"th":"td"];if(j&&m.advance(1),(y=s(m,"td"))&&(m.advance(y[0]),T.push(y[1])),y||j){var w=/^\.\s*/.exec(m);w?m.advance(w[0]):(T=["td"],m.load())}var E=/^(==.*?==|[^|])*/.exec(m);T=T.concat(i(E[0],t)),p.push("\n\t\t\t",T),b="|"===m.valueOf().charAt(E[0].length),m.advance(E[0].length+1)}while(b);p.push("\n\t\t")}$&&e.advance($[0])}while($);var P=["table",A];return _?(r&&P.push("\n\t",r),n&&P.push("\n\t",n),S.forEach((function(e){P.push("\n\t",e.concat(["\n\t"]))}))):P=P.concat(l(S[0].slice(2),-1)),P.push("\n"),P},testTable:function(e){return p.exec(e)}}}])})); //# sourceMappingURL=textile.js.map