markdown-to-jsx 7.7.16 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,1755 @@
1
- import*as r from"react";function n(){return n=Object.assign?Object.assign.bind():function(r){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(r[t]=e[t])}return r},n.apply(this,arguments)}var e=["children","options"],t={blockQuote:"0",breakLine:"1",breakThematic:"2",codeBlock:"3",codeFenced:"4",codeInline:"5",footnote:"6",footnoteReference:"7",gfmTask:"8",heading:"9",headingSetext:"10",htmlBlock:"11",htmlComment:"12",htmlSelfClosing:"13",image:"14",link:"15",linkAngleBraceStyleDetector:"16",linkBareUrlDetector:"17",linkMailtoDetector:"18",newlineCoalescer:"19",orderedList:"20",paragraph:"21",ref:"22",refImage:"23",refLink:"24",table:"25",tableSeparator:"26",text:"27",textBolded:"28",textEmphasized:"29",textEscaped:"30",textMarked:"31",textStrikethroughed:"32",unorderedList:"33"},a=["allowFullScreen","allowTransparency","autoComplete","autoFocus","autoPlay","cellPadding","cellSpacing","charSet","classId","colSpan","contentEditable","contextMenu","crossOrigin","encType","formAction","formEncType","formMethod","formNoValidate","formTarget","frameBorder","hrefLang","inputMode","keyParams","keyType","marginHeight","marginWidth","maxLength","mediaGroup","minLength","noValidate","radioGroup","readOnly","rowSpan","spellCheck","srcDoc","srcLang","srcSet","tabIndex","useMap"].reduce(function(r,n){return r[n.toLowerCase()]=n,r},{class:"className",for:"htmlFor"}),u={amp:"&",apos:"'",gt:">",lt:"<",nbsp:" ",quot:"“"},o=["style","script","pre"],i=["src","href","data","formAction","srcDoc","action"],c=/([-A-Z0-9_:]+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|(?:\{((?:\\.|{[^}]*?}|[^}])*)\})))?/gi,f=/\n{2,}$/,l=/^(\s*>[\s\S]*?)(?=\n\n|$)/,s=/^ *> ?/gm,_=/^(?:\[!([^\]]*)\]\n)?([\s\S]*)/,d=/^ {2,}\n/,p=/^(?:([-*_])( *\1){2,}) *(?:\n *)+\n/,v=/^(?: {1,3})?(`{3,}|~{3,}) *(\S+)? *([^\n]*?)?\n([\s\S]*?)(?:\1\n?|$)/,m=/^(?: {4}[^\n]+\n*)+(?:\n *)+\n?/,y=/^(`+)((?:\\`|(?!\1)`|[^`])+)\1/,h=/^(?:\n *)*\n/,g=/\r\n?/g,k=/^\[\^([^\]]+)](:(.*)((\n+ {4,}.*)|(\n(?!\[\^).+))*)/,x=/^\[\^([^\]]+)]/,b=/\f/g,q=/^---[ \t]*\n(.|\n)*\n---[ \t]*\n/,S=/^\s*?\[(x|\s)\]/,z=/^ *(#{1,6}) *([^\n]+?)(?: +#*)?(?:\n *)*(?:\n|$)/,$=/^ *(#{1,6}) +([^\n]+?)(?: +#*)?(?:\n *)*(?:\n|$)/,E=/^([^\n]+)\n *(=|-)\2{2,} *\n/,R=/^ *(?!<[a-z][^ >/]* ?\/>)<([a-z][^ >/]*) ?((?:[^>]*[^/])?)>\n?(\s*(?:<\1[^>]*?>[\s\S]*?<\/\1>|(?!<\1\b)[\s\S])*?)<\/\1>(?!<\/\1>)\n*/i,O=/&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});/gi,A=/^<!--[\s\S]*?(?:-->)/,j=/^(data|aria|x)-[a-z_][a-z\d_.-]*$/,M=/^ *<([a-z][a-z0-9:]*)(?:\s+((?:<.*?>|[^>])*))?\/?>(?!<\/\1>)(\s*\n)?/i,B=/^\{.*\}$/,L=/^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,C=/^<([^ >]+[:@\/][^ >]+)>/,I=/-([a-z])?/gi,N=/^(\|.*)\n(?: *(\|? *[-:]+ *\|[-| :]*)\n((?:.*\|.*\n)*))?\n?/,T=/^[^\n]+(?: \n|\n{2,})/,P=/^\[([^\]]*)\]:\s+<?([^\s>]+)>?\s*("([^"]*)")?/,w=/^!\[([^\]]*)\] ?\[([^\]]*)\]/,D=/^\[([^\]]*)\] ?\[([^\]]*)\]/,F=/(\n|^[-*]\s|^#|^ {2,}|^-{2,}|^>\s)/,Z=/\t/g,G=/(^ *\||\| *$)/g,U=/^ *:-+: *$/,V=/^ *:-+ *$/,H=/^ *-+: *$/,J=function(r){return"(?=[\\s\\S]+?\\1"+(r?"\\1":"")+")"},Q="((?:\\[.*?\\][([].*?[)\\]]|<.*?>(?:.*?<.*?>)?|`.*?`|\\\\\\1|[\\s\\S])+?)",W=RegExp("^([*_])\\1"+J(1)+Q+"\\1\\1(?!\\1)"),K=RegExp("^([*_])"+J(0)+Q+"\\1(?!\\1)"),X=RegExp("^(==)"+J(0)+Q+"\\1"),Y=RegExp("^(~~)"+J(0)+Q+"\\1"),rr=/^(:[a-zA-Z0-9-_]+:)/,nr=/^\\([^0-9A-Za-z\s])/,er=/\\([^0-9A-Za-z\s])/g,tr=/^[\s\S](?:(?! \n|[0-9]\.|http)[^=*_~\-\n:<`\\\[!])*/,ar=/^\n+/,ur=/^([ \t]*)/,or=/(?:^|\n)( *)$/,ir="(?:\\d+\\.)",cr="(?:[*+-])";function fr(r){return"( *)("+(1===r?ir:cr)+") +"}var lr=fr(1),sr=fr(2);function _r(r){return RegExp("^"+(1===r?lr:sr))}var dr=_r(1),pr=_r(2);function vr(r){return RegExp("^"+(1===r?lr:sr)+"[^\\n]*(?:\\n(?!\\1"+(1===r?ir:cr)+" )[^\\n]*)*(\\n|$)","gm")}var mr=vr(1),yr=vr(2);function hr(r){var n=1===r?ir:cr;return RegExp("^( *)("+n+") [\\s\\S]+?(?:\\n{2,}(?! )(?!\\1"+n+" (?!"+n+" ))\\n*|\\s*\\n*$)")}var gr=hr(1),kr=hr(2);function xr(r,n){var e=1===n,a=e?gr:kr,u=e?mr:yr,o=e?dr:pr;return{t:function(r){return o.test(r)},u:Br(function(r,n){var e=or.exec(n.prevCapture);return e&&(n.list||!n.inline&&!n.simple)?a.exec(r=e[1]+r):null}),o:1,i:function(r,n,t){var a=e?+r[2]:void 0,i=r[0].replace(f,"\n").match(u),c=!1;return{items:i.map(function(r,e){var a=o.exec(r)[0].length,u=RegExp("^ {1,"+a+"}","gm"),f=r.replace(u,"").replace(o,""),l=e===i.length-1,s=-1!==f.indexOf("\n\n")||l&&c;c=s;var _,d=t.inline,p=t.list;t.list=!0,s?(t.inline=!1,_=zr(f)+"\n\n"):(t.inline=!0,_=zr(f));var v=n(_,t);return t.inline=d,t.list=p,v}),ordered:e,start:a}},l:function(n,e,a){return r(n.ordered?"ol":"ul",{key:a.key,start:n.type===t.orderedList?n.start:void 0},n.items.map(function(n,t){return r("li",{key:t},e(n,a))}))}}}var br=RegExp("^\\[((?:\\[[^\\[\\]]*(?:\\[[^\\[\\]]*\\][^\\[\\]]*)*\\]|[^\\[\\]])*)\\]\\(\\s*<?((?:\\([^)]*\\)|[^\\s\\\\]|\\\\.)*?)>?(?:\\s+['\"]([\\s\\S]*?)['\"])?\\s*\\)"),qr=/^!\[(.*?)\]\( *((?:\([^)]*\)|[^() ])*) *"?([^)"]*)?"?\)/;function Sr(r){return"string"==typeof r}function zr(r){for(var n=r.length;n>0&&r[n-1]<=" ";)n--;return r.slice(0,n)}function $r(r,n){return r.startsWith(n)}function Er(r,n,e){if(Array.isArray(e)){for(var t=0;t<e.length;t++)if($r(r,e[t]))return!0;return!1}return e(r,n)}function Rr(r){return r.replace(/[ÀÁÂÃÄÅàáâãä忯]/g,"a").replace(/[çÇ]/g,"c").replace(/[ðÐ]/g,"d").replace(/[ÈÉÊËéèêë]/g,"e").replace(/[ÏïÎîÍíÌì]/g,"i").replace(/[Ññ]/g,"n").replace(/[øØœŒÕõÔôÓóÒò]/g,"o").replace(/[ÜüÛûÚúÙù]/g,"u").replace(/[ŸÿÝý]/g,"y").replace(/[^a-z0-9- ]/gi,"").replace(/ /gi,"-").toLowerCase()}function Or(r){return H.test(r)?"right":U.test(r)?"center":V.test(r)?"left":null}function Ar(r,n,e,t){var a=e.inTable;e.inTable=!0;var u=[[]],o="";function i(){if(o){var r=u[u.length-1];r.push.apply(r,n(o,e)),o=""}}return r.trim().split(/(`[^`]*`|\\\||\|)/).filter(Boolean).forEach(function(r,n,e){"|"===r.trim()&&(i(),t)?0!==n&&n!==e.length-1&&u.push([]):o+=r}),i(),e.inTable=a,u}function jr(r,n,e){e.inline=!0;var a=r[2]?r[2].replace(G,"").split("|").map(Or):[],u=r[3]?function(r,n,e){return r.trim().split("\n").map(function(r){return Ar(r,n,e,!0)})}(r[3],n,e):[],o=Ar(r[1],n,e,!!u.length);return e.inline=!1,u.length?{align:a,cells:u,header:o,type:t.table}:{children:o,type:t.paragraph}}function Mr(r,n){return null==r.align[n]?{}:{textAlign:r.align[n]}}function Br(r){return r.inline=1,r}function Lr(r){return Br(function(n,e){return e.inline?r.exec(n):null})}function Cr(r){return Br(function(n,e){return e.inline||e.simple?r.exec(n):null})}function Ir(r){return function(n,e){return e.inline||e.simple?null:r.exec(n)}}function Nr(r){return Br(function(n){return r.exec(n)})}var Tr=/(javascript|vbscript|data(?!:image)):/i;function Pr(r){try{var n=decodeURIComponent(r).replace(/[^A-Za-z0-9/:]/g,"");if(Tr.test(n))return null}catch(r){return null}return r}function wr(r){return r?r.replace(er,"$1"):r}function Dr(r,n,e){var t=e.inline||!1,a=e.simple||!1;e.inline=!0,e.simple=!0;var u=r(n,e);return e.inline=t,e.simple=a,u}function Fr(r,n,e){var t=e.inline||!1,a=e.simple||!1;e.inline=!1,e.simple=!0;var u=r(n,e);return e.inline=t,e.simple=a,u}function Zr(r,n,e){var t=e.inline||!1;e.inline=!1;var a=r(n,e);return e.inline=t,a}var Gr=function(r,n,e){return{children:Dr(n,r[2],e)}};function Ur(){return{}}function Vr(){return null}function Hr(){return[].slice.call(arguments).filter(Boolean).join(" ")}function Jr(r,n,e){for(var t=r,a=n.split(".");a.length&&void 0!==(t=t[a[0]]);)a.shift();return t||e}function Qr(r,n){var e=Jr(n,r);return e?"function"==typeof e||"object"==typeof e&&"render"in e?e:Jr(n,r+".component",r):r}function Wr(e,f){var G;void 0===e&&(e=""),void 0===f&&(f={}),f.overrides=f.overrides||{},f.namedCodesToUnicode=f.namedCodesToUnicode?n({},u,f.namedCodesToUnicode):u;var U=f.slugify||Rr,V=f.sanitizer||Pr,H=f.createElement||r.createElement,J=[l,v,m,f.enforceAtxHeadings?$:z,E,N,gr,kr],Q=[].concat(J,[T,R,A,M]);function er(r,n){for(var e=0;e<r.length;e++)if(r[e].test(n))return!0;return!1}function or(r,e){var t=Jr(f.overrides,r+".props",{});return H.apply(void 0,[Qr(r,f.overrides),n({},e,t,{className:Hr(null==e?void 0:e.className,t.className)||void 0})].concat([].slice.call(arguments,2)))}function ir(r){r=r.replace(q,"");var n=!1;f.forceInline?n=!0:f.forceBlock||(n=!1===F.test(r));for(var e=mr(vr(n?r:zr(r).replace(ar,"")+"\n\n",{inline:n}));Sr(e[e.length-1])&&!e[e.length-1].trim();)e.pop();if(null===f.wrapper)return e;var t,a=f.wrapper||(n?"span":"div");if(e.length>1||f.forceWrapper)t=e;else{if(1===e.length)return"string"==typeof(t=e[0])?or("span",{key:"outer"},t):t;t=null}return H(a,{key:"outer"},t)}function cr(r,n){if(!n||!n.trim())return null;var e=n.match(c);return e?e.reduce(function(n,e){var t=e.indexOf("=");if(-1!==t){var u=function(r){return-1!==r.indexOf("-")&&null===r.match(j)&&(r=r.replace(I,function(r,n){return n.toUpperCase()})),r}(e.slice(0,t)).trim(),o=function(r){var n=r[0];return('"'===n||"'"===n)&&r.length>=2&&r[r.length-1]===n?r.slice(1,-1):r}(e.slice(t+1).trim()),c=a[u]||u;if("ref"===c)return n;var f=n[c]=function(r,n,e,t){return"style"===n?function(r){var n=[],e="",t=!1,a=!1,u="";if(!r)return n;for(var o=0;o<r.length;o++){var i=r[o];if('"'!==i&&"'"!==i||t||(a?i===u&&(a=!1,u=""):(a=!0,u=i)),"("===i&&e.endsWith("url")?t=!0:")"===i&&t&&(t=!1),";"!==i||a||t)e+=i;else{var c=e.trim();if(c){var f=c.indexOf(":");if(f>0){var l=c.slice(0,f).trim(),s=c.slice(f+1).trim();n.push([l,s])}}e=""}}var _=e.trim();if(_){var d=_.indexOf(":");if(d>0){var p=_.slice(0,d).trim(),v=_.slice(d+1).trim();n.push([p,v])}}return n}(e).reduce(function(n,e){var a=e[0],u=e[1];return n[a.replace(/(-[a-z])/g,function(r){return r[1].toUpperCase()})]=t(u,r,a),n},{}):-1!==i.indexOf(n)?t(wr(e),r,n):(e.match(B)&&(e=wr(e.slice(1,e.length-1))),"true"===e||"false"!==e&&e)}(r,u,o,V);"string"==typeof f&&(R.test(f)||M.test(f))&&(n[c]=ir(f.trim()))}else"style"!==e&&(n[a[e]||e]=!0);return n},{}):null}var fr,lr,sr=[],_r={},dr=((G={})[t.blockQuote]={t:[">"],u:Ir(l),o:1,i:function(r,n,e){var t=r[0].replace(s,"").match(_);return{alert:t[1],children:n(t[2],e)}},l:function(r,n,e){var a={key:e.key};return r.alert&&(a.className="markdown-alert-"+U(r.alert.toLowerCase(),Rr),r.children.unshift({attrs:{},children:[{type:t.text,text:r.alert}],noInnerParse:!0,type:t.htmlBlock,tag:"header"})),or("blockquote",a,n(r.children,e))}},G[t.breakLine]={t:[" "],u:Nr(d),o:1,i:Ur,l:function(r,n,e){return or("br",{key:e.key})}},G[t.breakThematic]={t:["--","__","**","- ","* ","_ "],u:Ir(p),o:1,i:Ur,l:function(r,n,e){return or("hr",{key:e.key})}},G[t.codeBlock]={t:[" "],u:Ir(m),o:0,i:function(r){return{lang:void 0,text:wr(zr(r[0].replace(/^ {4}/gm,"")))}},l:function(r,e,t){return or("pre",{key:t.key},or("code",n({},r.attrs,{className:r.lang?"lang-"+r.lang:""}),r.text))}},G[t.codeFenced]={t:["```","~~~"],u:Ir(v),o:0,i:function(r){return{attrs:cr("code",r[3]||""),lang:r[2]||void 0,text:r[4],type:t.codeBlock}}},G[t.codeInline]={t:["`"],u:Cr(y),o:3,i:function(r){return{text:wr(r[2])}},l:function(r,n,e){return or("code",{key:e.key},r.text)}},G[t.footnote]={t:["[^"],u:Ir(k),o:0,i:function(r){return sr.push({footnote:r[2],identifier:r[1]}),{}},l:Vr},G[t.footnoteReference]={t:["[^"],u:Lr(x),o:1,i:function(r){return{target:"#"+U(r[1],Rr),text:r[1]}},l:function(r,n,e){return or("a",{key:e.key,href:V(r.target,"a","href")},or("sup",{key:e.key},r.text))}},G[t.gfmTask]={t:["[ ]","[x]"],u:Lr(S),o:1,i:function(r){return{completed:"x"===r[1].toLowerCase()}},l:function(r,n,e){return or("input",{checked:r.completed,key:e.key,readOnly:!0,type:"checkbox"})}},G[t.heading]={t:["#"],u:Ir(f.enforceAtxHeadings?$:z),o:1,i:function(r,n,e){return{children:Dr(n,r[2],e),id:U(r[2],Rr),level:r[1].length}},l:function(r,n,e){return or("h"+r.level,{id:r.id,key:e.key},n(r.children,e))}},G[t.headingSetext]={t:function(r){var n=r.indexOf("\n");return n>0&&n<r.length-1&&("="===r[n+1]||"-"===r[n+1])},u:Ir(E),o:1,i:function(r,n,e){return{children:Dr(n,r[1],e),level:"="===r[2]?1:2,type:t.heading}}},G[t.htmlBlock]={t:["<"],u:Nr(R),o:1,i:function(r,n,e){var t=r[3].match(ur),a=RegExp("^"+t[1],"gm"),u=r[3].replace(a,""),i=er(Q,u)?Zr:Dr,c=r[1].toLowerCase(),f=-1!==o.indexOf(c),l=(f?c:r[1]).trim(),s={attrs:cr(l,r[2]),noInnerParse:f,tag:l};if(e.inAnchor=e.inAnchor||"a"===c,f)s.text=r[3];else{var _=e.inHTML;e.inHTML=!0,s.children=i(n,u,e),e.inHTML=_}return e.inAnchor=!1,s},l:function(r,e,t){return or(r.tag,n({key:t.key},r.attrs),r.text||(r.children?e(r.children,t):""))}},G[t.htmlSelfClosing]={t:["<"],u:Nr(M),o:1,i:function(r){var n=r[1].trim();return{attrs:cr(n,r[2]||""),tag:n}},l:function(r,e,t){return or(r.tag,n({},r.attrs,{key:t.key}))}},G[t.htmlComment]={t:["\x3c!--"],u:Nr(A),o:1,i:function(){return{}},l:Vr},G[t.image]={t:["!["],u:Cr(qr),o:1,i:function(r){return{alt:wr(r[1]),target:wr(r[2]),title:wr(r[3])}},l:function(r,n,e){return or("img",{key:e.key,alt:r.alt||void 0,title:r.title||void 0,src:V(r.target,"img","src")})}},G[t.link]={t:["["],u:Lr(br),o:3,i:function(r,n,e){return{children:Fr(n,r[1],e),target:wr(r[2]),title:wr(r[3])}},l:function(r,n,e){return or("a",{key:e.key,href:V(r.target,"a","href"),title:r.title},n(r.children,e))}},G[t.linkAngleBraceStyleDetector]={t:["<"],u:Lr(C),o:0,i:function(r){var n=r[1],e=!1;return-1!==n.indexOf("@")&&-1===n.indexOf("//")&&(e=!0,n=n.replace("mailto:","")),{children:[{text:n,type:t.text}],target:e?"mailto:"+n:n,type:t.link}}},G[t.linkBareUrlDetector]={t:function(r,n){return!n.inAnchor&&!f.disableAutoLink&&($r(r,"http://")||$r(r,"https://"))},u:Lr(L),o:0,i:function(r){return{children:[{text:r[1],type:t.text}],target:r[1],title:void 0,type:t.link}}},G[t.orderedList]=xr(or,1),G[t.unorderedList]=xr(or,2),G[t.newlineCoalescer]={t:["\n"],u:Ir(h),o:3,i:Ur,l:function(){return"\n"}},G[t.paragraph]={u:Br(function(r,n){if(n.inline||n.simple||n.inHTML&&-1===r.indexOf("\n\n")&&-1===n.prevCapture.indexOf("\n\n"))return null;for(var e="",t=0;;){var a=r.indexOf("\n",t),u=r.slice(t,-1===a?void 0:a+1);if(er(J,u))break;if(e+=u,-1===a||!u.trim())break;t=a+1}var o=zr(e);return""===o?null:[e,,o]}),o:3,i:Gr,l:function(r,n,e){return or("p",{key:e.key},n(r.children,e))}},G[t.ref]={t:["["],u:Lr(P),o:0,i:function(r){return _r[r[1]]={target:r[2],title:r[4]},{}},l:Vr},G[t.refImage]={t:["!["],u:Cr(w),o:0,i:function(r){return{alt:r[1]?wr(r[1]):void 0,ref:r[2]}},l:function(r,n,e){return _r[r.ref]?or("img",{key:e.key,alt:r.alt,src:V(_r[r.ref].target,"img","src"),title:_r[r.ref].title}):null}},G[t.refLink]={t:function(r){return"["===r[0]&&-1===r.indexOf("](")},u:Lr(D),o:0,i:function(r,n,e){return{children:n(r[1],e),fallbackChildren:r[0],ref:r[2]}},l:function(r,n,e){return _r[r.ref]?or("a",{key:e.key,href:V(_r[r.ref].target,"a","href"),title:_r[r.ref].title},n(r.children,e)):or("span",{key:e.key},r.fallbackChildren)}},G[t.table]={t:["|"],u:Ir(N),o:1,i:jr,l:function(r,n,e){var t=r;return or("table",{key:e.key},or("thead",null,or("tr",null,t.header.map(function(r,a){return or("th",{key:a,style:Mr(t,a)},n(r,e))}))),or("tbody",null,t.cells.map(function(r,a){return or("tr",{key:a},r.map(function(r,a){return or("td",{key:a,style:Mr(t,a)},n(r,e))}))})))}},G[t.text]={u:Br(function(r,n){var e;return $r(r,":")&&(e=rr.exec(r)),e||tr.exec(r)}),o:4,i:function(r){var n=r[0];return{text:-1===n.indexOf("&")?n:n.replace(O,function(r,n){return f.namedCodesToUnicode[n]||r})}},l:function(r){return r.text}},G[t.textBolded]={t:["**","__"],u:Cr(W),o:2,i:function(r,n,e){return{children:n(r[2],e)}},l:function(r,n,e){return or("strong",{key:e.key},n(r.children,e))}},G[t.textEmphasized]={t:function(r){var n=r[0];return("*"===n||"_"===n)&&r[1]!==n},u:Cr(K),o:3,i:function(r,n,e){return{children:n(r[2],e)}},l:function(r,n,e){return or("em",{key:e.key},n(r.children,e))}},G[t.textEscaped]={t:["\\"],u:Cr(nr),o:1,i:function(r){return{text:r[1],type:t.text}}},G[t.textMarked]={t:["=="],u:Cr(X),o:3,i:Gr,l:function(r,n,e){return or("mark",{key:e.key},n(r.children,e))}},G[t.textStrikethroughed]={t:["~~"],u:Cr(Y),o:3,i:Gr,l:function(r,n,e){return or("del",{key:e.key},n(r.children,e))}},G),pr=!!process.env.DEBUG&&"0"!==process.env.DEBUG;pr&&(fr={match:{total:0,attempts:0},parse:{total:0}},lr={},Object.keys(t).forEach(function(r){lr[t[r]]=r}),Object.keys(dr).forEach(function(r){var n=dr[r],e=n.u,t=n.i;fr.match[r]=[0,0,0],fr.parse[r]=[0,0,0],dr[r].u=function(){var n,t=[].slice.call(arguments);fr.match.attempts++,fr.match[r][1]++;var a,u=performance.now(),o=e.apply(void 0,t),i=performance.now()-u;return fr.match[r][2]=Math.max(Number(fr.match[r][2])||0,i),o?(fr.match.total++,fr.match[r][0]++,null!=(a=process.env.DEBUG)&&a.includes("speed")&&console[i>5?"warn":"log"]((lr[r]||r)+":match",i.toFixed(3)+"ms",t[0])):null!=(n=process.env.DEBUG)&&n.includes("miss")&&console.log("\n"+(lr[r]||r)+":miss",JSON.stringify(t[0])),o},dr[r].i=function(){var n,e=[].slice.call(arguments);fr.parse.total++,fr.parse[r][0]+=1;var a=performance.now(),u=t.apply(void 0,e),o=performance.now()-a;return fr.parse[r][1]+=o,fr.parse[r][2]=Math.max(Number(fr.parse[r][2])||0,o),null!=(n=process.env.DEBUG)&&n.includes("speed")&&console[o>5?"warn":"log"]((lr[r]||r)+":parse",o.toFixed(3)+"ms",e[0]),u}})),!0===f.disableParsingRawHTML&&(delete dr[t.htmlBlock],delete dr[t.htmlSelfClosing]);var vr=function(r){var n=Object.keys(r);function e(t,a){var u=[];if(a.prevCapture=a.prevCapture||"",t.trim())for(;t;)for(var o=0;o<n.length;){var i=n[o],c=r[i];if(!c.t||Er(t,a,c.t)){var f=c.u(t,a);if(f&&f[0]){t=t.substring(f[0].length);var l=c.i(f,e,a);a.prevCapture+=f[0],l.type||(l.type=i),u.push(l);break}o++}else o++}return a.prevCapture="",u}return n.sort(function(n,e){return r[n].o-r[e].o||(n<e?-1:1)}),function(r,n){return e(function(r){return r.replace(g,"\n").replace(b,"").replace(Z," ")}(r),n)}}(dr),mr=function(r,n){return function e(t,a){if(void 0===a&&(a={}),Array.isArray(t)){for(var u=a.key,o=[],i=!1,c=0;c<t.length;c++){a.key=c;var f=e(t[c],a),l=Sr(f);l&&i?o[o.length-1]+=f:null!==f&&o.push(f),i=l}return a.key=u,o}return function(e,t,a){var u=r[e.type].l;return n?n(function(){return u(e,t,a)},e,t,a):u(e,t,a)}(t,e,a)}}(dr,f.renderRule),yr=ir(e);if(pr){var hr={total:fr.match.total,attempts:fr.match.attempts,missRatio:fr.match.attempts>0?((fr.match.attempts-fr.match.total)/fr.match.attempts*100).toFixed(1)+"%":"0%"},Or={total:fr.parse.total};Object.keys(fr.match).forEach(function(r){if("total"!==r&&"attempts"!==r){var n=fr.match[r],e=n[0],t=n[1],a=n[2];hr[lr[r]||r]={matches:e,attempts:t,missRatio:t>0?((t-e)/t*100).toFixed(1)+"%":"0%",max:a.toFixed(3)}}}),Object.keys(fr.parse).forEach(function(r){if("total"!==r){var n=fr.parse[r],e=n[2];Or[lr[r]||r]={executions:n[0],cost:n[1].toFixed(3),max:e.toFixed(3)}}}),console.log("Match invocations:",hr),console.log("Parse invocations:",Or)}return sr.length?or("div",null,yr,or("footer",{key:"footer"},sr.map(function(r){return or("div",{id:U(r.identifier,Rr),key:r.identifier},r.identifier,mr(vr(r.footnote,{inline:!0})))}))):yr}export default function(n){var t=n.children,a=void 0===t?"":t,u=n.options,o=function(r,n){if(null==r)return{};var e,t,a={},u=Object.keys(r);for(t=0;t<u.length;t++)n.indexOf(e=u[t])>=0||(a[e]=r[e]);return a}(n,e);return r.cloneElement(Wr(a,u),o)}export{t as RuleType,Wr as compiler,Pr as sanitizer,Rr as slugify};
1
+ import * as React from 'react';
2
+
3
+ function _extends() {
4
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
5
+ for (var e = 1; e < arguments.length; e++) {
6
+ var t = arguments[e];
7
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
8
+ }
9
+ return n;
10
+ }, _extends.apply(null, arguments);
11
+ }
12
+ function _objectWithoutPropertiesLoose(r, e) {
13
+ if (null == r) return {};
14
+ var t = {};
15
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
16
+ if (-1 !== e.indexOf(n)) continue;
17
+ t[n] = r[n];
18
+ }
19
+ return t;
20
+ }
21
+
22
+ /**
23
+ * Analogous to `node.type`. Please note that the values here may change at any time,
24
+ * so do not hard code against the value directly.
25
+ */
26
+ var RuleType$1 = {
27
+ blockQuote: '0',
28
+ breakLine: '1',
29
+ breakThematic: '2',
30
+ codeBlock: '3',
31
+ codeFenced: '4',
32
+ codeInline: '5',
33
+ footnote: '6',
34
+ footnoteReference: '7',
35
+ gfmTask: '8',
36
+ heading: '9',
37
+ headingSetext: '10',
38
+ htmlBlock: '11',
39
+ htmlComment: '12',
40
+ htmlSelfClosing: '13',
41
+ image: '14',
42
+ link: '15',
43
+ linkAngleBraceStyleDetector: '16',
44
+ linkBareUrlDetector: '17',
45
+ linkMailtoDetector: '18',
46
+ newlineCoalescer: '19',
47
+ orderedList: '20',
48
+ paragraph: '21',
49
+ ref: '22',
50
+ refImage: '23',
51
+ refLink: '24',
52
+ table: '25',
53
+ tableSeparator: '26',
54
+ text: '27',
55
+ textEscaped: '28',
56
+ textFormatted: '34',
57
+ unorderedList: '30'
58
+ };
59
+ var T = ['strong', 'em', 'del', 'mark'];
60
+ var DELS = [['**', T[0]], ['__', T[0]], ['~~', T[2]], ['==', T[3]], ['*', T[1]], ['_', T[1]]];
61
+ function skipLinkOrImage(source, pos) {
62
+ var bracketDepth = 1;
63
+ var i = pos + 1;
64
+ while (i < source.length && bracketDepth > 0) {
65
+ if (source[i] === '\\') {
66
+ i += 2;
67
+ continue;
68
+ }
69
+ if (source[i] === '[') bracketDepth++;
70
+ if (source[i] === ']') bracketDepth--;
71
+ i++;
72
+ }
73
+ if (bracketDepth === 0 && i < source.length && (source[i] === '(' || source[i] === '[')) {
74
+ var closingChar = source[i] === '(' ? ')' : ']';
75
+ var parenDepth = 1;
76
+ i++;
77
+ while (i < source.length && parenDepth > 0) {
78
+ if (source[i] === '\\') {
79
+ i += 2;
80
+ continue;
81
+ }
82
+ if (source[i] === '(' && closingChar === ')') parenDepth++;
83
+ if (source[i] === closingChar) parenDepth--;
84
+ i++;
85
+ }
86
+ if (parenDepth === 0) return i;
87
+ }
88
+ return -1;
89
+ }
90
+ function matchInlineFormatting(source, state) {
91
+ if (!state || !state.inline && !state.simple) return null;
92
+ var c = source[0];
93
+ if (c !== '*' && c !== '_' && c !== '~' && c !== '=') return null;
94
+ var delimiter = '';
95
+ var startLength = 0;
96
+ var tag = '';
97
+ for (var i = 0; i < 6; i++) {
98
+ var d = DELS[i][0];
99
+ if (source.startsWith(d) && source.length >= d.length * 2) {
100
+ delimiter = d;
101
+ startLength = d.length;
102
+ tag = DELS[i][1];
103
+ break;
104
+ }
105
+ }
106
+ if (!delimiter) return null;
107
+ var pos = startLength;
108
+ var inCode = false;
109
+ var inHTMLTag = false;
110
+ var inHTMLQuote = '';
111
+ var htmlDepth = 0;
112
+ var content = '';
113
+ var lastWasEscape = false;
114
+ var lastChar = '';
115
+ while (pos < source.length) {
116
+ var _char = source[pos];
117
+ if (lastWasEscape) {
118
+ content += _char;
119
+ lastWasEscape = false;
120
+ lastChar = _char;
121
+ pos++;
122
+ continue;
123
+ }
124
+ if (_char === '\\') {
125
+ content += _char;
126
+ lastWasEscape = true;
127
+ lastChar = _char;
128
+ pos++;
129
+ continue;
130
+ }
131
+ if (_char === '`' && htmlDepth === 0) {
132
+ inCode = !inCode;
133
+ content += _char;
134
+ lastChar = _char;
135
+ pos++;
136
+ continue;
137
+ }
138
+ if (_char === '[' && !inCode && htmlDepth === 0) {
139
+ var linkEnd = skipLinkOrImage(source, pos);
140
+ if (linkEnd !== -1) {
141
+ content += source.slice(pos, linkEnd);
142
+ pos = linkEnd;
143
+ lastChar = source[linkEnd - 1];
144
+ continue;
145
+ }
146
+ }
147
+ if (inHTMLTag) {
148
+ content += _char;
149
+ if (inHTMLQuote) {
150
+ if (_char === inHTMLQuote) inHTMLQuote = '';
151
+ } else if (_char === '"' || _char === "'") {
152
+ inHTMLQuote = _char;
153
+ } else if (_char === '>') {
154
+ inHTMLTag = false;
155
+ }
156
+ lastChar = _char;
157
+ pos++;
158
+ continue;
159
+ }
160
+ if (_char === '<' && !inCode) {
161
+ var nextChar = source[pos + 1];
162
+ var tagEnd = source.indexOf('>', pos);
163
+ if (tagEnd !== -1) {
164
+ var tagContent = source.slice(pos, tagEnd + 1);
165
+ var isSelfClosing = tagContent.endsWith('/>');
166
+ if (nextChar === '/') {
167
+ htmlDepth = Math.max(0, htmlDepth - 1);
168
+ } else if (!isSelfClosing) {
169
+ htmlDepth++;
170
+ }
171
+ }
172
+ inHTMLTag = true;
173
+ content += _char;
174
+ lastChar = _char;
175
+ pos++;
176
+ continue;
177
+ }
178
+ if (_char === '\n' && lastChar === '\n' && !inCode && htmlDepth === 0) {
179
+ return null;
180
+ }
181
+ if (!inCode && htmlDepth === 0) {
182
+ var delimiterRunLength = 0;
183
+ while (pos + delimiterRunLength < source.length && source[pos + delimiterRunLength] === delimiter[0]) {
184
+ delimiterRunLength++;
185
+ }
186
+ if (delimiterRunLength >= startLength) {
187
+ if (startLength !== 1 || delimiter !== '*' && delimiter !== '_' || source[pos - 1] !== delimiter && source[pos + 1] !== delimiter) {
188
+ var result = [source.slice(0, pos + delimiterRunLength), tag, content + source.slice(pos + startLength, pos + delimiterRunLength)];
189
+ result.index = 0;
190
+ result.input = source;
191
+ return result;
192
+ }
193
+ }
194
+ }
195
+ content += _char;
196
+ lastChar = _char;
197
+ pos++;
198
+ }
199
+ return null;
200
+ }
201
+
202
+ var _excluded = ["children", "options"];
203
+ var RuleType = RuleType$1;
204
+ var Priority = {
205
+ /**
206
+ * anything that must scan the tree before everything else
207
+ */
208
+ MAX: 0,
209
+ /**
210
+ * scans for block-level constructs
211
+ */
212
+ HIGH: 1,
213
+ /**
214
+ * inline w/ more priority than other inline
215
+ */
216
+ MED: 2,
217
+ /**
218
+ * inline elements
219
+ */
220
+ LOW: 3,
221
+ /**
222
+ * bare text and stuff that is considered leftovers
223
+ */
224
+ MIN: 4
225
+ };
226
+ /** TODO: Drop for React 16? */
227
+ var ATTRIBUTE_TO_JSX_PROP_MAP = ['allowFullScreen', 'allowTransparency', 'autoComplete', 'autoFocus', 'autoPlay', 'cellPadding', 'cellSpacing', 'charSet', 'classId', 'colSpan', 'contentEditable', 'contextMenu', 'crossOrigin', 'encType', 'formAction', 'formEncType', 'formMethod', 'formNoValidate', 'formTarget', 'frameBorder', 'hrefLang', 'inputMode', 'keyParams', 'keyType', 'marginHeight', 'marginWidth', 'maxLength', 'mediaGroup', 'minLength', 'noValidate', 'radioGroup', 'readOnly', 'rowSpan', 'spellCheck', 'srcDoc', 'srcLang', 'srcSet', 'tabIndex', 'useMap'].reduce(function (obj, x) {
228
+ obj[x.toLowerCase()] = x;
229
+ return obj;
230
+ }, {
231
+ "class": 'className',
232
+ "for": 'htmlFor'
233
+ });
234
+ var namedCodesToUnicode = {
235
+ amp: "&",
236
+ apos: "'",
237
+ gt: ">",
238
+ lt: "<",
239
+ nbsp: "\xA0",
240
+ quot: "\u201C"
241
+ };
242
+ var DO_NOT_PROCESS_HTML_ELEMENTS = ['style', 'script', 'pre'];
243
+ var ATTRIBUTES_TO_SANITIZE = ['src', 'href', 'data', 'formAction', 'srcDoc', 'action'];
244
+ /**
245
+ * the attribute extractor regex looks for a valid attribute name,
246
+ * followed by an equal sign (whitespace around the equal sign is allowed), followed
247
+ * by one of the following:
248
+ *
249
+ * 1. a single quote-bounded string, e.g. 'foo'
250
+ * 2. a double quote-bounded string, e.g. "bar"
251
+ * 3. an interpolation, e.g. {something}
252
+ *
253
+ * JSX can be be interpolated into itself and is passed through the compiler using
254
+ * the same options and setup as the current run.
255
+ *
256
+ * <Something children={<SomeOtherThing />} />
257
+ * ==================
258
+ * ↳ children: [<SomeOtherThing />]
259
+ *
260
+ * Otherwise, interpolations are handled as strings or simple booleans
261
+ * unless HTML syntax is detected.
262
+ *
263
+ * <Something color={green} disabled={true} />
264
+ * ===== ====
265
+ * ↓ ↳ disabled: true
266
+ * ↳ color: "green"
267
+ *
268
+ * Numbers are not parsed at this time due to complexities around int, float,
269
+ * and the upcoming bigint functionality that would make handling it unwieldy.
270
+ * Parse the string in your component as desired.
271
+ *
272
+ * <Something someBigNumber={123456789123456789} />
273
+ * ==================
274
+ * ↳ someBigNumber: "123456789123456789"
275
+ */
276
+ var ATTR_EXTRACTOR_R = /([-A-Z0-9_:]+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|(?:\{((?:\\.|{[^}]*?}|[^}])*)\})))?/gi;
277
+ /** TODO: Write explainers for each of these */
278
+ var BLOCK_END_R = /\n{2,}$/;
279
+ var BLOCKQUOTE_R = /^(\s*>[\s\S]*?)(?=\n\n|$)/;
280
+ var BLOCKQUOTE_TRIM_LEFT_MULTILINE_R = /^ *> ?/gm;
281
+ var BLOCKQUOTE_ALERT_R = /^(?:\[!([^\]]*)\]\n)?([\s\S]*)/;
282
+ var BREAK_LINE_R = /^ {2,}\n/;
283
+ var BREAK_THEMATIC_R = /^(?:([-*_])( *\1){2,}) *(?:\n *)+\n/;
284
+ var CODE_BLOCK_FENCED_R = /^(?: {1,3})?(`{3,}|~{3,}) *(\S+)? *([^\n]*?)?\n([\s\S]*?)(?:\1\n?|$)/;
285
+ var CODE_BLOCK_R = /^(?: {4}[^\n]+\n*)+(?:\n *)+\n?/;
286
+ var CODE_INLINE_R = /^(`+)((?:\\`|(?!\1)`|[^`])+)\1/;
287
+ var CONSECUTIVE_NEWLINE_R = /^(?:\n *)*\n/;
288
+ var CR_NEWLINE_R = /\r\n?/g;
289
+ /**
290
+ * Matches footnotes on the format:
291
+ *
292
+ * [^key]: value
293
+ *
294
+ * Matches multiline footnotes
295
+ *
296
+ * [^key]: row
297
+ * row
298
+ * row
299
+ *
300
+ * And empty lines in indented multiline footnotes
301
+ *
302
+ * [^key]: indented with
303
+ * row
304
+ *
305
+ * row
306
+ *
307
+ * Explanation:
308
+ *
309
+ * 1. Look for the starting tag, eg: [^key]
310
+ * ^\[\^([^\]]+)]
311
+ *
312
+ * 2. The first line starts with a colon, and continues for the rest of the line
313
+ * :(.*)
314
+ *
315
+ * 3. Parse as many additional lines as possible. Matches new non-empty lines that doesn't begin with a new footnote definition.
316
+ * (\n(?!\[\^).+)
317
+ *
318
+ * 4. ...or allows for repeated newlines if the next line begins with at least four whitespaces.
319
+ * (\n+ {4,}.*)
320
+ */
321
+ var FOOTNOTE_R = /^\[\^([^\]]+)](:(.*)((\n+ {4,}.*)|(\n(?!\[\^).+))*)/;
322
+ var FOOTNOTE_REFERENCE_R = /^\[\^([^\]]+)]/;
323
+ var FORMFEED_R = /\f/g;
324
+ var FRONT_MATTER_R = /^---[ \t]*\n(.|\n)*\n---[ \t]*\n/;
325
+ var GFM_TASK_R = /^\[(x|\s)\]/;
326
+ var HEADING_R = /^(#{1,6}) *([^\n]+?)(?: +#*)?(?:\n *)*(?:\n|$)/;
327
+ var HEADING_ATX_COMPLIANT_R = /^ *(#{1,6}) +([^\n]+?)(?: +#*)?(?:\n *)*(?:\n|$)/;
328
+ var HEADING_SETEXT_R = /^([^\n]+)\n *(=|-)\2{2,} *\n/;
329
+ var HTML_BLOCK_ELEMENT_START_R = /^<([a-z][^ >/]*) ?((?:[^>]*[^/])?)>/i;
330
+ function matchHTMLBlock(source) {
331
+ var m = HTML_BLOCK_ELEMENT_START_R.exec(source);
332
+ if (!m) return null;
333
+ var tagName = m[1];
334
+ var tagLower = tagName.toLowerCase();
335
+ var openTagLen = tagLower.length + 1;
336
+ var pos = m[0].length;
337
+ if (source[pos] === '\n') pos++;
338
+ var contentStart = pos;
339
+ var contentEnd = pos;
340
+ var depth = 1;
341
+ var sourceLen = source.length;
342
+ while (depth > 0) {
343
+ var idx = source.indexOf('<', pos);
344
+ if (idx === -1) return null;
345
+ var openIdx = -1;
346
+ var closeIdx = -1;
347
+ if (source[idx + 1] === '/') {
348
+ closeIdx = idx;
349
+ } else if (source[idx + 1] === tagLower[0] || source[idx + 1] === tagName[0]) {
350
+ var match = true;
351
+ for (var i = 0; i < tagLower.length; i++) {
352
+ var c = source[idx + 1 + i];
353
+ if (c !== tagLower[i] && c !== tagName[i]) {
354
+ match = false;
355
+ break;
356
+ }
357
+ }
358
+ if (match && (source[idx + openTagLen] === ' ' || source[idx + openTagLen] === '>')) {
359
+ openIdx = idx;
360
+ }
361
+ }
362
+ if (openIdx === -1 && closeIdx === -1) {
363
+ pos = idx + 1;
364
+ continue;
365
+ }
366
+ if (openIdx !== -1 && (closeIdx === -1 || openIdx < closeIdx)) {
367
+ pos = openIdx + openTagLen + 1;
368
+ depth++;
369
+ } else {
370
+ var p = closeIdx + 2;
371
+ while (p < sourceLen) {
372
+ var _c = source[p];
373
+ if (_c !== ' ' && _c !== '\t' && _c !== '\n' && _c !== '\r') break;
374
+ p++;
375
+ }
376
+ if (p + tagLower.length > sourceLen) return null;
377
+ var _match = true;
378
+ for (var _i = 0; _i < tagLower.length; _i++) {
379
+ var _c2 = source[p + _i];
380
+ if (_c2 !== tagLower[_i] && _c2 !== tagName[_i]) {
381
+ _match = false;
382
+ break;
383
+ }
384
+ }
385
+ if (!_match) {
386
+ pos = p;
387
+ continue;
388
+ }
389
+ p += tagLower.length;
390
+ while (p < sourceLen) {
391
+ var _c3 = source[p];
392
+ if (_c3 !== ' ' && _c3 !== '\t' && _c3 !== '\n' && _c3 !== '\r') break;
393
+ p++;
394
+ }
395
+ if (p >= sourceLen || source[p] !== '>') {
396
+ pos = p;
397
+ continue;
398
+ }
399
+ contentEnd = closeIdx;
400
+ pos = p + 1;
401
+ depth--;
402
+ }
403
+ }
404
+ var trailingNl = 0;
405
+ while (pos + trailingNl < sourceLen && source[pos + trailingNl] === '\n') trailingNl++;
406
+ return [source.slice(0, pos + trailingNl), tagName, m[2], source.slice(contentStart, contentEnd)];
407
+ }
408
+ var HTML_CHAR_CODE_R = /&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-fA-F]{1,6});/gi;
409
+ var HTML_COMMENT_R = /^<!--[\s\S]*?(?:-->)/;
410
+ /**
411
+ * borrowed from React 15(https://github.com/facebook/react/blob/894d20744cba99383ffd847dbd5b6e0800355a5c/src/renderers/dom/shared/HTMLDOMPropertyConfig.js)
412
+ */
413
+ var HTML_CUSTOM_ATTR_R = /^(data|aria|x)-[a-z_][a-z\d_.-]*$/;
414
+ var HTML_SELF_CLOSING_ELEMENT_R = /^ *<([a-z][a-z0-9:]*)(?:\s+((?:<.*?>|[^>])*))?\/?>(?!<\/\1>)(\s*\n)?/i;
415
+ var INTERPOLATION_R = /^\{.*\}$/;
416
+ var LINK_AUTOLINK_BARE_URL_R = /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/;
417
+ var LINK_AUTOLINK_R = /^<([^ >]+[:@\/][^ >]+)>/;
418
+ var CAPTURE_LETTER_AFTER_HYPHEN = /-([a-z])?/gi;
419
+ var NP_TABLE_R = /^(\|.*)\n(?: *(\|? *[-:]+ *\|[-| :]*)\n((?:.*\|.*\n)*))?\n?/;
420
+ var PARAGRAPH_R = /^[^\n]+(?: \n|\n{2,})/;
421
+ var REFERENCE_IMAGE_OR_LINK = /^\[([^\]]*)\]:\s+<?([^\s>]+)>?\s*("([^"]*)")?/;
422
+ var REFERENCE_IMAGE_R = /^!\[([^\]]*)\] ?\[([^\]]*)\]/;
423
+ var REFERENCE_LINK_R = /^\[([^\]]*)\] ?\[([^\]]*)\]/;
424
+ var SHOULD_RENDER_AS_BLOCK_R = /(\n|^[-*]\s|^#|^ {2,}|^-{2,}|^>\s)/;
425
+ var TAB_R = /\t/g;
426
+ var TABLE_TRIM_PIPES = /(^ *\||\| *$)/g;
427
+ var TABLE_CENTER_ALIGN = /^ *:-+: *$/;
428
+ var TABLE_LEFT_ALIGN = /^ *:-+ *$/;
429
+ var TABLE_RIGHT_ALIGN = /^ *-+: *$/;
430
+ /**
431
+ * Special case for shortcodes like :big-smile: or :emoji:
432
+ */
433
+ var SHORTCODE_R = /^(:[a-zA-Z0-9-_]+:)/;
434
+ var TEXT_ESCAPED_R = /^\\([^0-9A-Za-z\s])/;
435
+ var UNESCAPE_R = /\\([^0-9A-Za-z\s])/g;
436
+ /**
437
+ * Always take the first character, then eagerly take text until a double space
438
+ * (potential line break) or some markdown-like punctuation is reached.
439
+ */
440
+ var TEXT_PLAIN_R = /^[\s\S](?:(?! \n|[0-9]\.|http)[^=*_~\-\n:<`\\\[!])*/;
441
+ var TRIM_STARTING_NEWLINES = /^\n+/;
442
+ var HTML_LEFT_TRIM_AMOUNT_R = /^([ \t]*)/;
443
+ var ORDERED = 1;
444
+ var UNORDERED = 2;
445
+ var LIST_LOOKBEHIND_R = /(?:^|\n)( *)$/;
446
+ // recognize a `*` `-`, `+`, `1.`, `2.`... list bullet
447
+ var ORDERED_LIST_BULLET = '(?:\\d+\\.)';
448
+ var UNORDERED_LIST_BULLET = '(?:[*+-])';
449
+ function generateListItemPrefix(type) {
450
+ return '( *)(' + (type === ORDERED ? ORDERED_LIST_BULLET : UNORDERED_LIST_BULLET) + ') +';
451
+ }
452
+ // recognize the start of a list item:
453
+ // leading space plus a bullet plus a space (` * `)
454
+ var ORDERED_LIST_ITEM_PREFIX = generateListItemPrefix(ORDERED);
455
+ var UNORDERED_LIST_ITEM_PREFIX = generateListItemPrefix(UNORDERED);
456
+ function generateListItemPrefixRegex(type) {
457
+ return new RegExp('^' + (type === ORDERED ? ORDERED_LIST_ITEM_PREFIX : UNORDERED_LIST_ITEM_PREFIX));
458
+ }
459
+ var ORDERED_LIST_ITEM_PREFIX_R = generateListItemPrefixRegex(ORDERED);
460
+ var UNORDERED_LIST_ITEM_PREFIX_R = generateListItemPrefixRegex(UNORDERED);
461
+ function generateListItemRegex(type) {
462
+ // recognize an individual list item:
463
+ // * hi
464
+ // this is part of the same item
465
+ //
466
+ // as is this, which is a new paragraph in the same item
467
+ //
468
+ // * but this is not part of the same item
469
+ return new RegExp('^' + (type === ORDERED ? ORDERED_LIST_ITEM_PREFIX : UNORDERED_LIST_ITEM_PREFIX) + '[^\\n]*(?:\\n' + '(?!\\1' + (type === ORDERED ? ORDERED_LIST_BULLET : UNORDERED_LIST_BULLET) + ' )[^\\n]*)*(\\n|$)', 'gm');
470
+ }
471
+ var ORDERED_LIST_ITEM_R = generateListItemRegex(ORDERED);
472
+ var UNORDERED_LIST_ITEM_R = generateListItemRegex(UNORDERED);
473
+ // check whether a list item has paragraphs: if it does,
474
+ // we leave the newlines at the end
475
+ function generateListRegex(type) {
476
+ var bullet = type === ORDERED ? ORDERED_LIST_BULLET : UNORDERED_LIST_BULLET;
477
+ return new RegExp('^( *)(' + bullet + ') ' + '[\\s\\S]+?(?:\\n{2,}(?! )' + '(?!\\1' + bullet + ' (?!' + bullet + ' ))\\n*' +
478
+ // the \\s*$ here is so that we can parse the inside of nested
479
+ // lists, where our content might end before we receive two `\n`s
480
+ '|\\s*\\n*$)');
481
+ }
482
+ var ORDERED_LIST_R = generateListRegex(ORDERED);
483
+ var UNORDERED_LIST_R = generateListRegex(UNORDERED);
484
+ function generateListRule(h, type) {
485
+ var ordered = type === ORDERED;
486
+ var LIST_R = ordered ? ORDERED_LIST_R : UNORDERED_LIST_R;
487
+ var LIST_ITEM_R = ordered ? ORDERED_LIST_ITEM_R : UNORDERED_LIST_ITEM_R;
488
+ var LIST_ITEM_PREFIX_R = ordered ? ORDERED_LIST_ITEM_PREFIX_R : UNORDERED_LIST_ITEM_PREFIX_R;
489
+ return {
490
+ _qualify: function _qualify(source) {
491
+ return LIST_ITEM_PREFIX_R.test(source);
492
+ },
493
+ _match: allowInline(function (source, state) {
494
+ // We only want to break into a list if we are at the start of a
495
+ // line. This is to avoid parsing "hi * there" with "* there"
496
+ // becoming a part of a list.
497
+ // You might wonder, "but that's inline, so of course it wouldn't
498
+ // start a list?". You would be correct! Except that some of our
499
+ // lists can be inline, because they might be inside another list,
500
+ // in which case we can parse with inline scope, but need to allow
501
+ // nested lists inside this inline scope.
502
+ var isStartOfLine = LIST_LOOKBEHIND_R.exec(state.prevCapture);
503
+ var isListAllowed = state.list || !state.inline && !state.simple;
504
+ if (isStartOfLine && isListAllowed) {
505
+ source = isStartOfLine[1] + source;
506
+ return LIST_R.exec(source);
507
+ } else {
508
+ return null;
509
+ }
510
+ }),
511
+ _order: Priority.HIGH,
512
+ _parse: function _parse(capture, parse, state) {
513
+ var bullet = capture[2];
514
+ var start = ordered ? +bullet : undefined;
515
+ var items = capture[0]
516
+ // recognize the end of a paragraph block inside a list item:
517
+ // two or more newlines at end end of the item
518
+ .replace(BLOCK_END_R, '\n').match(LIST_ITEM_R);
519
+ var firstPrefixMatch = LIST_ITEM_PREFIX_R.exec(items[0]);
520
+ var space = firstPrefixMatch ? firstPrefixMatch[0].length : 0;
521
+ var spaceRegex = new RegExp('^ {1,' + space + '}', 'gm');
522
+ var lastItemWasAParagraph = false;
523
+ var itemContent = items.map(function (item, i) {
524
+ // Before processing the item, we need a couple things
525
+ var content = item
526
+ // remove indents on trailing lines:
527
+ .replace(spaceRegex, '')
528
+ // remove the bullet:
529
+ .replace(LIST_ITEM_PREFIX_R, '');
530
+ // Handling "loose" lists, like:
531
+ //
532
+ // * this is wrapped in a paragraph
533
+ //
534
+ // * as is this
535
+ //
536
+ // * as is this
537
+ var isLastItem = i === items.length - 1;
538
+ var containsBlocks = includes(content, '\n\n');
539
+ // Any element in a list is a block if it contains multiple
540
+ // newlines. The last element in the list can also be a block
541
+ // if the previous item in the list was a block (this is
542
+ // because non-last items in the list can end with \n\n, but
543
+ // the last item can't, so we just "inherit" this property
544
+ // from our previous element).
545
+ var thisItemIsAParagraph = containsBlocks || isLastItem && lastItemWasAParagraph;
546
+ lastItemWasAParagraph = thisItemIsAParagraph;
547
+ // backup our state for delta afterwards. We're going to
548
+ // want to set state.list to true, and state.inline depending
549
+ // on our list's looseness.
550
+ var oldStateInline = state.inline;
551
+ var oldStateList = state.list;
552
+ state.list = true;
553
+ // Parse inline if we're in a tight list, or block if we're in
554
+ // a loose list.
555
+ var adjustedContent;
556
+ if (thisItemIsAParagraph) {
557
+ state.inline = false;
558
+ adjustedContent = trimEnd(content) + '\n\n';
559
+ } else {
560
+ state.inline = true;
561
+ adjustedContent = trimEnd(content);
562
+ }
563
+ var result = parse(adjustedContent, state);
564
+ // Restore our state before returning
565
+ state.inline = oldStateInline;
566
+ state.list = oldStateList;
567
+ return result;
568
+ });
569
+ return {
570
+ items: itemContent,
571
+ ordered: ordered,
572
+ start: start
573
+ };
574
+ }
575
+ };
576
+ }
577
+ var LINK_INSIDE = '(?:\\[[^\\[\\]]*(?:\\[[^\\[\\]]*\\][^\\[\\]]*)*\\]|[^\\[\\]])*';
578
+ var LINK_HREF_AND_TITLE = '\\s*<?((?:\\([^)]*\\)|[^\\s\\\\]|\\\\.)*?)>?(?:\\s+[\'"]([\\s\\S]*?)[\'"])?\\s*';
579
+ var LINK_R = new RegExp('^\\[(' + LINK_INSIDE + ')\\]\\(' + LINK_HREF_AND_TITLE + '\\)');
580
+ var IMAGE_R = /^!\[(.*?)\]\( *((?:\([^)]*\)|[^() ])*) *"?([^)"]*)?"?\)/;
581
+ function isString(value) {
582
+ return typeof value === 'string';
583
+ }
584
+ function trimEnd(str) {
585
+ var end = str.length;
586
+ while (end > 0 && str[end - 1] <= ' ') end--;
587
+ return str.slice(0, end);
588
+ }
589
+ function startsWith(str, prefix) {
590
+ return str.startsWith(prefix);
591
+ }
592
+ function includes(str, search) {
593
+ return str.indexOf(search) !== -1;
594
+ }
595
+ function qualifies(source, state, qualify) {
596
+ if (Array.isArray(qualify)) {
597
+ for (var i = 0; i < qualify.length; i++) {
598
+ if (startsWith(source, qualify[i])) return true;
599
+ }
600
+ return false;
601
+ }
602
+ return qualify(source, state);
603
+ }
604
+ /** Remove symmetrical leading and trailing quotes */
605
+ function unquote(str) {
606
+ var first = str[0];
607
+ if ((first === '"' || first === "'") && str.length >= 2 && str[str.length - 1] === first) {
608
+ return str.slice(1, -1);
609
+ }
610
+ return str;
611
+ }
612
+ // based on https://stackoverflow.com/a/18123682/1141611
613
+ // not complete, but probably good enough
614
+ function slugify(str) {
615
+ return str.replace(/[ÀÁÂÃÄÅàáâãä忯]/g, 'a').replace(/[çÇ]/g, 'c').replace(/[ðÐ]/g, 'd').replace(/[ÈÉÊËéèêë]/g, 'e').replace(/[ÏïÎîÍíÌì]/g, 'i').replace(/[Ññ]/g, 'n').replace(/[øØœŒÕõÔôÓóÒò]/g, 'o').replace(/[ÜüÛûÚúÙù]/g, 'u').replace(/[ŸÿÝý]/g, 'y').replace(/[^a-z0-9- ]/gi, '').replace(/ /gi, '-').toLowerCase();
616
+ }
617
+ function parseTableAlignCapture(alignCapture) {
618
+ if (TABLE_RIGHT_ALIGN.test(alignCapture)) {
619
+ return 'right';
620
+ } else if (TABLE_CENTER_ALIGN.test(alignCapture)) {
621
+ return 'center';
622
+ } else if (TABLE_LEFT_ALIGN.test(alignCapture)) {
623
+ return 'left';
624
+ }
625
+ return null;
626
+ }
627
+ function parseTableRow(source, parse, state, tableOutput) {
628
+ var prevInTable = state.inTable;
629
+ state.inTable = true;
630
+ var cells = [[]];
631
+ var acc = '';
632
+ function flush() {
633
+ if (!acc) return;
634
+ var cell = cells[cells.length - 1];
635
+ cell.push.apply(cell, parse(acc, state));
636
+ acc = '';
637
+ }
638
+ source.trim()
639
+ // isolate situations where a pipe should be ignored (inline code, escaped, etc)
640
+ .split(/(`[^`]*`|\\\||\|)/).filter(Boolean).forEach(function (fragment, i, arr) {
641
+ if (fragment.trim() === '|') {
642
+ flush();
643
+ if (tableOutput) {
644
+ if (i !== 0 && i !== arr.length - 1) {
645
+ // Split the current row
646
+ cells.push([]);
647
+ }
648
+ return;
649
+ }
650
+ }
651
+ acc += fragment;
652
+ });
653
+ flush();
654
+ state.inTable = prevInTable;
655
+ return cells;
656
+ }
657
+ function parseTableAlign(source /*, parse, state*/) {
658
+ var alignText = source.replace(TABLE_TRIM_PIPES, '').split('|');
659
+ return alignText.map(parseTableAlignCapture);
660
+ }
661
+ function parseTableCells(source, parse, state) {
662
+ var rowsText = source.trim().split('\n');
663
+ return rowsText.map(function (rowText) {
664
+ return parseTableRow(rowText, parse, state, true);
665
+ });
666
+ }
667
+ function parseTable(capture, parse, state) {
668
+ /**
669
+ * The table syntax makes some other parsing angry so as a bit of a hack even if alignment and/or cell rows are missing,
670
+ * we'll still run a detected first row through the parser and then just emit a paragraph.
671
+ */
672
+ state.inline = true;
673
+ var align = capture[2] ? parseTableAlign(capture[2]) : [];
674
+ var cells = capture[3] ? parseTableCells(capture[3], parse, state) : [];
675
+ var header = parseTableRow(capture[1], parse, state, !!cells.length);
676
+ state.inline = false;
677
+ return cells.length ? {
678
+ align: align,
679
+ cells: cells,
680
+ header: header,
681
+ type: RuleType.table
682
+ } : {
683
+ children: header,
684
+ type: RuleType.paragraph
685
+ };
686
+ }
687
+ function getTableStyle(node, colIndex) {
688
+ return node.align[colIndex] == null ? {} : {
689
+ textAlign: node.align[colIndex]
690
+ };
691
+ }
692
+ /** TODO: remove for react 16 */
693
+ function normalizeAttributeKey(key) {
694
+ var hyphenIndex = key.indexOf('-');
695
+ if (hyphenIndex !== -1 && key.match(HTML_CUSTOM_ATTR_R) === null) {
696
+ key = key.replace(CAPTURE_LETTER_AFTER_HYPHEN, function (_, letter) {
697
+ return letter.toUpperCase();
698
+ });
699
+ }
700
+ return key;
701
+ }
702
+ function parseStyleAttribute(styleString) {
703
+ var styles = [];
704
+ if (!styleString) return styles;
705
+ var buffer = '';
706
+ var depth = 0;
707
+ var quoteChar = '';
708
+ for (var i = 0; i < styleString.length; i++) {
709
+ var _char = styleString[i];
710
+ if (_char === '"' || _char === "'") {
711
+ if (!quoteChar) {
712
+ quoteChar = _char;
713
+ depth++;
714
+ } else if (_char === quoteChar) {
715
+ quoteChar = '';
716
+ depth--;
717
+ }
718
+ } else if (_char === '(' && buffer.endsWith('url')) {
719
+ depth++;
720
+ } else if (_char === ')' && depth > 0) {
721
+ depth--;
722
+ } else if (_char === ';' && depth === 0) {
723
+ var _colonIndex = buffer.indexOf(':');
724
+ if (_colonIndex > 0) {
725
+ styles.push([buffer.slice(0, _colonIndex).trim(), buffer.slice(_colonIndex + 1).trim()]);
726
+ }
727
+ buffer = '';
728
+ continue;
729
+ }
730
+ buffer += _char;
731
+ }
732
+ var colonIndex = buffer.indexOf(':');
733
+ if (colonIndex > 0) {
734
+ styles.push([buffer.slice(0, colonIndex).trim(), buffer.slice(colonIndex + 1).trim()]);
735
+ }
736
+ return styles;
737
+ }
738
+ function attributeValueToJSXPropValue(tag, key, value, sanitizeUrlFn) {
739
+ if (key === 'style') {
740
+ return parseStyleAttribute(value).reduce(function (styles, _ref) {
741
+ var key = _ref[0],
742
+ value = _ref[1];
743
+ styles[key.replace(/(-[a-z])/g, function (substr) {
744
+ return substr[1].toUpperCase();
745
+ })] = sanitizeUrlFn(value, tag, key);
746
+ return styles;
747
+ }, {});
748
+ }
749
+ if (ATTRIBUTES_TO_SANITIZE.indexOf(key) !== -1) {
750
+ return sanitizeUrlFn(unescape(value), tag, key);
751
+ }
752
+ if (value.match(INTERPOLATION_R)) {
753
+ value = unescape(value.slice(1, value.length - 1));
754
+ }
755
+ return value === 'true' ? true : value === 'false' ? false : value;
756
+ }
757
+ function normalizeWhitespace(source) {
758
+ return source.replace(CR_NEWLINE_R, '\n').replace(FORMFEED_R, '').replace(TAB_R, ' ');
759
+ }
760
+ /**
761
+ * Creates a parser for a given set of rules, with the precedence
762
+ * specified as a list of rules.
763
+ *
764
+ * @rules: an object containing
765
+ * rule type -> {match, order, parse} objects
766
+ * (lower order is higher precedence)
767
+ * (Note: `order` is added to defaultRules after creation so that
768
+ * the `order` of defaultRules in the source matches the `order`
769
+ * of defaultRules in terms of `order` fields.)
770
+ *
771
+ * @returns The resulting parse function, with the following parameters:
772
+ * @source: the input source string to be parsed
773
+ * @state: an optional object to be threaded through parse
774
+ * calls. Allows clients to add stateful operations to
775
+ * parsing, such as keeping track of how many levels deep
776
+ * some nesting is. For an example use-case, see passage-ref
777
+ * parsing in src/widgets/passage/passage-markdown.jsx
778
+ */
779
+ function parserFor(rules) {
780
+ var ruleList = Object.keys(rules);
781
+ // Sorts rules in order of increasing order, then
782
+ // ascending rule name in case of ties.
783
+ ruleList.sort(function (a, b) {
784
+ return rules[a]._order - rules[b]._order || (a < b ? -1 : 1);
785
+ });
786
+ function nestedParse(source, state) {
787
+ var result = [];
788
+ state.prevCapture = state.prevCapture || '';
789
+ if (source.trim()) {
790
+ while (source) {
791
+ var i = 0;
792
+ while (i < ruleList.length) {
793
+ var ruleType = ruleList[i];
794
+ var rule = rules[ruleType];
795
+ if (rule._qualify && !qualifies(source, state, rule._qualify)) {
796
+ i++;
797
+ continue;
798
+ }
799
+ var capture = rule._match(source, state);
800
+ if (capture && capture[0]) {
801
+ source = source.substring(capture[0].length);
802
+ var parsed = rule._parse(capture, nestedParse, state);
803
+ state.prevCapture += capture[0];
804
+ if (!parsed.type) parsed.type = ruleType;
805
+ result.push(parsed);
806
+ break;
807
+ }
808
+ i++;
809
+ }
810
+ }
811
+ }
812
+ // reset on exit
813
+ state.prevCapture = '';
814
+ return result;
815
+ }
816
+ return function (source, state) {
817
+ return nestedParse(normalizeWhitespace(source), state);
818
+ };
819
+ }
820
+ /**
821
+ * Marks a matcher function as eligible for being run inside an inline context;
822
+ * allows us to do a little less work in the nested parser.
823
+ */
824
+ function allowInline(fn) {
825
+ fn.inline = 1;
826
+ return fn;
827
+ }
828
+ // Creates a match function for an inline scoped or simple element from a regex
829
+ function inlineRegex(regex) {
830
+ return allowInline(function match(source, state) {
831
+ if (state.inline) {
832
+ return regex.exec(source);
833
+ } else {
834
+ return null;
835
+ }
836
+ });
837
+ }
838
+ // basically any inline element except links
839
+ function simpleInlineRegex(regex) {
840
+ return allowInline(function match(source, state) {
841
+ if (state.inline || state.simple) {
842
+ return regex.exec(source);
843
+ } else {
844
+ return null;
845
+ }
846
+ });
847
+ }
848
+ // Creates a match function for a block scoped element from a regex
849
+ function blockRegex(regex) {
850
+ return function match(source, state) {
851
+ if (state.inline || state.simple) {
852
+ return null;
853
+ } else {
854
+ return regex.exec(source);
855
+ }
856
+ };
857
+ }
858
+ // Creates a match function from a regex, ignoring block/inline scope
859
+ function anyScopeRegex(regex) {
860
+ return allowInline(function match(source /*, state*/) {
861
+ return regex.exec(source);
862
+ });
863
+ }
864
+ var SANITIZE_R = /(javascript|vbscript|data(?!:image)):/i;
865
+ function sanitizer(input) {
866
+ try {
867
+ var decoded = decodeURIComponent(input).replace(/[^A-Za-z0-9/:]/g, '');
868
+ if (SANITIZE_R.test(decoded)) {
869
+ if ("production" !== 'production') ;
870
+ return null;
871
+ }
872
+ } catch (e) {
873
+ // decodeURIComponent sometimes throws a URIError
874
+ // See `decodeURIComponent('a%AFc');`
875
+ // http://stackoverflow.com/questions/9064536/javascript-decodeuricomponent-malformed-uri-exception
876
+ return null;
877
+ }
878
+ return input;
879
+ }
880
+ function unescape(rawString) {
881
+ return rawString ? rawString.replace(UNESCAPE_R, '$1') : rawString;
882
+ }
883
+ /**
884
+ * Everything inline, including links.
885
+ */
886
+ function parseInline(parse, children, state) {
887
+ var isCurrentlyInline = state.inline || false;
888
+ var isCurrentlySimple = state.simple || false;
889
+ state.inline = true;
890
+ state.simple = true;
891
+ var result = parse(children, state);
892
+ state.inline = isCurrentlyInline;
893
+ state.simple = isCurrentlySimple;
894
+ return result;
895
+ }
896
+ /**
897
+ * Anything inline that isn't a link.
898
+ */
899
+ function parseSimpleInline(parse, children, state) {
900
+ var isCurrentlyInline = state.inline || false;
901
+ var isCurrentlySimple = state.simple || false;
902
+ state.inline = false;
903
+ state.simple = true;
904
+ var result = parse(children, state);
905
+ state.inline = isCurrentlyInline;
906
+ state.simple = isCurrentlySimple;
907
+ return result;
908
+ }
909
+ function parseBlock(parse, children, state) {
910
+ var isCurrentlyInline = state.inline || false;
911
+ state.inline = false;
912
+ var result = parse(children, state);
913
+ state.inline = isCurrentlyInline;
914
+ return result;
915
+ }
916
+ var parseCaptureInline = function parseCaptureInline(capture, parse, state) {
917
+ return {
918
+ children: parseInline(parse, capture[2], state)
919
+ };
920
+ };
921
+ function captureNothing() {
922
+ return {};
923
+ }
924
+ function render(node, output, state, h, sanitize, slug, refs) {
925
+ switch (node.type) {
926
+ case RuleType.blockQuote:
927
+ {
928
+ var props = {
929
+ key: state.key
930
+ };
931
+ if (node.alert) {
932
+ props.className = 'markdown-alert-' + slug(node.alert.toLowerCase(), slugify);
933
+ node.children.unshift({
934
+ attrs: {},
935
+ children: [{
936
+ type: RuleType.text,
937
+ text: node.alert
938
+ }],
939
+ noInnerParse: true,
940
+ type: RuleType.htmlBlock,
941
+ tag: 'header'
942
+ });
943
+ }
944
+ return h('blockquote', props, output(node.children, state));
945
+ }
946
+ case RuleType.breakLine:
947
+ return h("br", {
948
+ key: state.key
949
+ });
950
+ case RuleType.breakThematic:
951
+ return h("hr", {
952
+ key: state.key
953
+ });
954
+ case RuleType.codeBlock:
955
+ return h("pre", {
956
+ key: state.key
957
+ }, h("code", _extends({}, node.attrs, {
958
+ className: node.lang ? "lang-" + node.lang : ''
959
+ }), node.text));
960
+ case RuleType.codeInline:
961
+ return h("code", {
962
+ key: state.key
963
+ }, node.text);
964
+ case RuleType.footnoteReference:
965
+ return h("a", {
966
+ key: state.key,
967
+ href: sanitize(node.target, 'a', 'href')
968
+ }, h("sup", {
969
+ key: state.key
970
+ }, node.text));
971
+ case RuleType.gfmTask:
972
+ return h("input", {
973
+ checked: node.completed,
974
+ key: state.key,
975
+ readOnly: true,
976
+ type: "checkbox"
977
+ });
978
+ case RuleType.heading:
979
+ return h("h" + node.level, {
980
+ id: node.id,
981
+ key: state.key
982
+ }, output(node.children, state));
983
+ case RuleType.htmlBlock:
984
+ return h(node.tag, _extends({
985
+ key: state.key
986
+ }, node.attrs), node.text || (node.children ? output(node.children, state) : ''));
987
+ case RuleType.htmlSelfClosing:
988
+ return h(node.tag, _extends({}, node.attrs, {
989
+ key: state.key
990
+ }));
991
+ case RuleType.image:
992
+ return h("img", {
993
+ key: state.key,
994
+ alt: node.alt || undefined,
995
+ title: node.title || undefined,
996
+ src: sanitize(node.target, 'img', 'src')
997
+ });
998
+ case RuleType.link:
999
+ return h("a", {
1000
+ key: state.key,
1001
+ href: sanitize(node.target, 'a', 'href'),
1002
+ title: node.title
1003
+ }, output(node.children, state));
1004
+ case RuleType.refImage:
1005
+ return refs[node.ref] ? h("img", {
1006
+ key: state.key,
1007
+ alt: node.alt,
1008
+ src: sanitize(refs[node.ref].target, 'img', 'src'),
1009
+ title: refs[node.ref].title
1010
+ }) : null;
1011
+ case RuleType.refLink:
1012
+ return refs[node.ref] ? h("a", {
1013
+ key: state.key,
1014
+ href: sanitize(refs[node.ref].target, 'a', 'href'),
1015
+ title: refs[node.ref].title
1016
+ }, output(node.children, state)) : h("span", {
1017
+ key: state.key
1018
+ }, node.fallbackChildren);
1019
+ case RuleType.table:
1020
+ {
1021
+ var table = node;
1022
+ return h("table", {
1023
+ key: state.key
1024
+ }, h("thead", null, h("tr", null, table.header.map(function generateHeaderCell(content, i) {
1025
+ return h("th", {
1026
+ key: i,
1027
+ style: getTableStyle(table, i)
1028
+ }, output(content, state));
1029
+ }))), h("tbody", null, table.cells.map(function generateTableRow(row, i) {
1030
+ return h("tr", {
1031
+ key: i
1032
+ }, row.map(function generateTableCell(content, c) {
1033
+ return h("td", {
1034
+ key: c,
1035
+ style: getTableStyle(table, c)
1036
+ }, output(content, state));
1037
+ }));
1038
+ })));
1039
+ }
1040
+ case RuleType.text:
1041
+ return node.text;
1042
+ case RuleType.textFormatted:
1043
+ return h(node.tag, {
1044
+ key: state.key
1045
+ }, output(node.children, state));
1046
+ case RuleType.orderedList:
1047
+ case RuleType.unorderedList:
1048
+ {
1049
+ var Tag = node.ordered ? 'ol' : 'ul';
1050
+ return h(Tag, {
1051
+ key: state.key,
1052
+ start: node.type === RuleType.orderedList ? node.start : undefined
1053
+ }, node.items.map(function generateListItem(item, i) {
1054
+ return h("li", {
1055
+ key: i
1056
+ }, output(item, state));
1057
+ }));
1058
+ }
1059
+ case RuleType.newlineCoalescer:
1060
+ return '\n';
1061
+ case RuleType.paragraph:
1062
+ return h("p", {
1063
+ key: state.key
1064
+ }, output(node.children, state));
1065
+ default:
1066
+ return null;
1067
+ }
1068
+ }
1069
+ function createRenderer(userRender, h, sanitize, slug, refs) {
1070
+ function renderRule(ast, renderer, state) {
1071
+ var nodeRender = function nodeRender() {
1072
+ return render(ast, renderer, state, h, sanitize, slug, refs);
1073
+ };
1074
+ return userRender ? userRender(nodeRender, ast, renderer, state) : nodeRender();
1075
+ }
1076
+ // Return plain text as fallback to prevent stack overflow
1077
+ function handleStackOverflow(ast) {
1078
+ if (Array.isArray(ast)) {
1079
+ return ast.map(function (node) {
1080
+ return 'text' in node ? node.text : '';
1081
+ });
1082
+ }
1083
+ return 'text' in ast ? ast.text : '';
1084
+ }
1085
+ return function patchedRender(ast, state) {
1086
+ if (state === void 0) {
1087
+ state = {};
1088
+ }
1089
+ // Track render depth to prevent stack overflow from extremely deep nesting
1090
+ var currentDepth = (state.renderDepth || 0) + 1;
1091
+ var MAX_RENDER_DEPTH = 2500;
1092
+ if (currentDepth > MAX_RENDER_DEPTH) {
1093
+ return handleStackOverflow(ast);
1094
+ }
1095
+ state.renderDepth = currentDepth;
1096
+ try {
1097
+ if (Array.isArray(ast)) {
1098
+ var oldKey = state.key;
1099
+ var _result = [];
1100
+ // map nestedOutput over the ast, except group any text
1101
+ // nodes together into a single string output.
1102
+ var lastWasString = false;
1103
+ for (var i = 0; i < ast.length; i++) {
1104
+ state.key = i;
1105
+ var nodeOut = patchedRender(ast[i], state);
1106
+ var _isString = isString(nodeOut);
1107
+ if (_isString && lastWasString) {
1108
+ _result[_result.length - 1] += nodeOut;
1109
+ } else if (nodeOut !== null) {
1110
+ _result.push(nodeOut);
1111
+ }
1112
+ lastWasString = _isString;
1113
+ }
1114
+ state.key = oldKey;
1115
+ state.renderDepth = currentDepth - 1;
1116
+ return _result;
1117
+ }
1118
+ var result = renderRule(ast, patchedRender, state);
1119
+ state.renderDepth = currentDepth - 1;
1120
+ return result;
1121
+ } catch (error) {
1122
+ // Catch stack overflow or other unexpected errors
1123
+ if (error instanceof RangeError && error.message.includes('Maximum call stack')) {
1124
+ return handleStackOverflow(ast);
1125
+ }
1126
+ // Re-throw other errors
1127
+ throw error;
1128
+ }
1129
+ };
1130
+ }
1131
+ function cx() {
1132
+ return [].slice.call(arguments).filter(Boolean).join(' ');
1133
+ }
1134
+ function get(src, path, fb) {
1135
+ var ptr = src;
1136
+ var frags = path.split('.');
1137
+ while (frags.length) {
1138
+ ptr = ptr[frags[0]];
1139
+ if (ptr === undefined) break;else frags.shift();
1140
+ }
1141
+ return ptr || fb;
1142
+ }
1143
+ function getTag(tag, overrides) {
1144
+ var override = get(overrides, tag);
1145
+ if (!override) return tag;
1146
+ return typeof override === 'function' || typeof override === 'object' && 'render' in override ? override : get(overrides, tag + ".component", tag);
1147
+ }
1148
+ function attrStringToMap(tag, str, sanitize, compile) {
1149
+ if (!str || !str.trim()) return null;
1150
+ var attributes = str.match(ATTR_EXTRACTOR_R);
1151
+ if (!attributes) return null;
1152
+ return attributes.reduce(function (map, raw) {
1153
+ var delimiterIdx = raw.indexOf('=');
1154
+ if (delimiterIdx !== -1) {
1155
+ var key = normalizeAttributeKey(raw.slice(0, delimiterIdx)).trim();
1156
+ var mappedKey = ATTRIBUTE_TO_JSX_PROP_MAP[key] || key;
1157
+ if (mappedKey === 'ref') return map;
1158
+ var normalizedValue = map[mappedKey] = attributeValueToJSXPropValue(tag, key, unquote(raw.slice(delimiterIdx + 1).trim()), sanitize);
1159
+ if (typeof normalizedValue === 'string' && (HTML_BLOCK_ELEMENT_START_R.test(normalizedValue) || HTML_SELF_CLOSING_ELEMENT_R.test(normalizedValue))) {
1160
+ map[mappedKey] = compile(normalizedValue.trim());
1161
+ }
1162
+ } else if (raw !== 'style') {
1163
+ map[ATTRIBUTE_TO_JSX_PROP_MAP[raw] || raw] = true;
1164
+ }
1165
+ return map;
1166
+ }, {});
1167
+ }
1168
+ function some(regexes, input) {
1169
+ for (var i = 0; i < regexes.length; i++) {
1170
+ if (regexes[i].test(input)) {
1171
+ return true;
1172
+ }
1173
+ }
1174
+ return false;
1175
+ }
1176
+ function compiler(markdown, options) {
1177
+ var _rules;
1178
+ if (markdown === void 0) {
1179
+ markdown = '';
1180
+ }
1181
+ if (options === void 0) {
1182
+ options = {};
1183
+ }
1184
+ options.overrides = options.overrides || {};
1185
+ options.namedCodesToUnicode = options.namedCodesToUnicode ? _extends({}, namedCodesToUnicode, options.namedCodesToUnicode) : namedCodesToUnicode;
1186
+ var slug = options.slugify || slugify;
1187
+ var sanitize = options.sanitizer || sanitizer;
1188
+ var createElement = options.createElement || React.createElement;
1189
+ var NON_PARAGRAPH_BLOCK_SYNTAXES = [BLOCKQUOTE_R, CODE_BLOCK_FENCED_R, CODE_BLOCK_R, options.enforceAtxHeadings ? HEADING_ATX_COMPLIANT_R : HEADING_R, HEADING_SETEXT_R, NP_TABLE_R, ORDERED_LIST_R, UNORDERED_LIST_R];
1190
+ var BLOCK_SYNTAXES = [].concat(NON_PARAGRAPH_BLOCK_SYNTAXES, [PARAGRAPH_R, HTML_BLOCK_ELEMENT_START_R, HTML_COMMENT_R, HTML_SELF_CLOSING_ELEMENT_R]);
1191
+ function matchParagraph(source, state) {
1192
+ if (state.inline || state.simple || state.inHTML && !includes(source, '\n\n') && !includes(state.prevCapture, '\n\n')) return null;
1193
+ var match = '';
1194
+ var start = 0;
1195
+ while (true) {
1196
+ var nlIdx = source.indexOf('\n', start);
1197
+ var line = source.slice(start, nlIdx === -1 ? undefined : nlIdx + 1);
1198
+ var c = source[start];
1199
+ if ((c === '>' || c === '#' || c === '|' || c === '`' || c === '~' || c === '*' || c === '-' || c === '_' || c === ' ') && some(NON_PARAGRAPH_BLOCK_SYNTAXES, line)) break;
1200
+ match += line;
1201
+ if (nlIdx === -1 || !line.trim()) break;
1202
+ start = nlIdx + 1;
1203
+ }
1204
+ var captured = trimEnd(match);
1205
+ if (captured === '') return null;
1206
+ return [match,, captured];
1207
+ }
1208
+ // JSX custom pragma
1209
+ // eslint-disable-next-line no-unused-vars
1210
+ function h(
1211
+ // locally we always will render a known string tag
1212
+ tag, props) {
1213
+ var overrideProps = get(options.overrides, tag + ".props", {});
1214
+ return createElement.apply(void 0, [getTag(tag, options.overrides), _extends({}, props, overrideProps, {
1215
+ className: cx(props == null ? void 0 : props.className, overrideProps.className) || undefined
1216
+ })].concat([].slice.call(arguments, 2)));
1217
+ }
1218
+ function compile(input) {
1219
+ input = input.replace(FRONT_MATTER_R, '');
1220
+ var inline = false;
1221
+ if (options.forceInline) {
1222
+ inline = true;
1223
+ } else if (!options.forceBlock) {
1224
+ /**
1225
+ * should not contain any block-level markdown like newlines, lists, headings,
1226
+ * thematic breaks, blockquotes, tables, etc
1227
+ */
1228
+ inline = SHOULD_RENDER_AS_BLOCK_R.test(input) === false;
1229
+ }
1230
+ var astNodes = parser(inline ? input : trimEnd(input).replace(TRIM_STARTING_NEWLINES, '') + "\n\n", {
1231
+ inline: inline
1232
+ });
1233
+ if (options.ast) {
1234
+ return astNodes;
1235
+ }
1236
+ var arr = emitter(astNodes);
1237
+ while (isString(arr[arr.length - 1]) && !arr[arr.length - 1].trim()) {
1238
+ arr.pop();
1239
+ }
1240
+ if (footnotes.length) {
1241
+ arr.push(h("footer", {
1242
+ key: "footer"
1243
+ }, footnotes.map(function createFootnote(def) {
1244
+ return h("div", {
1245
+ id: slug(def.identifier, slugify),
1246
+ key: def.identifier
1247
+ }, def.identifier, emitter(parser(def.footnote, {
1248
+ inline: true
1249
+ })));
1250
+ })));
1251
+ }
1252
+ if (options.wrapper === null) {
1253
+ return arr;
1254
+ }
1255
+ var wrapper = options.wrapper || (inline ? 'span' : 'div');
1256
+ var jsx;
1257
+ if (arr.length > 1 || options.forceWrapper) {
1258
+ jsx = arr;
1259
+ } else if (arr.length === 1) {
1260
+ jsx = arr[0];
1261
+ // TODO: remove this for React 16
1262
+ if (typeof jsx === 'string') {
1263
+ return h("span", {
1264
+ key: "outer"
1265
+ }, jsx);
1266
+ } else {
1267
+ return jsx;
1268
+ }
1269
+ } else {
1270
+ // TODO: return null for React 16
1271
+ jsx = null;
1272
+ }
1273
+ return createElement(wrapper, _extends({
1274
+ key: 'outer'
1275
+ }, options.wrapperProps), jsx);
1276
+ }
1277
+ var footnotes = [];
1278
+ var refs = {};
1279
+ /**
1280
+ * each rule's react() output function goes through our custom
1281
+ * h() JSX pragma; this allows the override functionality to be
1282
+ * automatically applied
1283
+ */
1284
+ // @ts-ignore
1285
+ var rules = (_rules = {}, _rules[RuleType.blockQuote] = {
1286
+ _qualify: ['>'],
1287
+ _match: blockRegex(BLOCKQUOTE_R),
1288
+ _order: Priority.HIGH,
1289
+ _parse: function _parse(capture, parse, state) {
1290
+ var _capture$0$replace$ma = capture[0].replace(BLOCKQUOTE_TRIM_LEFT_MULTILINE_R, '').match(BLOCKQUOTE_ALERT_R),
1291
+ alert = _capture$0$replace$ma[1],
1292
+ content = _capture$0$replace$ma[2];
1293
+ return {
1294
+ alert: alert,
1295
+ children: parse(content, state)
1296
+ };
1297
+ }
1298
+ }, _rules[RuleType.breakLine] = {
1299
+ _qualify: [' '],
1300
+ _match: inlineRegex(BREAK_LINE_R),
1301
+ _order: Priority.HIGH,
1302
+ _parse: captureNothing
1303
+ }, _rules[RuleType.breakThematic] = {
1304
+ _qualify: function _qualify(source, state) {
1305
+ // Only attempt in block mode
1306
+ if (state.inline || state.simple) return false;
1307
+ var c = source[0];
1308
+ return c === '-' || c === '*' || c === '_';
1309
+ },
1310
+ _match: blockRegex(BREAK_THEMATIC_R),
1311
+ _order: Priority.HIGH,
1312
+ _parse: captureNothing
1313
+ }, _rules[RuleType.codeBlock] = {
1314
+ _qualify: [' '],
1315
+ _match: blockRegex(CODE_BLOCK_R),
1316
+ _order: Priority.MAX,
1317
+ _parse: function _parse(capture /*, parse, state*/) {
1318
+ return {
1319
+ lang: undefined,
1320
+ text: unescape(trimEnd(capture[0].replace(/^ {4}/gm, '')))
1321
+ };
1322
+ }
1323
+ }, _rules[RuleType.codeFenced] = {
1324
+ _qualify: ['```', '~~~'],
1325
+ _match: blockRegex(CODE_BLOCK_FENCED_R),
1326
+ _order: Priority.MAX,
1327
+ _parse: function _parse(capture /*, parse, state*/) {
1328
+ return {
1329
+ // if capture[3] it's additional metadata
1330
+ attrs: attrStringToMap('code', capture[3] || '', sanitize, compile),
1331
+ lang: capture[2] || undefined,
1332
+ text: capture[4],
1333
+ type: RuleType.codeBlock
1334
+ };
1335
+ }
1336
+ }, _rules[RuleType.codeInline] = {
1337
+ _qualify: ['`'],
1338
+ _match: simpleInlineRegex(CODE_INLINE_R),
1339
+ _order: Priority.LOW,
1340
+ _parse: function _parse(capture /*, parse, state*/) {
1341
+ return {
1342
+ text: unescape(capture[2])
1343
+ };
1344
+ }
1345
+ }, _rules[RuleType.footnote] = {
1346
+ _qualify: ['[^'],
1347
+ _match: blockRegex(FOOTNOTE_R),
1348
+ _order: Priority.MAX,
1349
+ _parse: function _parse(capture /*, parse, state*/) {
1350
+ footnotes.push({
1351
+ footnote: capture[2],
1352
+ identifier: capture[1]
1353
+ });
1354
+ return {};
1355
+ }
1356
+ }, _rules[RuleType.footnoteReference] = {
1357
+ _qualify: ['[^'],
1358
+ _match: inlineRegex(FOOTNOTE_REFERENCE_R),
1359
+ _order: Priority.HIGH,
1360
+ _parse: function _parse(capture /*, parse*/) {
1361
+ return {
1362
+ target: "#" + slug(capture[1], slugify),
1363
+ text: capture[1]
1364
+ };
1365
+ }
1366
+ }, _rules[RuleType.gfmTask] = {
1367
+ _qualify: ['[ ]', '[x]'],
1368
+ _match: inlineRegex(GFM_TASK_R),
1369
+ _order: Priority.HIGH,
1370
+ _parse: function _parse(capture /*, parse, state*/) {
1371
+ return {
1372
+ completed: capture[1].toLowerCase() === 'x'
1373
+ };
1374
+ }
1375
+ }, _rules[RuleType.heading] = {
1376
+ _qualify: ['#'],
1377
+ _match: blockRegex(options.enforceAtxHeadings ? HEADING_ATX_COMPLIANT_R : HEADING_R),
1378
+ _order: Priority.HIGH,
1379
+ _parse: function _parse(capture, parse, state) {
1380
+ return {
1381
+ children: parseInline(parse, capture[2], state),
1382
+ id: slug(capture[2], slugify),
1383
+ level: capture[1].length
1384
+ };
1385
+ }
1386
+ }, _rules[RuleType.headingSetext] = {
1387
+ _qualify: function _qualify(source) {
1388
+ var nlIndex = source.indexOf('\n');
1389
+ return nlIndex > 0 && nlIndex < source.length - 1 && (source[nlIndex + 1] === '=' || source[nlIndex + 1] === '-');
1390
+ },
1391
+ _match: blockRegex(HEADING_SETEXT_R),
1392
+ _order: Priority.HIGH,
1393
+ _parse: function _parse(capture, parse, state) {
1394
+ return {
1395
+ children: parseInline(parse, capture[1], state),
1396
+ level: capture[2] === '=' ? 1 : 2,
1397
+ type: RuleType.heading
1398
+ };
1399
+ }
1400
+ }, _rules[RuleType.htmlBlock] = {
1401
+ _qualify: ['<'],
1402
+ /**
1403
+ * find the first matching end tag and process the interior
1404
+ */
1405
+ _match: allowInline(matchHTMLBlock),
1406
+ _order: Priority.HIGH,
1407
+ _parse: function _parse(capture, parse, state) {
1408
+ var _capture$3$match = capture[3].match(HTML_LEFT_TRIM_AMOUNT_R),
1409
+ whitespace = _capture$3$match[1];
1410
+ var trimmer = new RegExp("^" + whitespace, 'gm');
1411
+ var trimmed = capture[3].replace(trimmer, '');
1412
+ var parseFunc = some(BLOCK_SYNTAXES, trimmed) ? parseBlock : parseInline;
1413
+ var tagName = capture[1].toLowerCase();
1414
+ var noInnerParse = DO_NOT_PROCESS_HTML_ELEMENTS.indexOf(tagName) !== -1;
1415
+ var tag = (noInnerParse ? tagName : capture[1]).trim();
1416
+ var ast = {
1417
+ attrs: attrStringToMap(tag, capture[2], sanitize, compile),
1418
+ noInnerParse: noInnerParse,
1419
+ tag: tag
1420
+ };
1421
+ state.inAnchor = state.inAnchor || tagName === 'a';
1422
+ if (noInnerParse) {
1423
+ ast.text = capture[3];
1424
+ } else {
1425
+ var prevInHTML = state.inHTML;
1426
+ state.inHTML = true;
1427
+ ast.children = parseFunc(parse, trimmed, state);
1428
+ state.inHTML = prevInHTML;
1429
+ }
1430
+ /**
1431
+ * if another html block is detected within, parse as block,
1432
+ * otherwise parse as inline to pick up any further markdown
1433
+ */
1434
+ state.inAnchor = false;
1435
+ return ast;
1436
+ }
1437
+ }, _rules[RuleType.htmlSelfClosing] = {
1438
+ _qualify: ['<'],
1439
+ /**
1440
+ * find the first matching end tag and process the interior
1441
+ */
1442
+ _match: anyScopeRegex(HTML_SELF_CLOSING_ELEMENT_R),
1443
+ _order: Priority.HIGH,
1444
+ _parse: function _parse(capture /*, parse, state*/) {
1445
+ var tag = capture[1].trim();
1446
+ return {
1447
+ attrs: attrStringToMap(tag, capture[2] || '', sanitize, compile),
1448
+ tag: tag
1449
+ };
1450
+ }
1451
+ }, _rules[RuleType.htmlComment] = {
1452
+ _qualify: ['<!--'],
1453
+ _match: anyScopeRegex(HTML_COMMENT_R),
1454
+ _order: Priority.HIGH,
1455
+ _parse: function _parse() {
1456
+ return {};
1457
+ }
1458
+ }, _rules[RuleType.image] = {
1459
+ _qualify: ['!['],
1460
+ _match: simpleInlineRegex(IMAGE_R),
1461
+ _order: Priority.HIGH,
1462
+ _parse: function _parse(capture /*, parse, state*/) {
1463
+ return {
1464
+ alt: unescape(capture[1]),
1465
+ target: unescape(capture[2]),
1466
+ title: unescape(capture[3])
1467
+ };
1468
+ }
1469
+ }, _rules[RuleType.link] = {
1470
+ _qualify: ['['],
1471
+ _match: inlineRegex(LINK_R),
1472
+ _order: Priority.LOW,
1473
+ _parse: function _parse(capture, parse, state) {
1474
+ return {
1475
+ children: parseSimpleInline(parse, capture[1], state),
1476
+ target: unescape(capture[2]),
1477
+ title: unescape(capture[3])
1478
+ };
1479
+ }
1480
+ }, _rules[RuleType.linkAngleBraceStyleDetector] = {
1481
+ _qualify: function _qualify(source, state) {
1482
+ // Only attempt in inline mode and skip if in anchor
1483
+ if (!state.inline || state.inAnchor) return false;
1484
+ // Must start with < and contain URL-like characters
1485
+ if (source[0] !== '<') return false;
1486
+ return includes(source, ':') || includes(source, '@') || includes(source, '/');
1487
+ },
1488
+ _match: inlineRegex(LINK_AUTOLINK_R),
1489
+ _order: Priority.MAX,
1490
+ _parse: function _parse(capture /*, parse, state*/) {
1491
+ var target = capture[1];
1492
+ var isEmail = false;
1493
+ if (includes(target, '@') &&
1494
+ // emails don't have protocols in them
1495
+ !includes(target, '//')) {
1496
+ isEmail = true;
1497
+ target = target.replace('mailto:', '');
1498
+ }
1499
+ return {
1500
+ children: [{
1501
+ text: target,
1502
+ type: RuleType.text
1503
+ }],
1504
+ target: isEmail ? 'mailto:' + target : target,
1505
+ type: RuleType.link
1506
+ };
1507
+ }
1508
+ }, _rules[RuleType.linkBareUrlDetector] = {
1509
+ _qualify: function _qualify(source, state) {
1510
+ if (state.inAnchor || options.disableAutoLink) return false;
1511
+ return startsWith(source, 'http');
1512
+ },
1513
+ _match: inlineRegex(LINK_AUTOLINK_BARE_URL_R),
1514
+ _order: Priority.MAX,
1515
+ _parse: function _parse(capture /*, parse, state*/) {
1516
+ return {
1517
+ children: [{
1518
+ text: capture[1],
1519
+ type: RuleType.text
1520
+ }],
1521
+ target: capture[1],
1522
+ title: undefined,
1523
+ type: RuleType.link
1524
+ };
1525
+ }
1526
+ }, _rules[RuleType.orderedList] = generateListRule(h, ORDERED), _rules[RuleType.unorderedList] = generateListRule(h, UNORDERED), _rules[RuleType.newlineCoalescer] = {
1527
+ _qualify: ['\n'],
1528
+ _match: blockRegex(CONSECUTIVE_NEWLINE_R),
1529
+ _order: Priority.LOW,
1530
+ _parse: captureNothing
1531
+ }, _rules[RuleType.paragraph] = {
1532
+ _qualify: function _qualify(source, state) {
1533
+ // Only attempt paragraph if not in inline/simple mode
1534
+ return !state.inline && !state.simple;
1535
+ },
1536
+ _match: allowInline(matchParagraph),
1537
+ _order: Priority.LOW,
1538
+ _parse: parseCaptureInline
1539
+ }, _rules[RuleType.ref] = {
1540
+ _qualify: ['['],
1541
+ _match: inlineRegex(REFERENCE_IMAGE_OR_LINK),
1542
+ _order: Priority.MAX,
1543
+ _parse: function _parse(capture /*, parse*/) {
1544
+ refs[capture[1]] = {
1545
+ target: capture[2],
1546
+ title: capture[4]
1547
+ };
1548
+ return {};
1549
+ }
1550
+ }, _rules[RuleType.refImage] = {
1551
+ _qualify: ['!['],
1552
+ _match: simpleInlineRegex(REFERENCE_IMAGE_R),
1553
+ _order: Priority.MAX,
1554
+ _parse: function _parse(capture) {
1555
+ return {
1556
+ alt: capture[1] ? unescape(capture[1]) : undefined,
1557
+ ref: capture[2]
1558
+ };
1559
+ }
1560
+ }, _rules[RuleType.refLink] = {
1561
+ _qualify: function _qualify(source) {
1562
+ return source[0] === '[' && !includes(source, '](');
1563
+ },
1564
+ _match: inlineRegex(REFERENCE_LINK_R),
1565
+ _order: Priority.MAX,
1566
+ _parse: function _parse(capture, parse, state) {
1567
+ return {
1568
+ children: parse(capture[1], state),
1569
+ fallbackChildren: capture[0],
1570
+ ref: capture[2]
1571
+ };
1572
+ }
1573
+ }, _rules[RuleType.table] = {
1574
+ _qualify: ['|'],
1575
+ _match: blockRegex(NP_TABLE_R),
1576
+ _order: Priority.HIGH,
1577
+ _parse: parseTable
1578
+ }, _rules[RuleType.text] = {
1579
+ // Here we look for anything followed by non-symbols,
1580
+ // double newlines, or double-space-newlines
1581
+ // We break on any symbol characters so that this grammar
1582
+ // is easy to extend without needing to modify this regex
1583
+ _match: allowInline(function (source, state) {
1584
+ var ret;
1585
+ if (startsWith(source, ':')) ret = SHORTCODE_R.exec(source);
1586
+ if (ret) return ret;
1587
+ return TEXT_PLAIN_R.exec(source);
1588
+ }),
1589
+ _order: Priority.MIN,
1590
+ _parse: function _parse(capture) {
1591
+ var text = capture[0];
1592
+ return {
1593
+ text: !includes(text, '&') ? text : text.replace(HTML_CHAR_CODE_R, function (full, inner) {
1594
+ return options.namedCodesToUnicode[inner] || full;
1595
+ })
1596
+ };
1597
+ }
1598
+ }, _rules[RuleType.textFormatted] = {
1599
+ _qualify: ['*', '_', '~', '='],
1600
+ _match: allowInline(matchInlineFormatting),
1601
+ _order: Priority.MED,
1602
+ _parse: function _parse(capture, parse, state) {
1603
+ return {
1604
+ children: parse(capture[2], state),
1605
+ tag: capture[1]
1606
+ };
1607
+ }
1608
+ }, _rules[RuleType.textEscaped] = {
1609
+ _qualify: ['\\'],
1610
+ // We don't allow escaping numbers, letters, or spaces here so that
1611
+ // backslashes used in plain text still get rendered. But allowing
1612
+ // escaping anything else provides a very flexible escape mechanism,
1613
+ // regardless of how this grammar is extended.
1614
+ _match: simpleInlineRegex(TEXT_ESCAPED_R),
1615
+ _order: Priority.HIGH,
1616
+ _parse: function _parse(capture /*, parse, state*/) {
1617
+ return {
1618
+ text: capture[1],
1619
+ type: RuleType.text
1620
+ };
1621
+ }
1622
+ }, _rules);
1623
+ var isDebug = !!process.env.DEBUG && process.env.DEBUG !== '0';
1624
+ var invocationCounts, ruleNames;
1625
+ if (isDebug) {
1626
+ // Initialize invocation counters for debugging
1627
+ invocationCounts = {
1628
+ match: {
1629
+ total: 0,
1630
+ attempts: 0
1631
+ },
1632
+ parse: {
1633
+ total: 0
1634
+ }
1635
+ };
1636
+ // Create a reverse mapping from numeric keys to rule names for better debugging output
1637
+ ruleNames = {};
1638
+ Object.keys(RuleType).forEach(function (ruleKey) {
1639
+ ruleNames[RuleType[ruleKey]] = ruleKey;
1640
+ });
1641
+ Object.keys(rules).forEach(function (key) {
1642
+ var _rules$key = rules[key],
1643
+ match = _rules$key._match,
1644
+ parse = _rules$key._parse;
1645
+ // Initialize per-rule counters: [matches, attempts, max]
1646
+ invocationCounts.match[key] = [0, 0, 0];
1647
+ // [exections, cost, max]
1648
+ invocationCounts.parse[key] = [0, 0, 0];
1649
+ rules[key]._match = function () {
1650
+ var _process$env$DEBUG2;
1651
+ var args = [].slice.call(arguments);
1652
+ // Track attempts for miss ratio calculation
1653
+ invocationCounts.match.attempts++;
1654
+ invocationCounts.match[key][1]++; // attempts for this rule
1655
+ var start = performance.now();
1656
+ var result = match.apply(void 0, args);
1657
+ var delta = performance.now() - start;
1658
+ invocationCounts.match[key][2] = Math.max(Number(invocationCounts.match[key][2]) || 0, delta);
1659
+ if (result) {
1660
+ var _process$env$DEBUG;
1661
+ // Successful match
1662
+ invocationCounts.match.total++;
1663
+ invocationCounts.match[key][0]++; // matches for this rule
1664
+ if ((_process$env$DEBUG = process.env.DEBUG) != null && _process$env$DEBUG.includes('speed')) {
1665
+ console[delta > 5 ? 'warn' : 'log']((ruleNames[key] || key) + ":match", delta.toFixed(3) + "ms", args[0]);
1666
+ }
1667
+ } else if ((_process$env$DEBUG2 = process.env.DEBUG) != null && _process$env$DEBUG2.includes('miss')) {
1668
+ console.log("\n" + (ruleNames[key] || key) + ":miss", JSON.stringify(args[0]));
1669
+ }
1670
+ return result;
1671
+ };
1672
+ rules[key]._parse = function () {
1673
+ var _process$env$DEBUG3;
1674
+ var args = [].slice.call(arguments);
1675
+ invocationCounts.parse.total++;
1676
+ invocationCounts.parse[key][0] += 1;
1677
+ var start = performance.now();
1678
+ var result = parse.apply(void 0, args);
1679
+ var delta = performance.now() - start;
1680
+ invocationCounts.parse[key][1] += delta;
1681
+ invocationCounts.parse[key][2] = Math.max(Number(invocationCounts.parse[key][2]) || 0, delta);
1682
+ if ((_process$env$DEBUG3 = process.env.DEBUG) != null && _process$env$DEBUG3.includes('speed')) {
1683
+ console[delta > 5 ? 'warn' : 'log']((ruleNames[key] || key) + ":parse", delta.toFixed(3) + "ms", args[0]);
1684
+ }
1685
+ return result;
1686
+ };
1687
+ });
1688
+ }
1689
+ if (options.disableParsingRawHTML === true) {
1690
+ delete rules[RuleType.htmlBlock];
1691
+ delete rules[RuleType.htmlSelfClosing];
1692
+ }
1693
+ var parser = parserFor(rules);
1694
+ var emitter = createRenderer(options.renderRule, h, sanitize, slug, refs);
1695
+ var jsx = compile(markdown);
1696
+ if (isDebug) {
1697
+ // Log invocation counts for debugging with readable rule names and miss ratios
1698
+ var matchCountsWithNames = {
1699
+ total: invocationCounts.match.total,
1700
+ attempts: invocationCounts.match.attempts,
1701
+ missRatio: invocationCounts.match.attempts > 0 ? ((invocationCounts.match.attempts - invocationCounts.match.total) / invocationCounts.match.attempts * 100).toFixed(1) + '%' : '0%'
1702
+ };
1703
+ var parseCountsWithNames = {
1704
+ total: invocationCounts.parse.total
1705
+ };
1706
+ Object.keys(invocationCounts.match).forEach(function (key) {
1707
+ if (key !== 'total' && key !== 'attempts') {
1708
+ var ruleName = ruleNames[key] || key;
1709
+ var _invocationCounts$mat = invocationCounts.match[key],
1710
+ matches = _invocationCounts$mat[0],
1711
+ attempts = _invocationCounts$mat[1],
1712
+ max = _invocationCounts$mat[2];
1713
+ matchCountsWithNames[ruleName] = {
1714
+ matches: matches,
1715
+ attempts: attempts,
1716
+ missRatio: attempts > 0 ? ((attempts - matches) / attempts * 100).toFixed(1) + '%' : '0%',
1717
+ max: max.toFixed(3)
1718
+ };
1719
+ }
1720
+ });
1721
+ Object.keys(invocationCounts.parse).forEach(function (key) {
1722
+ if (key !== 'total') {
1723
+ var ruleName = ruleNames[key] || key;
1724
+ var _invocationCounts$par = invocationCounts.parse[key],
1725
+ executions = _invocationCounts$par[0],
1726
+ cost = _invocationCounts$par[1],
1727
+ max = _invocationCounts$par[2];
1728
+ parseCountsWithNames[ruleName] = {
1729
+ executions: executions,
1730
+ cost: cost.toFixed(3),
1731
+ max: max.toFixed(3)
1732
+ };
1733
+ }
1734
+ });
1735
+ console.log('Match invocations:', matchCountsWithNames);
1736
+ console.log('Parse invocations:', parseCountsWithNames);
1737
+ }
1738
+ return jsx;
1739
+ }
1740
+ /**
1741
+ * A simple HOC for easy React use. Feed the markdown content as a direct child
1742
+ * and the rest is taken care of automatically.
1743
+ */
1744
+ var Markdown = function Markdown(_ref2) {
1745
+ var rawChildren = _ref2.children,
1746
+ options = _ref2.options,
1747
+ props = _objectWithoutPropertiesLoose(_ref2, _excluded);
1748
+ var children = rawChildren === null || rawChildren === undefined ? '' : rawChildren;
1749
+ return compiler(children, _extends({}, options, {
1750
+ wrapperProps: _extends({}, options == null ? void 0 : options.wrapperProps, props)
1751
+ }));
1752
+ };
1753
+
1754
+ export { RuleType, compiler, Markdown as default, sanitizer, slugify };
2
1755
  //# sourceMappingURL=debug.module.js.map