UNPKG

14.3 kBJavaScriptView Raw
1import e from"react";function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var n=/[\'\"]/;const r={accesskey:"accessKey",allowfullscreen:"allowFullScreen",allowtransparency:"allowTransparency",autocomplete:"autoComplete",autofocus:"autoFocus",autoplay:"autoPlay",cellpadding:"cellPadding",cellspacing:"cellSpacing",charset:"charSet",class:"className",classid:"classId",colspan:"colSpan",contenteditable:"contentEditable",contextmenu:"contextMenu",crossorigin:"crossOrigin",enctype:"encType",for:"htmlFor",formaction:"formAction",formenctype:"formEncType",formmethod:"formMethod",formnovalidate:"formNoValidate",formtarget:"formTarget",frameborder:"frameBorder",hreflang:"hrefLang",inputmode:"inputMode",keyparams:"keyParams",keytype:"keyType",marginheight:"marginHeight",marginwidth:"marginWidth",maxlength:"maxLength",mediagroup:"mediaGroup",minlength:"minLength",novalidate:"noValidate",radiogroup:"radioGroup",readonly:"readOnly",rowspan:"rowSpan",spellcheck:"spellCheck",srcdoc:"srcDoc",srclang:"srcLang",srcset:"srcSet",tabindex:"tabIndex",usemap:"useMap"},a={amp:"&",apos:"'",gt:">",lt:"<",nbsp:" ",quot:"“"},c=["style","script"],o=/([-A-Z0-9_:]+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|(?:\{((?:\\.|{[^}]*?}|[^}])*)\})))?/gi,l=/mailto:/i,i=/\n{2,}$/,s=/^( *>[^\n]+(\n[^\n]+)*\n*)+\n{2,}/,p=/^ *> ?/gm,u=/^ {2,}\n/,d=/^(?:( *[-*_]) *){3,}(?:\n *)+\n/,f=/^\s*(`{3,}|~{3,}) *(\S+)? *\n([\s\S]+?)\s*\1 *(?:\n *)+\n?/,m=/^(?: {4}[^\n]+\n*)+(?:\n *)+\n?/,g=/^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,h=/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?|`.*?`|~+.*?~+|.)*?)\1(?!\1|\w)/,J=/^~~((?:\[.*?\]|<.*?>(?:.*?<.*?>)?|`.*?`|.)*?)~~/,Y=/^\\([^0-9A-Za-z\s])/,ee=/^[\s\S]+?(?=[^0-9A-Z\s\u00c0-\uffff&;.()'"]|\d+\.|\n\n| {2,}\n|\w+:\S|$)/i,te=/(^\n+|\n+$|\s+$)/g,ne=/^([ \t]*)/,re=/\\([^0-9A-Z\s])/gi,ae=new RegExp("^( *)((?:[*+-]|\\d+\\.)) +"),ce=new RegExp("( *)((?:[*+-]|\\d+\\.)) +[^\\n]*(?:\\n(?!\\1(?:[*+-]|\\d+\\.) )[^\\n]*)*(\\n|$)","gm"),oe=new RegExp("^( *)((?:[*+-]|\\d+\\.)) [\\s\\S]+?(?:\\n{2,}(?! )(?!\\1(?:[*+-]|\\d+\\.) (?!(?:[*+-]|\\d+\\.) ))\\n*|\\s*\\n*$)"),le="(?:\\[[^\\]]*\\]|[^\\[\\]]|\\](?=[^\\[]*\\]))*",ie=new RegExp("^\\[("+le+")\\]\\(\\s*<?((?:[^\\s\\\\]|\\\\.)*?)>?(?:\\s+['\"]([\\s\\S]*?)['\"])?\\s*\\)"),se=new RegExp("^!\\[("+le+")\\]\\(\\s*<?((?:[^\\s\\\\]|\\\\.)*?)>?(?:\\s+['\"]([\\s\\S]*?)['\"])?\\s*\\)"),pe=[s,m,f,v,A,I,$,M,ce,oe,X,R];function ue(e){return e.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 de(e){return V.test(e)?"right":F.test(e)?"center":q.test(e)?"left":null}function fe(e,t,n){const r=n.inTable;n.inTable=!0;const a=t(e.trim(),n);n.inTable=r;let c=[[]];return a.forEach(function(e,t){"tableSeparator"===e.type?0!==t&&t!==a.length-1&&c.push([]):("text"!==e.type||null!=a[t+1]&&"tableSeparator"!==a[t+1].type||(e.content=e.content.replace(Z,"")),c[c.length-1].push(e))}),c}function me(e,t,n){n.inline=!0;const r=fe(e[1],t,n),a=e[2].replace(P,"").split("|").map(de),c=function(e,t,n){return e.trim().split("\n").map(function(e){return fe(e,t,n)})}(e[3],t,n);return n.inline=!1,{align:a,cells:c,header:r,type:"table"}}function ge(e,t){return null==e.align[t]?{}:{textAlign:e.align[t]}}function he(e){return function(t,n){return n.inline?e.exec(t):null}}function ye(e){return function(t,n){return n.inline||n.simple?e.exec(t):null}}function ke(e){return function(t,n){return n.inline||n.simple?null:e.exec(t)}}function xe(e){return function(t){return e.exec(t)}}function be(e){try{if(decodeURIComponent(e).replace(/[^A-Za-z0-9/:]/g,"").match(/^\s*(javascript|vbscript|data):/i))return null}catch(e){return null}return e}function He(e){return e.replace(re,"$1")}function ve(e,t,n){const r=n.inline||!1,a=n.simple||!1;n.inline=!0,n.simple=!0;const c=e(t,n);return n.inline=r,n.simple=a,c}function Ae(e,t,n){const r=n.inline||!1,a=n.simple||!1;n.inline=!1,n.simple=!0;const c=e(t,n);return n.inline=r,n.simple=a,c}function Ie(e,t,n){return n.inline=!1,e(t+"\n\n",n)}const Se=(e,t,n)=>({content:ve(t,e[1],n)});function $e(){return{}}function we(){return null}function Me(...e){return e.filter(Boolean).join(" ")}function Oe(e,t,n){let r=e;const a=t.split(".");for(;a.length&&(r=r[a[0]],void 0!==r);)a.shift();return r||n}var Ee;function Ce(P,Z={}){Z.overrides=Z.overrides||{},Z.slugify=Z.slugify||ue,Z.namedCodesToUnicode=Z.namedCodesToUnicode?t({},a,Z.namedCodesToUnicode):a;const F=Z.createElement||e.createElement;function q(e,n,...r){const a=Oe(Z.overrides,`${e}.props`,{});return F(function(e,t){const n=Oe(t,e);return n?"function"==typeof n||"object"==typeof n&&"render"in n?n:Oe(t,`${e}.component`,e):e}(e,Z.overrides),t({},n,a,{className:Me(null==n?void 0:n.className,a.className)||void 0}),...r)}function V(t){let n=!1;Z.forceInline?n=!0:Z.forceBlock||(n=!1===N.test(t));const r=Ge(Ce(n?t:`${t.replace(te,"")}\n\n`,{inline:n}));if(null===Z.wrapper)return r;const a=Z.wrapper||(n?"span":"div");let c;if(r.length>1||Z.forceWrapper)c=r;else{if(1===r.length)return c=r[0],"string"==typeof c?q("span",{key:"outer"},c):c;c=null}return e.createElement(a,{key:"outer"},c)}function re(t){const a=t.match(o);return a?a.reduce(function(t,a,c){const o=a.indexOf("=");if(-1!==o){const l=function(e){return-1!==e.indexOf("-")&&null===e.match(w)&&(e=e.replace(z,function(e,t){return t.toUpperCase()})),e}(a.slice(0,o)).trim(),i=function(e){return e?(n.test(e.charAt(0))&&(e=e.substr(1)),n.test(e.charAt(e.length-1))&&(e=e.substr(0,e.length-1)),e):""}(a.slice(o+1).trim()),s=r[l]||l,p=t[s]=function(e,t){return"style"===e?t.split(/;\s?/).reduce(function(e,t){const n=t.slice(0,t.indexOf(":"));return e[n.replace(/(-[a-z])/g,e=>e[1].toUpperCase())]=t.slice(n.length+1).trim(),e},{}):"href"===e?be(t):(t.match(O)&&(t=t.slice(1,t.length-1)),"true"===t||"false"!==t&&t)}(l,i);"string"==typeof p&&(I.test(p)||M.test(p))&&(t[s]=e.cloneElement(V(p.trim()),{key:c}))}else"style"!==a&&(t[r[a]||a]=!0);return t},{}):void 0}const le=[],de={},fe={blockQuote:{match:ke(s),order:Ee.HIGH,parse:(e,t,n)=>({content:t(e[0].replace(p,""),n)}),react:(e,t,n)=>q("blockquote",{key:n.key},t(e.content,n))},breakLine:{match:xe(u),order:Ee.HIGH,parse:$e,react:(e,t,n)=>q("br",{key:n.key})},breakThematic:{match:ke(d),order:Ee.HIGH,parse:$e,react:(e,t,n)=>q("hr",{key:n.key})},codeBlock:{match:ke(m),order:Ee.MAX,parse:e=>({content:e[0].replace(/^ {4}/gm,"").replace(/\n+$/,""),lang:void 0}),react:(e,t,n)=>q("pre",{key:n.key},q("code",{className:e.lang?`lang-${e.lang}`:""},e.content))},codeFenced:{match:ke(f),order:Ee.MAX,parse:e=>({content:e[3],lang:e[2]||void 0,type:"codeBlock"})},codeInline:{match:ye(g),order:Ee.LOW,parse:e=>({content:e[2]}),react:(e,t,n)=>q("code",{key:n.key},e.content)},footnote:{match:ke(k),order:Ee.MAX,parse:e=>(le.push({footnote:e[2],identifier:e[1]}),{}),react:we},footnoteReference:{match:he(x),order:Ee.HIGH,parse:e=>({content:e[1],target:`#${Z.slugify(e[1])}`}),react:(e,t,n)=>q("a",{key:n.key,href:be(e.target)},q("sup",{key:n.key},e.content))},gfmTask:{match:he(H),order:Ee.HIGH,parse:e=>({completed:"x"===e[1].toLowerCase()}),react:(e,t,n)=>q("input",{checked:e.completed,key:n.key,readOnly:!0,type:"checkbox"})},heading:{match:ke(v),order:Ee.HIGH,parse:(e,t,n)=>({content:ve(t,e[2],n),id:Z.slugify(e[2]),level:e[1].length}),react:(e,t,n)=>(e.tag=`h${e.level}`,q(e.tag,{id:e.id,key:n.key},t(e.content,n)))},headingSetext:{match:ke(A),order:Ee.MAX,parse:(e,t,n)=>({content:ve(t,e[1],n),level:"="===e[2]?1:2,type:"heading"})},htmlComment:{match:xe($),order:Ee.HIGH,parse:()=>({}),react:we},image:{match:ye(se),order:Ee.HIGH,parse:e=>({alt:e[1],target:He(e[2]),title:e[3]}),react:(e,t,n)=>q("img",{key:n.key,alt:e.alt||void 0,title:e.title||void 0,src:be(e.target)})},link:{match:he(ie),order:Ee.LOW,parse:(e,t,n)=>({content:Ae(t,e[1],n),target:He(e[2]),title:e[3]}),react:(e,t,n)=>q("a",{key:n.key,href:be(e.target),title:e.title},t(e.content,n))},linkAngleBraceStyleDetector:{match:he(G),order:Ee.MAX,parse:e=>({content:[{content:e[1],type:"text"}],target:e[1],type:"link"})},linkBareUrlDetector:{match:(e,t)=>t.inAnchor?null:he(E)(e,t),order:Ee.MAX,parse:e=>({content:[{content:e[1],type:"text"}],target:e[1],title:void 0,type:"link"})},linkMailtoDetector:{match:he(C),order:Ee.MAX,parse(e){let t=e[1],n=e[1];return l.test(n)||(n="mailto:"+n),{content:[{content:t.replace("mailto:",""),type:"text"}],target:n,type:"link"}}},list:{match(e,t,n){const r=T.exec(n);return!r||!t._list&&t.inline?null:oe.exec(e=r[1]+e)},order:Ee.HIGH,parse(e,t,n){const r=e[2],a=r.length>1,c=a?+r:void 0,o=e[0].replace(i,"\n").match(ce);let l=!1;return{items:o.map(function(e,r){const a=ae.exec(e)[0].length,c=new RegExp("^ {1,"+a+"}","gm"),i=e.replace(c,"").replace(ae,""),s=r===o.length-1,p=-1!==i.indexOf("\n\n")||s&&l;l=p;const u=n.inline,d=n._list;let f;n._list=!0,p?(n.inline=!1,f=i.replace(L,"\n\n")):(n.inline=!0,f=i.replace(L,""));const m=t(f,n);return n.inline=u,n._list=d,m}),ordered:a,start:c}},react:(e,t,n)=>q(e.ordered?"ol":"ul",{key:n.key,start:e.start},e.items.map(function(e,r){return q("li",{key:r},t(e,n))}))},newlineCoalescer:{match:ke(h),order:Ee.LOW,parse:$e,react:()=>"\n"},paragraph:{match:ke(R),order:Ee.LOW,parse:Se,react:(e,t,n)=>q("p",{key:n.key},t(e.content,n))},ref:{match:he(W),order:Ee.MAX,parse:e=>(de[e[1]]={target:e[2],title:e[4]},{}),react:we},refImage:{match:ye(_),order:Ee.MAX,parse:e=>({alt:e[1]||void 0,ref:e[2]}),react:(e,t,n)=>q("img",{key:n.key,alt:e.alt,src:be(de[e.ref].target),title:de[e.ref].title})},refLink:{match:he(j),order:Ee.MAX,parse:(e,t,n)=>({content:t(e[1],n),fallbackContent:t(e[0].replace(B,"\\$1"),n),ref:e[2]}),react:(e,t,n)=>de[e.ref]?q("a",{key:n.key,href:be(de[e.ref].target),title:de[e.ref].title},t(e.content,n)):q("span",{key:n.key},t(e.fallbackContent,n))},table:{match:ke(X),order:Ee.HIGH,parse:me,react:(e,t,n)=>q("table",{key:n.key},q("thead",null,q("tr",null,e.header.map(function(r,a){return q("th",{key:a,style:ge(e,a)},t(r,n))}))),q("tbody",null,e.cells.map(function(r,a){return q("tr",{key:a},r.map(function(r,a){return q("td",{key:a,style:ge(e,a)},t(r,n))}))})))},tableSeparator:{match:function(e,t){return t.inTable?D.exec(e):null},order:Ee.HIGH,parse:function(){return{type:"tableSeparator"}},react:()=>" | "},text:{match:xe(ee),order:Ee.MIN,parse:e=>({content:e[0].replace(S,(e,t)=>Z.namedCodesToUnicode[t]?Z.namedCodesToUnicode[t]:e)}),react:e=>e.content},textBolded:{match:ye(K),order:Ee.MED,parse:(e,t,n)=>({content:t(e[2],n)}),react:(e,t,n)=>q("strong",{key:n.key},t(e.content,n))},textEmphasized:{match:ye(Q),order:Ee.LOW,parse:(e,t,n)=>({content:t(e[2],n)}),react:(e,t,n)=>q("em",{key:n.key},t(e.content,n))},textEscaped:{match:ye(Y),order:Ee.HIGH,parse:e=>({content:e[1],type:"text"})},textStrikethroughed:{match:ye(J),order:Ee.LOW,parse:Se,react:(e,t,n)=>q("del",{key:n.key},t(e.content,n))}};!0!==Z.disableParsingRawHTML&&(fe.htmlBlock={match:xe(I),order:Ee.HIGH,parse(e,t,n){const[,r]=e[3].match(ne),a=new RegExp(`^${r}`,"gm"),o=e[3].replace(a,""),l=(i=o,pe.some(e=>e.test(i))?Ie:ve);var i;const s=e[1].toLowerCase(),p=-1!==c.indexOf(s);n.inAnchor=n.inAnchor||"a"===s;const u=p?e[3]:l(t,o,n);return n.inAnchor=!1,{attrs:re(e[2]),content:u,noInnerParse:p,tag:p?s:e[1]}},react:(e,t,n)=>q(e.tag,Object.assign({key:n.key},e.attrs),e.noInnerParse?e.content:t(e.content,n))},fe.htmlSelfClosing={match:xe(M),order:Ee.HIGH,parse:e=>({attrs:re(e[2]||""),tag:e[1]}),react:(e,t,n)=>q(e.tag,Object.assign({},e.attrs,{key:n.key}))});const Ce=function(e){let t=Object.keys(e);function n(r,a){let c=[],o="";for(;r;){let l=0;for(;l<t.length;){const i=t[l],s=e[i],p=s.match(r,a,o);if(p){const e=p[0];r=r.substring(e.length);const t=s.parse(p,n,a);null==t.type&&(t.type=i),c.push(t),o=e;break}l++}}return c}return t.sort(function(t,n){let r=e[t].order,a=e[n].order;return r!==a?r-a:t<n?-1:1}),function(e,t){return n(function(e){return e.replace(y,"\n").replace(b,"").replace(U," ")}(e),t)}}(fe),Ge=(Le=function(e){return function(t,n,r){return e[t.type].react(t,n,r)}}(fe),function e(t,n={}){if(Array.isArray(t)){const r=n.key,a=[];let c=!1;for(let r=0;r<t.length;r++){n.key=r;const o=e(t[r],n),l="string"==typeof o;l&&c?a[a.length-1]+=o:a.push(o),c=l}return n.key=r,a}return Le(t,e,n)});var Le;const Te=V(P);return le.length&&Te.props.children.push(q("footer",{key:"footer"},le.map(function(e){return q("div",{id:Z.slugify(e.identifier),key:e.identifier},e.identifier,Ge(Ce(e.footnote,{inline:!0})))}))),Te}!function(e){e[e.MAX=0]="MAX",e[e.HIGH=1]="HIGH",e[e.MED=2]="MED",e[e.LOW=3]="LOW",e[e.MIN=4]="MIN"}(Ee||(Ee={}));export default t=>{let{children:n,options:r}=t,a=function(e,t){if(null==e)return{};var n,r,a={},c=Object.keys(e);for(r=0;r<c.length;r++)t.indexOf(n=c[r])>=0||(a[n]=e[n]);return a}(t,["children","options"]);return e.cloneElement(Ce(n,r),a)};export{Ce as compiler};
2//# sourceMappingURL=index.modern.js.map