46 lines
33 KiB
JavaScript
46 lines
33 KiB
JavaScript
function M(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}let T=M();function Y(c){T=c}const ee=/[&<>"']/,ce=new RegExp(ee.source,"g"),te=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,he=new RegExp(te.source,"g"),pe={"&":"&","<":"<",">":">",'"':""","'":"'"},G=c=>pe[c];function d(c,n){if(n){if(ee.test(c))return c.replace(ce,G)}else if(te.test(c))return c.replace(he,G);return c}const ue=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function fe(c){return c.replace(ue,(n,e)=>(e=e.toLowerCase(),e==="colon"?":":e.charAt(0)==="#"?e.charAt(1)==="x"?String.fromCharCode(parseInt(e.substring(2),16)):String.fromCharCode(+e.substring(1)):""))}const ge=/(^|[^\[])\^/g;function k(c,n){let e=typeof c=="string"?c:c.source;n=n||"";const t={replace:(r,i)=>{let s=typeof i=="string"?i:i.source;return s=s.replace(ge,"$1"),e=e.replace(r,s),t},getRegex:()=>new RegExp(e,n)};return t}function W(c){try{c=encodeURI(c).replace(/%25/g,"%")}catch{return null}return c}const R={exec:()=>null};function J(c,n){const e=c.replace(/\|/g,(i,s,l)=>{let o=!1,p=s;for(;--p>=0&&l[p]==="\\";)o=!o;return o?"|":" |"}),t=e.split(/ \|/);let r=0;if(t[0].trim()||t.shift(),t.length>0&&!t[t.length-1].trim()&&t.pop(),n)if(t.length>n)t.splice(n);else for(;t.length<n;)t.push("");for(;r<t.length;r++)t[r]=t[r].trim().replace(/\\\|/g,"|");return t}function I(c,n,e){const t=c.length;if(t===0)return"";let r=0;for(;r<t;){const i=c.charAt(t-r-1);if(i===n&&!e)r++;else if(i!==n&&e)r++;else break}return c.slice(0,t-r)}function ke(c,n){if(c.indexOf(n[1])===-1)return-1;let e=0;for(let t=0;t<c.length;t++)if(c[t]==="\\")t++;else if(c[t]===n[0])e++;else if(c[t]===n[1]&&(e--,e<0))return t;return-1}function K(c,n,e,t){const r=n.href,i=n.title?d(n.title):null,s=c[1].replace(/\\([\[\]])/g,"$1");if(c[0].charAt(0)!=="!"){t.state.inLink=!0;const l={type:"link",raw:e,href:r,title:i,text:s,tokens:t.inlineTokens(s)};return t.state.inLink=!1,l}return{type:"image",raw:e,href:r,title:i,text:d(s)}}function de(c,n){const e=c.match(/^(\s+)(?:```)/);if(e===null)return n;const t=e[1];return n.split(`
|
|
`).map(r=>{const i=r.match(/^\s+/);if(i===null)return r;const[s]=i;return s.length>=t.length?r.slice(t.length):r}).join(`
|
|
`)}class L{options;rules;lexer;constructor(n){this.options=n||T}space(n){const e=this.rules.block.newline.exec(n);if(e&&e[0].length>0)return{type:"space",raw:e[0]}}code(n){const e=this.rules.block.code.exec(n);if(e){const t=e[0].replace(/^ {1,4}/gm,"");return{type:"code",raw:e[0],codeBlockStyle:"indented",text:this.options.pedantic?t:I(t,`
|
|
`)}}}fences(n){const e=this.rules.block.fences.exec(n);if(e){const t=e[0],r=de(t,e[3]||"");return{type:"code",raw:t,lang:e[2]?e[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):e[2],text:r}}}heading(n){const e=this.rules.block.heading.exec(n);if(e){let t=e[2].trim();if(/#$/.test(t)){const r=I(t,"#");(this.options.pedantic||!r||/ $/.test(r))&&(t=r.trim())}return{type:"heading",raw:e[0],depth:e[1].length,text:t,tokens:this.lexer.inline(t)}}}hr(n){const e=this.rules.block.hr.exec(n);if(e)return{type:"hr",raw:e[0]}}blockquote(n){const e=this.rules.block.blockquote.exec(n);if(e){const t=I(e[0].replace(/^ *>[ \t]?/gm,""),`
|
|
`),r=this.lexer.state.top;this.lexer.state.top=!0;const i=this.lexer.blockTokens(t);return this.lexer.state.top=r,{type:"blockquote",raw:e[0],tokens:i,text:t}}}list(n){let e=this.rules.block.list.exec(n);if(e){let t=e[1].trim();const r=t.length>1,i={type:"list",raw:"",ordered:r,start:r?+t.slice(0,-1):"",loose:!1,items:[]};t=r?`\\d{1,9}\\${t.slice(-1)}`:`\\${t}`,this.options.pedantic&&(t=r?t:"[*+-]");const s=new RegExp(`^( {0,3}${t})((?:[ ][^\\n]*)?(?:\\n|$))`);let l="",o="",p=!1;for(;n;){let a=!1;if(!(e=s.exec(n))||this.rules.block.hr.test(n))break;l=e[0],n=n.substring(l.length);let u=e[2].split(`
|
|
`,1)[0].replace(/^\t+/,B=>" ".repeat(3*B.length)),h=n.split(`
|
|
`,1)[0],f=0;this.options.pedantic?(f=2,o=u.trimStart()):(f=e[2].search(/[^ ]/),f=f>4?1:f,o=u.slice(f),f+=e[1].length);let w=!1;if(!u&&/^ *$/.test(h)&&(l+=h+`
|
|
`,n=n.substring(h.length+1),a=!0),!a){const B=new RegExp(`^ {0,${Math.min(3,f-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),F=new RegExp(`^ {0,${Math.min(3,f-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),U=new RegExp(`^ {0,${Math.min(3,f-1)}}(?:\`\`\`|~~~)`),X=new RegExp(`^ {0,${Math.min(3,f-1)}}#`);for(;n;){const q=n.split(`
|
|
`,1)[0];if(h=q,this.options.pedantic&&(h=h.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),U.test(h)||X.test(h)||B.test(h)||F.test(n))break;if(h.search(/[^ ]/)>=f||!h.trim())o+=`
|
|
`+h.slice(f);else{if(w||u.search(/[^ ]/)>=4||U.test(u)||X.test(u)||F.test(u))break;o+=`
|
|
`+h}!w&&!h.trim()&&(w=!0),l+=q+`
|
|
`,n=n.substring(q.length+1),u=h.slice(f)}}i.loose||(p?i.loose=!0:/\n *\n *$/.test(l)&&(p=!0));let x=null,y;this.options.gfm&&(x=/^\[[ xX]\] /.exec(o),x&&(y=x[0]!=="[ ] ",o=o.replace(/^\[[ xX]\] +/,""))),i.items.push({type:"list_item",raw:l,task:!!x,checked:y,loose:!1,text:o,tokens:[]}),i.raw+=l}i.items[i.items.length-1].raw=l.trimEnd(),i.items[i.items.length-1].text=o.trimEnd(),i.raw=i.raw.trimEnd();for(let a=0;a<i.items.length;a++)if(this.lexer.state.top=!1,i.items[a].tokens=this.lexer.blockTokens(i.items[a].text,[]),!i.loose){const u=i.items[a].tokens.filter(f=>f.type==="space"),h=u.length>0&&u.some(f=>/\n.*\n/.test(f.raw));i.loose=h}if(i.loose)for(let a=0;a<i.items.length;a++)i.items[a].loose=!0;return i}}html(n){const e=this.rules.block.html.exec(n);if(e)return{type:"html",block:!0,raw:e[0],pre:e[1]==="pre"||e[1]==="script"||e[1]==="style",text:e[0]}}def(n){const e=this.rules.block.def.exec(n);if(e){const t=e[1].toLowerCase().replace(/\s+/g," "),r=e[2]?e[2].replace(/^<(.*)>$/,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",i=e[3]?e[3].substring(1,e[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):e[3];return{type:"def",tag:t,raw:e[0],href:r,title:i}}}table(n){const e=this.rules.block.table.exec(n);if(!e||!/[:|]/.test(e[2]))return;const t=J(e[1]),r=e[2].replace(/^\||\| *$/g,"").split("|"),i=e[3]&&e[3].trim()?e[3].replace(/\n[ \t]*$/,"").split(`
|
|
`):[],s={type:"table",raw:e[0],header:[],align:[],rows:[]};if(t.length===r.length){for(const l of r)/^ *-+: *$/.test(l)?s.align.push("right"):/^ *:-+: *$/.test(l)?s.align.push("center"):/^ *:-+ *$/.test(l)?s.align.push("left"):s.align.push(null);for(const l of t)s.header.push({text:l,tokens:this.lexer.inline(l)});for(const l of i)s.rows.push(J(l,s.header.length).map(o=>({text:o,tokens:this.lexer.inline(o)})));return s}}lheading(n){const e=this.rules.block.lheading.exec(n);if(e)return{type:"heading",raw:e[0],depth:e[2].charAt(0)==="="?1:2,text:e[1],tokens:this.lexer.inline(e[1])}}paragraph(n){const e=this.rules.block.paragraph.exec(n);if(e){const t=e[1].charAt(e[1].length-1)===`
|
|
`?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:t,tokens:this.lexer.inline(t)}}}text(n){const e=this.rules.block.text.exec(n);if(e)return{type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(n){const e=this.rules.inline.escape.exec(n);if(e)return{type:"escape",raw:e[0],text:d(e[1])}}tag(n){const e=this.rules.inline.tag.exec(n);if(e)return!this.lexer.state.inLink&&/^<a /i.test(e[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&/^<\/a>/i.test(e[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(e[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(e[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:e[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:e[0]}}link(n){const e=this.rules.inline.link.exec(n);if(e){const t=e[2].trim();if(!this.options.pedantic&&/^</.test(t)){if(!/>$/.test(t))return;const s=I(t.slice(0,-1),"\\");if((t.length-s.length)%2===0)return}else{const s=ke(e[2],"()");if(s>-1){const o=(e[0].indexOf("!")===0?5:4)+e[1].length+s;e[2]=e[2].substring(0,s),e[0]=e[0].substring(0,o).trim(),e[3]=""}}let r=e[2],i="";if(this.options.pedantic){const s=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(r);s&&(r=s[1],i=s[3])}else i=e[3]?e[3].slice(1,-1):"";return r=r.trim(),/^</.test(r)&&(this.options.pedantic&&!/>$/.test(t)?r=r.slice(1):r=r.slice(1,-1)),K(e,{href:r&&r.replace(this.rules.inline.anyPunctuation,"$1"),title:i&&i.replace(this.rules.inline.anyPunctuation,"$1")},e[0],this.lexer)}}reflink(n,e){let t;if((t=this.rules.inline.reflink.exec(n))||(t=this.rules.inline.nolink.exec(n))){const r=(t[2]||t[1]).replace(/\s+/g," "),i=e[r.toLowerCase()];if(!i){const s=t[0].charAt(0);return{type:"text",raw:s,text:s}}return K(t,i,t[0],this.lexer)}}emStrong(n,e,t=""){let r=this.rules.inline.emStrongLDelim.exec(n);if(!r||r[3]&&t.match(/[\p{L}\p{N}]/u))return;if(!(r[1]||r[2]||"")||!t||this.rules.inline.punctuation.exec(t)){const s=[...r[0]].length-1;let l,o,p=s,a=0;const u=r[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(u.lastIndex=0,e=e.slice(-1*n.length+s);(r=u.exec(e))!=null;){if(l=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!l)continue;if(o=[...l].length,r[3]||r[4]){p+=o;continue}else if((r[5]||r[6])&&s%3&&!((s+o)%3)){a+=o;continue}if(p-=o,p>0)continue;o=Math.min(o,o+p+a);const h=[...r[0]][0].length,f=n.slice(0,s+r.index+h+o);if(Math.min(s,o)%2){const x=f.slice(1,-1);return{type:"em",raw:f,text:x,tokens:this.lexer.inlineTokens(x)}}const w=f.slice(2,-2);return{type:"strong",raw:f,text:w,tokens:this.lexer.inlineTokens(w)}}}}codespan(n){const e=this.rules.inline.code.exec(n);if(e){let t=e[2].replace(/\n/g," ");const r=/[^ ]/.test(t),i=/^ /.test(t)&&/ $/.test(t);return r&&i&&(t=t.substring(1,t.length-1)),t=d(t,!0),{type:"codespan",raw:e[0],text:t}}}br(n){const e=this.rules.inline.br.exec(n);if(e)return{type:"br",raw:e[0]}}del(n){const e=this.rules.inline.del.exec(n);if(e)return{type:"del",raw:e[0],text:e[2],tokens:this.lexer.inlineTokens(e[2])}}autolink(n){const e=this.rules.inline.autolink.exec(n);if(e){let t,r;return e[2]==="@"?(t=d(e[1]),r="mailto:"+t):(t=d(e[1]),r=t),{type:"link",raw:e[0],text:t,href:r,tokens:[{type:"text",raw:t,text:t}]}}}url(n){let e;if(e=this.rules.inline.url.exec(n)){let t,r;if(e[2]==="@")t=d(e[0]),r="mailto:"+t;else{let i;do i=e[0],e[0]=this.rules.inline._backpedal.exec(e[0])?.[0]??"";while(i!==e[0]);t=d(e[0]),e[1]==="www."?r="http://"+e[0]:r=e[0]}return{type:"link",raw:e[0],text:t,href:r,tokens:[{type:"text",raw:t,text:t}]}}}inlineText(n){const e=this.rules.inline.text.exec(n);if(e){let t;return this.lexer.state.inRawBlock?t=e[0]:t=d(e[0]),{type:"text",raw:e[0],text:t}}}}const xe=/^(?: *(?:\n|$))+/,be=/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,me=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,_=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,we=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,ne=/(?:[*+-]|\d{1,9}[.)])/,se=k(/^(?!bull )((?:.|\n(?!\s*?\n|bull ))+?)\n {0,3}(=+|-+) *(?:\n+|$)/).replace(/bull/g,ne).getRegex(),Q=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,ye=/^[^\n]+/,D=/(?!\s*\])(?:\\.|[^\[\]\\])+/,$e=k(/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/).replace("label",D).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Te=k(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,ne).getRegex(),P="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",O=/<!--(?!-?>)[\s\S]*?(?:-->|$)/,ze=k("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))","i").replace("comment",O).replace("tag",P).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),ie=k(Q).replace("hr",_).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",P).getRegex(),Re=k(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",ie).getRegex(),j={blockquote:Re,code:be,def:$e,fences:me,heading:we,hr:_,html:ze,lheading:se,list:Te,newline:xe,paragraph:ie,table:R,text:ye},V=k("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",_).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code"," {4}[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",P).getRegex(),_e={...j,table:V,paragraph:k(Q).replace("hr",_).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",V).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",P).getRegex()},Se={...j,html:k(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",O).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:R,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:k(Q).replace("hr",_).replace("heading",` *#{1,6} *[^
|
|
]`).replace("lheading",se).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},re=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Ie=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,le=/^( {2,}|\\)\n(?!\s*$)/,Ae=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,S="\\p{P}$+<=>`^|~",Ee=k(/^((?![*_])[\spunctuation])/,"u").replace(/punctuation/g,S).getRegex(),Le=/\[[^[\]]*?\]\([^\(\)]*?\)|`[^`]*?`|<[^<>]*?>/g,Ce=k(/^(?:\*+(?:((?!\*)[punct])|[^\s*]))|^_+(?:((?!_)[punct])|([^\s_]))/,"u").replace(/punct/g,S).getRegex(),Ze=k("^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)[punct](\\*+)(?=[\\s]|$)|[^punct\\s](\\*+)(?!\\*)(?=[punct\\s]|$)|(?!\\*)[punct\\s](\\*+)(?=[^punct\\s])|[\\s](\\*+)(?!\\*)(?=[punct])|(?!\\*)[punct](\\*+)(?!\\*)(?=[punct])|[^punct\\s](\\*+)(?=[^punct\\s])","gu").replace(/punct/g,S).getRegex(),Pe=k("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)[punct](_+)(?=[\\s]|$)|[^punct\\s](_+)(?!_)(?=[punct\\s]|$)|(?!_)[punct\\s](_+)(?=[^punct\\s])|[\\s](_+)(?!_)(?=[punct])|(?!_)[punct](_+)(?!_)(?=[punct])","gu").replace(/punct/g,S).getRegex(),Be=k(/\\([punct])/,"gu").replace(/punct/g,S).getRegex(),qe=k(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),ve=k(O).replace("(?:-->|$)","-->").getRegex(),Me=k("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",ve).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),C=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,Qe=k(/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/).replace("label",C).replace("href",/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),oe=k(/^!?\[(label)\]\[(ref)\]/).replace("label",C).replace("ref",D).getRegex(),ae=k(/^!?\[(ref)\](?:\[\])?/).replace("ref",D).getRegex(),De=k("reflink|nolink(?!\\()","g").replace("reflink",oe).replace("nolink",ae).getRegex(),H={_backpedal:R,anyPunctuation:Be,autolink:qe,blockSkip:Le,br:le,code:Ie,del:R,emStrongLDelim:Ce,emStrongRDelimAst:Ze,emStrongRDelimUnd:Pe,escape:re,link:Qe,nolink:ae,punctuation:Ee,reflink:oe,reflinkSearch:De,tag:Me,text:Ae,url:R},Oe={...H,link:k(/^!?\[(label)\]\((.*?)\)/).replace("label",C).getRegex(),reflink:k(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",C).getRegex()},v={...H,escape:k(re).replace("])","~|])").getRegex(),url:k(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,"i").replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},je={...v,br:k(le).replace("{2,}","*").getRegex(),text:k(v.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},A={normal:j,gfm:_e,pedantic:Se},z={normal:H,gfm:v,breaks:je,pedantic:Oe};class b{tokens;options;state;tokenizer;inlineQueue;constructor(n){this.tokens=[],this.tokens.links=Object.create(null),this.options=n||T,this.options.tokenizer=this.options.tokenizer||new L,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const e={block:A.normal,inline:z.normal};this.options.pedantic?(e.block=A.pedantic,e.inline=z.pedantic):this.options.gfm&&(e.block=A.gfm,this.options.breaks?e.inline=z.breaks:e.inline=z.gfm),this.tokenizer.rules=e}static get rules(){return{block:A,inline:z}}static lex(n,e){return new b(e).lex(n)}static lexInline(n,e){return new b(e).inlineTokens(n)}lex(n){n=n.replace(/\r\n|\r/g,`
|
|
`),this.blockTokens(n,this.tokens);let e;for(;e=this.inlineQueue.shift();)this.inlineTokens(e.src,e.tokens);return this.tokens}blockTokens(n,e=[]){this.options.pedantic?n=n.replace(/\t/g," ").replace(/^ +$/gm,""):n=n.replace(/^( *)(\t+)/gm,(l,o,p)=>o+" ".repeat(p.length));let t,r,i,s;for(;n;)if(!(this.options.extensions&&this.options.extensions.block&&this.options.extensions.block.some(l=>(t=l.call({lexer:this},n,e))?(n=n.substring(t.raw.length),e.push(t),!0):!1))){if(t=this.tokenizer.space(n)){n=n.substring(t.raw.length),t.raw.length===1&&e.length>0?e[e.length-1].raw+=`
|
|
`:e.push(t);continue}if(t=this.tokenizer.code(n)){n=n.substring(t.raw.length),r=e[e.length-1],r&&(r.type==="paragraph"||r.type==="text")?(r.raw+=`
|
|
`+t.raw,r.text+=`
|
|
`+t.text,this.inlineQueue[this.inlineQueue.length-1].src=r.text):e.push(t);continue}if(t=this.tokenizer.fences(n)){n=n.substring(t.raw.length),e.push(t);continue}if(t=this.tokenizer.heading(n)){n=n.substring(t.raw.length),e.push(t);continue}if(t=this.tokenizer.hr(n)){n=n.substring(t.raw.length),e.push(t);continue}if(t=this.tokenizer.blockquote(n)){n=n.substring(t.raw.length),e.push(t);continue}if(t=this.tokenizer.list(n)){n=n.substring(t.raw.length),e.push(t);continue}if(t=this.tokenizer.html(n)){n=n.substring(t.raw.length),e.push(t);continue}if(t=this.tokenizer.def(n)){n=n.substring(t.raw.length),r=e[e.length-1],r&&(r.type==="paragraph"||r.type==="text")?(r.raw+=`
|
|
`+t.raw,r.text+=`
|
|
`+t.raw,this.inlineQueue[this.inlineQueue.length-1].src=r.text):this.tokens.links[t.tag]||(this.tokens.links[t.tag]={href:t.href,title:t.title});continue}if(t=this.tokenizer.table(n)){n=n.substring(t.raw.length),e.push(t);continue}if(t=this.tokenizer.lheading(n)){n=n.substring(t.raw.length),e.push(t);continue}if(i=n,this.options.extensions&&this.options.extensions.startBlock){let l=1/0;const o=n.slice(1);let p;this.options.extensions.startBlock.forEach(a=>{p=a.call({lexer:this},o),typeof p=="number"&&p>=0&&(l=Math.min(l,p))}),l<1/0&&l>=0&&(i=n.substring(0,l+1))}if(this.state.top&&(t=this.tokenizer.paragraph(i))){r=e[e.length-1],s&&r.type==="paragraph"?(r.raw+=`
|
|
`+t.raw,r.text+=`
|
|
`+t.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=r.text):e.push(t),s=i.length!==n.length,n=n.substring(t.raw.length);continue}if(t=this.tokenizer.text(n)){n=n.substring(t.raw.length),r=e[e.length-1],r&&r.type==="text"?(r.raw+=`
|
|
`+t.raw,r.text+=`
|
|
`+t.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=r.text):e.push(t);continue}if(n){const l="Infinite loop on byte: "+n.charCodeAt(0);if(this.options.silent){console.error(l);break}else throw new Error(l)}}return this.state.top=!0,e}inline(n,e=[]){return this.inlineQueue.push({src:n,tokens:e}),e}inlineTokens(n,e=[]){let t,r,i,s=n,l,o,p;if(this.tokens.links){const a=Object.keys(this.tokens.links);if(a.length>0)for(;(l=this.tokenizer.rules.inline.reflinkSearch.exec(s))!=null;)a.includes(l[0].slice(l[0].lastIndexOf("[")+1,-1))&&(s=s.slice(0,l.index)+"["+"a".repeat(l[0].length-2)+"]"+s.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(l=this.tokenizer.rules.inline.blockSkip.exec(s))!=null;)s=s.slice(0,l.index)+"["+"a".repeat(l[0].length-2)+"]"+s.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);for(;(l=this.tokenizer.rules.inline.anyPunctuation.exec(s))!=null;)s=s.slice(0,l.index)+"++"+s.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;n;)if(o||(p=""),o=!1,!(this.options.extensions&&this.options.extensions.inline&&this.options.extensions.inline.some(a=>(t=a.call({lexer:this},n,e))?(n=n.substring(t.raw.length),e.push(t),!0):!1))){if(t=this.tokenizer.escape(n)){n=n.substring(t.raw.length),e.push(t);continue}if(t=this.tokenizer.tag(n)){n=n.substring(t.raw.length),r=e[e.length-1],r&&t.type==="text"&&r.type==="text"?(r.raw+=t.raw,r.text+=t.text):e.push(t);continue}if(t=this.tokenizer.link(n)){n=n.substring(t.raw.length),e.push(t);continue}if(t=this.tokenizer.reflink(n,this.tokens.links)){n=n.substring(t.raw.length),r=e[e.length-1],r&&t.type==="text"&&r.type==="text"?(r.raw+=t.raw,r.text+=t.text):e.push(t);continue}if(t=this.tokenizer.emStrong(n,s,p)){n=n.substring(t.raw.length),e.push(t);continue}if(t=this.tokenizer.codespan(n)){n=n.substring(t.raw.length),e.push(t);continue}if(t=this.tokenizer.br(n)){n=n.substring(t.raw.length),e.push(t);continue}if(t=this.tokenizer.del(n)){n=n.substring(t.raw.length),e.push(t);continue}if(t=this.tokenizer.autolink(n)){n=n.substring(t.raw.length),e.push(t);continue}if(!this.state.inLink&&(t=this.tokenizer.url(n))){n=n.substring(t.raw.length),e.push(t);continue}if(i=n,this.options.extensions&&this.options.extensions.startInline){let a=1/0;const u=n.slice(1);let h;this.options.extensions.startInline.forEach(f=>{h=f.call({lexer:this},u),typeof h=="number"&&h>=0&&(a=Math.min(a,h))}),a<1/0&&a>=0&&(i=n.substring(0,a+1))}if(t=this.tokenizer.inlineText(i)){n=n.substring(t.raw.length),t.raw.slice(-1)!=="_"&&(p=t.raw.slice(-1)),o=!0,r=e[e.length-1],r&&r.type==="text"?(r.raw+=t.raw,r.text+=t.text):e.push(t);continue}if(n){const a="Infinite loop on byte: "+n.charCodeAt(0);if(this.options.silent){console.error(a);break}else throw new Error(a)}}return e}}class Z{options;constructor(n){this.options=n||T}code(n,e,t){const r=(e||"").match(/^\S*/)?.[0];return n=n.replace(/\n$/,"")+`
|
|
`,r?'<pre><code class="language-'+d(r)+'">'+(t?n:d(n,!0))+`</code></pre>
|
|
`:"<pre><code>"+(t?n:d(n,!0))+`</code></pre>
|
|
`}blockquote(n){return`<blockquote>
|
|
${n}</blockquote>
|
|
`}html(n,e){return n}heading(n,e,t){return`<h${e}>${n}</h${e}>
|
|
`}hr(){return`<hr>
|
|
`}list(n,e,t){const r=e?"ol":"ul",i=e&&t!==1?' start="'+t+'"':"";return"<"+r+i+`>
|
|
`+n+"</"+r+`>
|
|
`}listitem(n,e,t){return`<li>${n}</li>
|
|
`}checkbox(n){return"<input "+(n?'checked="" ':"")+'disabled="" type="checkbox">'}paragraph(n){return`<p>${n}</p>
|
|
`}table(n,e){return e&&(e=`<tbody>${e}</tbody>`),`<table>
|
|
<thead>
|
|
`+n+`</thead>
|
|
`+e+`</table>
|
|
`}tablerow(n){return`<tr>
|
|
${n}</tr>
|
|
`}tablecell(n,e){const t=e.header?"th":"td";return(e.align?`<${t} align="${e.align}">`:`<${t}>`)+n+`</${t}>
|
|
`}strong(n){return`<strong>${n}</strong>`}em(n){return`<em>${n}</em>`}codespan(n){return`<code>${n}</code>`}br(){return"<br>"}del(n){return`<del>${n}</del>`}link(n,e,t){const r=W(n);if(r===null)return t;n=r;let i='<a href="'+n+'"';return e&&(i+=' title="'+e+'"'),i+=">"+t+"</a>",i}image(n,e,t){const r=W(n);if(r===null)return t;n=r;let i=`<img src="${n}" alt="${t}"`;return e&&(i+=` title="${e}"`),i+=">",i}text(n){return n}}class N{strong(n){return n}em(n){return n}codespan(n){return n}del(n){return n}html(n){return n}text(n){return n}link(n,e,t){return""+t}image(n,e,t){return""+t}br(){return""}}class m{options;renderer;textRenderer;constructor(n){this.options=n||T,this.options.renderer=this.options.renderer||new Z,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new N}static parse(n,e){return new m(e).parse(n)}static parseInline(n,e){return new m(e).parseInline(n)}parse(n,e=!0){let t="";for(let r=0;r<n.length;r++){const i=n[r];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[i.type]){const s=i,l=this.options.extensions.renderers[s.type].call({parser:this},s);if(l!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(s.type)){t+=l||"";continue}}switch(i.type){case"space":continue;case"hr":{t+=this.renderer.hr();continue}case"heading":{const s=i;t+=this.renderer.heading(this.parseInline(s.tokens),s.depth,fe(this.parseInline(s.tokens,this.textRenderer)));continue}case"code":{const s=i;t+=this.renderer.code(s.text,s.lang,!!s.escaped);continue}case"table":{const s=i;let l="",o="";for(let a=0;a<s.header.length;a++)o+=this.renderer.tablecell(this.parseInline(s.header[a].tokens),{header:!0,align:s.align[a]});l+=this.renderer.tablerow(o);let p="";for(let a=0;a<s.rows.length;a++){const u=s.rows[a];o="";for(let h=0;h<u.length;h++)o+=this.renderer.tablecell(this.parseInline(u[h].tokens),{header:!1,align:s.align[h]});p+=this.renderer.tablerow(o)}t+=this.renderer.table(l,p);continue}case"blockquote":{const s=i,l=this.parse(s.tokens);t+=this.renderer.blockquote(l);continue}case"list":{const s=i,l=s.ordered,o=s.start,p=s.loose;let a="";for(let u=0;u<s.items.length;u++){const h=s.items[u],f=h.checked,w=h.task;let x="";if(h.task){const y=this.renderer.checkbox(!!f);p?h.tokens.length>0&&h.tokens[0].type==="paragraph"?(h.tokens[0].text=y+" "+h.tokens[0].text,h.tokens[0].tokens&&h.tokens[0].tokens.length>0&&h.tokens[0].tokens[0].type==="text"&&(h.tokens[0].tokens[0].text=y+" "+h.tokens[0].tokens[0].text)):h.tokens.unshift({type:"text",text:y+" "}):x+=y+" "}x+=this.parse(h.tokens,p),a+=this.renderer.listitem(x,w,!!f)}t+=this.renderer.list(a,l,o);continue}case"html":{const s=i;t+=this.renderer.html(s.text,s.block);continue}case"paragraph":{const s=i;t+=this.renderer.paragraph(this.parseInline(s.tokens));continue}case"text":{let s=i,l=s.tokens?this.parseInline(s.tokens):s.text;for(;r+1<n.length&&n[r+1].type==="text";)s=n[++r],l+=`
|
|
`+(s.tokens?this.parseInline(s.tokens):s.text);t+=e?this.renderer.paragraph(l):l;continue}default:{const s='Token with "'+i.type+'" type was not found.';if(this.options.silent)return console.error(s),"";throw new Error(s)}}}return t}parseInline(n,e){e=e||this.renderer;let t="";for(let r=0;r<n.length;r++){const i=n[r];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[i.type]){const s=this.options.extensions.renderers[i.type].call({parser:this},i);if(s!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(i.type)){t+=s||"";continue}}switch(i.type){case"escape":{const s=i;t+=e.text(s.text);break}case"html":{const s=i;t+=e.html(s.text);break}case"link":{const s=i;t+=e.link(s.href,s.title,this.parseInline(s.tokens,e));break}case"image":{const s=i;t+=e.image(s.href,s.title,s.text);break}case"strong":{const s=i;t+=e.strong(this.parseInline(s.tokens,e));break}case"em":{const s=i;t+=e.em(this.parseInline(s.tokens,e));break}case"codespan":{const s=i;t+=e.codespan(s.text);break}case"br":{t+=e.br();break}case"del":{const s=i;t+=e.del(this.parseInline(s.tokens,e));break}case"text":{const s=i;t+=e.text(s.text);break}default:{const s='Token with "'+i.type+'" type was not found.';if(this.options.silent)return console.error(s),"";throw new Error(s)}}}return t}}class E{options;constructor(n){this.options=n||T}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(n){return n}postprocess(n){return n}processAllTokens(n){return n}}class He{defaults=M();options=this.setOptions;parse=this.#e(b.lex,m.parse);parseInline=this.#e(b.lexInline,m.parseInline);Parser=m;Renderer=Z;TextRenderer=N;Lexer=b;Tokenizer=L;Hooks=E;constructor(...n){this.use(...n)}walkTokens(n,e){let t=[];for(const r of n)switch(t=t.concat(e.call(this,r)),r.type){case"table":{const i=r;for(const s of i.header)t=t.concat(this.walkTokens(s.tokens,e));for(const s of i.rows)for(const l of s)t=t.concat(this.walkTokens(l.tokens,e));break}case"list":{const i=r;t=t.concat(this.walkTokens(i.items,e));break}default:{const i=r;this.defaults.extensions?.childTokens?.[i.type]?this.defaults.extensions.childTokens[i.type].forEach(s=>{t=t.concat(this.walkTokens(i[s],e))}):i.tokens&&(t=t.concat(this.walkTokens(i.tokens,e)))}}return t}use(...n){const e=this.defaults.extensions||{renderers:{},childTokens:{}};return n.forEach(t=>{const r={...t};if(r.async=this.defaults.async||r.async||!1,t.extensions&&(t.extensions.forEach(i=>{if(!i.name)throw new Error("extension name required");if("renderer"in i){const s=e.renderers[i.name];s?e.renderers[i.name]=function(...l){let o=i.renderer.apply(this,l);return o===!1&&(o=s.apply(this,l)),o}:e.renderers[i.name]=i.renderer}if("tokenizer"in i){if(!i.level||i.level!=="block"&&i.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");const s=e[i.level];s?s.unshift(i.tokenizer):e[i.level]=[i.tokenizer],i.start&&(i.level==="block"?e.startBlock?e.startBlock.push(i.start):e.startBlock=[i.start]:i.level==="inline"&&(e.startInline?e.startInline.push(i.start):e.startInline=[i.start]))}"childTokens"in i&&i.childTokens&&(e.childTokens[i.name]=i.childTokens)}),r.extensions=e),t.renderer){const i=this.defaults.renderer||new Z(this.defaults);for(const s in t.renderer){if(!(s in i))throw new Error(`renderer '${s}' does not exist`);if(s==="options")continue;const l=s,o=t.renderer[l],p=i[l];i[l]=(...a)=>{let u=o.apply(i,a);return u===!1&&(u=p.apply(i,a)),u||""}}r.renderer=i}if(t.tokenizer){const i=this.defaults.tokenizer||new L(this.defaults);for(const s in t.tokenizer){if(!(s in i))throw new Error(`tokenizer '${s}' does not exist`);if(["options","rules","lexer"].includes(s))continue;const l=s,o=t.tokenizer[l],p=i[l];i[l]=(...a)=>{let u=o.apply(i,a);return u===!1&&(u=p.apply(i,a)),u}}r.tokenizer=i}if(t.hooks){const i=this.defaults.hooks||new E;for(const s in t.hooks){if(!(s in i))throw new Error(`hook '${s}' does not exist`);if(s==="options")continue;const l=s,o=t.hooks[l],p=i[l];E.passThroughHooks.has(s)?i[l]=a=>{if(this.defaults.async)return Promise.resolve(o.call(i,a)).then(h=>p.call(i,h));const u=o.call(i,a);return p.call(i,u)}:i[l]=(...a)=>{let u=o.apply(i,a);return u===!1&&(u=p.apply(i,a)),u}}r.hooks=i}if(t.walkTokens){const i=this.defaults.walkTokens,s=t.walkTokens;r.walkTokens=function(l){let o=[];return o.push(s.call(this,l)),i&&(o=o.concat(i.call(this,l))),o}}this.defaults={...this.defaults,...r}}),this}setOptions(n){return this.defaults={...this.defaults,...n},this}lexer(n,e){return b.lex(n,e??this.defaults)}parser(n,e){return m.parse(n,e??this.defaults)}#e(n,e){return(t,r)=>{const i={...r},s={...this.defaults,...i};this.defaults.async===!0&&i.async===!1&&(s.silent||console.warn("marked(): The async option was set to true by an extension. The async: false option sent to parse will be ignored."),s.async=!0);const l=this.#t(!!s.silent,!!s.async);if(typeof t>"u"||t===null)return l(new Error("marked(): input parameter is undefined or null"));if(typeof t!="string")return l(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(t)+", string expected"));if(s.hooks&&(s.hooks.options=s),s.async)return Promise.resolve(s.hooks?s.hooks.preprocess(t):t).then(o=>n(o,s)).then(o=>s.hooks?s.hooks.processAllTokens(o):o).then(o=>s.walkTokens?Promise.all(this.walkTokens(o,s.walkTokens)).then(()=>o):o).then(o=>e(o,s)).then(o=>s.hooks?s.hooks.postprocess(o):o).catch(l);try{s.hooks&&(t=s.hooks.preprocess(t));let o=n(t,s);s.hooks&&(o=s.hooks.processAllTokens(o)),s.walkTokens&&this.walkTokens(o,s.walkTokens);let p=e(o,s);return s.hooks&&(p=s.hooks.postprocess(p)),p}catch(o){return l(o)}}}#t(n,e){return t=>{if(t.message+=`
|
|
Please report this to https://github.com/markedjs/marked.`,n){const r="<p>An error occurred:</p><pre>"+d(t.message+"",!0)+"</pre>";return e?Promise.resolve(r):r}if(e)return Promise.reject(t);throw t}}}const $=new He;function g(c,n){return $.parse(c,n)}g.options=g.setOptions=function(c){return $.setOptions(c),g.defaults=$.defaults,Y(g.defaults),g};g.getDefaults=M;g.defaults=T;g.use=function(...c){return $.use(...c),g.defaults=$.defaults,Y(g.defaults),g};g.walkTokens=function(c,n){return $.walkTokens(c,n)};g.parseInline=$.parseInline;g.Parser=m;g.parser=m.parse;g.Renderer=Z;g.TextRenderer=N;g.Lexer=b;g.lexer=b.lex;g.Tokenizer=L;g.Hooks=E;g.parse=g;g.options;g.setOptions;g.use;g.walkTokens;g.parseInline;m.parse;b.lex;export{g as m};
|