aboutsummaryrefslogtreecommitdiff
path: root/src/external/marked.min.js
blob: 343e92106f8c5ec0683c8aa72ad18b71cc42cb05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/**
 * marked v8.0.1 - a markdown parser
 * Copyright (c) 2011-2023, Christopher Jeffrey. (MIT Licensed)
 * https://github.com/markedjs/marked
 */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).marked={})}(this,function(t){"use strict";function e(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}function n(e){t.defaults=e}t.defaults=e();const r=/[&<>"']/,s=new RegExp(r.source,"g"),i=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,l=new RegExp(i.source,"g"),a={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},o=e=>a[e];function c(e,t){if(t){if(r.test(e))return e.replace(s,o)}else if(i.test(e))return e.replace(l,o);return e}const b=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi;const h=/(^|[^\[])\^/g;function p(n,e){n="string"==typeof n?n:n.source,e=e||"";const r={replace:(e,t)=>(t=(t="object"==typeof t&&"source"in t?t.source:t).replace(h,"$1"),n=n.replace(e,t),r),getRegex:()=>new RegExp(n,e)};return r}function u(e){try{e=encodeURI(e).replace(/%25/g,"%")}catch(e){return null}return e}var g={exec:()=>null};function k(e,t){var n=e.replace(/\|/g,(e,t,n)=>{let r=!1,s=t;for(;0<=--s&&"\\"===n[s];)r=!r;return r?"|":" |"}).split(/ \|/);let r=0;if(n[0].trim()||n.shift(),0<n.length&&!n[n.length-1].trim()&&n.pop(),t)if(n.length>t)n.splice(t);else for(;n.length<t;)n.push("");for(;r<n.length;r++)n[r]=n[r].trim().replace(/\\\|/g,"|");return n}function f(e,t,n){var r=e.length;if(0===r)return"";let s=0;for(;s<r;){var i=e.charAt(r-s-1);if((i!==t||n)&&(i===t||!n))break;s++}return e.slice(0,r-s)}function d(e,t,n,r){var s=t.href,t=t.title?c(t.title):null,i=e[1].replace(/\\([\[\]])/g,"$1");return"!"!==e[0].charAt(0)?(r.state.inLink=!0,e={type:"link",raw:n,href:s,title:t,text:i,tokens:r.inlineTokens(i)},r.state.inLink=!1,e):{type:"image",raw:n,href:s,title:t,text:c(i)}}class w{options;rules;lexer;constructor(e){this.options=e||t.defaults}space(e){e=this.rules.block.newline.exec(e);if(e&&0<e[0].length)return{type:"space",raw:e[0]}}code(e){var t,e=this.rules.block.code.exec(e);if(e)return t=e[0].replace(/^ {1,4}/gm,""),{type:"code",raw:e[0],codeBlockStyle:"indented",text:this.options.pedantic?t:f(t,"\n")}}fences(e){var t,n,e=this.rules.block.fences.exec(e);if(e)return n=function(e,t){if(null===(e=e.match(/^(\s+)(?:```)/)))return t;const n=e[1];return t.split("\n").map(e=>{var t=e.match(/^\s+/);return null!==t&&([t]=t,t.length>=n.length)?e.slice(n.length):e}).join("\n")}(t=e[0],e[3]||""),{type:"code",raw:t,lang:e[2]&&e[2].trim().replace(this.rules.inline._escapes,"$1"),text:n}}heading(t){var n,t=this.rules.block.heading.exec(t);if(t){let e=t[2].trim();return/#$/.test(e)&&(n=f(e,"#"),!this.options.pedantic&&n&&!/ $/.test(n)||(e=n.trim())),{type:"heading",raw:t[0],depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){e=this.rules.block.hr.exec(e);if(e)return{type:"hr",raw:e[0]}}blockquote(e){var t,n,r,e=this.rules.block.blockquote.exec(e);if(e)return t=e[0].replace(/^ *>[ \t]?/gm,""),n=this.lexer.state.top,this.lexer.state.top=!0,r=this.lexer.blockTokens(t),this.lexer.state.top=n,{type:"blockquote",raw:e[0],tokens:r,text:t}}list(h){let p=this.rules.block.list.exec(h);if(p){let e=p[1].trim();var t,n=1<e.length,u={type:"list",raw:"",ordered:n,start:n?+e.slice(0,-1):"",loose:!1,items:[]},g=(e=n?"\\d{1,9}\\"+e.slice(-1):"\\"+e,this.options.pedantic&&(e=n?e:"[*+-]"),new RegExp(`^( {0,3}${e})((?:[	 ][^\\n]*)?(?:\\n|$))`));let a="",o="",c=!1;for(;h;){let e=!1;if(!(p=g.exec(h)))break;if(this.rules.block.hr.test(h))break;a=p[0],h=h.substring(a.length);let t=p[2].split("\n",1)[0].replace(/^\t+/,e=>" ".repeat(3*e.length)),n=h.split("\n",1)[0],r=0,s=(this.options.pedantic?(r=2,o=t.trimStart()):(r=4<(r=p[2].search(/[^ ]/))?1:r,o=t.slice(r),r+=p[1].length),!1);if(!t&&/^ *$/.test(n)&&(a+=n+"\n",h=h.substring(n.length+1),e=!0),!e)for(var k=new RegExp(`^ {0,${Math.min(3,r-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ 	][^\\n]*)?(?:\\n|$))`),f=new RegExp(`^ {0,${Math.min(3,r-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),d=new RegExp(`^ {0,${Math.min(3,r-1)}}(?:\`\`\`|~~~)`),x=new RegExp(`^ {0,${Math.min(3,r-1)}}#`);h;){var b=h.split("\n",1)[0];if(n=b,this.options.pedantic&&(n=n.replace(/^ {1,4}(?=( {4})*[^ ])/g,"  ")),d.test(n))break;if(x.test(n))break;if(k.test(n))break;if(f.test(h))break;if(n.search(/[^ ]/)>=r||!n.trim())o+="\n"+n.slice(r);else{if(s)break;if(4<=t.search(/[^ ]/))break;if(d.test(t))break;if(x.test(t))break;if(f.test(t))break;o+="\n"+n}s||n.trim()||(s=!0),a+=b+"\n",h=h.substring(b.length+1),t=n.slice(r)}u.loose||(c?u.loose=!0:/\n *\n *$/.test(a)&&(c=!0));let i=null,l;this.options.gfm&&(i=/^\[[ xX]\] /.exec(o))&&(l="[ ] "!==i[0],o=o.replace(/^\[[ xX]\] +/,"")),u.items.push({type:"list_item",raw:a,task:!!i,checked:l,loose:!1,text:o,tokens:[]}),u.raw+=a}u.items[u.items.length-1].raw=a.trimEnd(),u.items[u.items.length-1].text=o.trimEnd(),u.raw=u.raw.trimEnd();for(let e=0;e<u.items.length;e++)this.lexer.state.top=!1,u.items[e].tokens=this.lexer.blockTokens(u.items[e].text,[]),u.loose||(t=0<(t=u.items[e].tokens.filter(e=>"space"===e.type)).length&&t.some(e=>/\n.*\n/.test(e.raw)),u.loose=t);if(u.loose)for(let e=0;e<u.items.length;e++)u.items[e].loose=!0;return u}}html(e){e=this.rules.block.html.exec(e);if(e)return{type:"html",block:!0,raw:e[0],pre:"pre"===e[1]||"script"===e[1]||"style"===e[1],text:e[0]}}def(e){var t,n,r,e=this.rules.block.def.exec(e);if(e)return t=e[1].toLowerCase().replace(/\s+/g," "),n=e[2]?e[2].replace(/^<(.*)>$/,"$1").replace(this.rules.inline._escapes,"$1"):"",r=e[3]&&e[3].substring(1,e[3].length-1).replace(this.rules.inline._escapes,"$1"),{type:"def",tag:t,raw:e[0],href:n,title:r}}table(e){e=this.rules.block.table.exec(e);if(e){var i={type:"table",raw:e[0],header:k(e[1]).map(e=>({text:e,tokens:[]})),align:e[2].replace(/^ *|\| *$/g,"").split(/ *\| */),rows:e[3]&&e[3].trim()?e[3].replace(/\n[ \t]*$/,"").split("\n"):[]};if(i.header.length===i.align.length){let e=i.align.length,t,n,r,s;for(t=0;t<e;t++){var l=i.align[t];l&&(/^ *-+: *$/.test(l)?i.align[t]="right":/^ *:-+: *$/.test(l)?i.align[t]="center":/^ *:-+ *$/.test(l)?i.align[t]="left":i.align[t]=null)}for(e=i.rows.length,t=0;t<e;t++)i.rows[t]=k(i.rows[t],i.header.length).map(e=>({text:e,tokens:[]}));for(e=i.header.length,n=0;n<e;n++)i.header[n].tokens=this.lexer.inline(i.header[n].text);for(e=i.rows.length,n=0;n<e;n++)for(s=i.rows[n],r=0;r<s.length;r++)s[r].tokens=this.lexer.inline(s[r].text);return i}}}lheading(e){e=this.rules.block.lheading.exec(e);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(e){var t,e=this.rules.block.paragraph.exec(e);if(e)return t="\n"===e[1].charAt(e[1].length-1)?e[1].slice(0,-1):e[1],{type:"paragraph",raw:e[0],text:t,tokens:this.lexer.inline(t)}}text(e){e=this.rules.block.text.exec(e);if(e)return{type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(e){e=this.rules.inline.escape.exec(e);if(e)return{type:"escape",raw:e[0],text:c(e[1])}}tag(e){e=this.rules.inline.tag.exec(e);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){n=this.rules.inline.link.exec(n);if(n){var r=n[2].trim();if(!this.options.pedantic&&/^</.test(r)){if(!/>$/.test(r))return;var s=f(r.slice(0,-1),"\\");if((r.length-s.length)%2==0)return}else{var i,s=function(n,r){if(-1!==n.indexOf(r[1])){let t=0;for(let e=0;e<n.length;e++)if("\\"===n[e])e++;else if(n[e]===r[0])t++;else if(n[e]===r[1]&&--t<0)return e}return-1}(n[2],"()");-1<s&&(i=(0===n[0].indexOf("!")?5:4)+n[1].length+s,n[2]=n[2].substring(0,s),n[0]=n[0].substring(0,i).trim(),n[3]="")}let e=n[2],t="";return this.options.pedantic?(s=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(e))&&(e=s[1],t=s[3]):t=n[3]?n[3].slice(1,-1):"",e=e.trim(),d(n,{href:(e=/^</.test(e)?this.options.pedantic&&!/>$/.test(r)?e.slice(1):e.slice(1,-1):e)&&e.replace(this.rules.inline._escapes,"$1"),title:t&&t.replace(this.rules.inline._escapes,"$1")},n[0],this.lexer)}}reflink(t,n){let r;if(r=(r=this.rules.inline.reflink.exec(t))||this.rules.inline.nolink.exec(t)){let e=(r[2]||r[1]).replace(/\s+/g," ");return(e=n[e.toLowerCase()])?d(r,e,r[0],this.lexer):{type:"text",raw:t=r[0].charAt(0),text:t}}}emStrong(s,i,e=""){let l=this.rules.inline.emStrong.lDelim.exec(s);if(l&&((!l[3]||!e.match(/[\p{L}\p{N}]/u))&&(!(l[1]||l[2]||"")||!e||this.rules.inline.punctuation.exec(e)))){var a=[...l[0]].length-1;let e,t,n=a,r=0;var o,c,h="*"===l[0][0]?this.rules.inline.emStrong.rDelimAst:this.rules.inline.emStrong.rDelimUnd;for(h.lastIndex=0,i=i.slice(-1*s.length+a);null!=(l=h.exec(i));)if(e=l[1]||l[2]||l[3]||l[4]||l[5]||l[6])if(t=[...e].length,l[3]||l[4])n+=t;else if((l[5]||l[6])&&a%3&&!((a+t)%3))r+=t;else if(!(0<(n-=t)))return t=Math.min(t,t+n+r),o=[...s].slice(0,a+l.index+t+1).join(""),Math.min(a,t)%2?(c=o.slice(1,-1),{type:"em",raw:o,text:c,tokens:this.lexer.inlineTokens(c)}):(c=o.slice(2,-2),{type:"strong",raw:o,text:c,tokens:this.lexer.inlineTokens(c)})}}codespan(t){t=this.rules.inline.code.exec(t);if(t){let e=t[2].replace(/\n/g," ");var n=/[^ ]/.test(e),r=/^ /.test(e)&&/ $/.test(e);return e=c(e=n&&r?e.substring(1,e.length-1):e,!0),{type:"codespan",raw:t[0],text:e}}}br(e){e=this.rules.inline.br.exec(e);if(e)return{type:"br",raw:e[0]}}del(e){e=this.rules.inline.del.exec(e);if(e)return{type:"del",raw:e[0],text:e[2],tokens:this.lexer.inlineTokens(e[2])}}autolink(n){n=this.rules.inline.autolink.exec(n);if(n){let e,t;return t="@"===n[2]?"mailto:"+(e=c(n[1])):e=c(n[1]),{type:"link",raw:n[0],text:e,href:t,tokens:[{type:"text",raw:e,text:e}]}}}url(e){var n,r;if(n=this.rules.inline.url.exec(e)){let e,t;if("@"===n[2])e=c(n[0]),t="mailto:"+e;else{for(;r=n[0],n[0]=this.rules.inline._backpedal.exec(n[0])[0],r!==n[0];);e=c(n[0]),t="www."===n[1]?"http://"+n[0]:n[0]}return{type:"link",raw:n[0],text:e,href:t,tokens:[{type:"text",raw:e,text:e}]}}}inlineText(t){t=this.rules.inline.text.exec(t);if(t){let e;return e=this.lexer.state.inRawBlock?t[0]:c(t[0]),{type:"text",raw:t[0],text:e}}}}const x={newline:/^(?: *(?:\n|$))+/,code:/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,hr:/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,blockquote:/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,list:/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/,html:"^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<