mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-12-29 00:23:19 -05:00
11 lines
34 KiB
JavaScript
11 lines
34 KiB
JavaScript
|
!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(n){"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 t(e){n.defaults=e}n.defaults=e();const s=/[&<>"']/,Q=new RegExp(s.source,"g"),r=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,B=new RegExp(r.source,"g"),M={"&":"&","<":"<",">":">",'"':""","'":"'"},i=e=>M[e];function l(e,t){if(t){if(s.test(e))return e.replace(Q,i)}else if(r.test(e))return e.replace(B,i);return e}const O=/(^|[^\[])\^/g;function a(e,t){let s="string"==typeof e?e:e.source;t=t||"";const r={replace:(e,t)=>{let n="string"==typeof t?t:t.source;return n=n.replace(O,"$1"),s=s.replace(e,n),r},getRegex:()=>new RegExp(s,t)};return r}function o(e){try{e=encodeURI(e).replace(/%25/g,"%")}catch{return null}return e}var c={exec:()=>null};function h(e,t){const n=e.replace(/\|/g,(e,t,n)=>{let s=!1,r=t;for(;0<=--r&&"\\"===n[r];)s=!s;return s?"|":" |"}),s=n.split(/ \|/);let r=0;if(s[0].trim()||s.shift(),0<s.length&&!s[s.length-1].trim()&&s.pop(),t)if(s.length>t)s.splice(t);else for(;s.length<t;)s.push("");for(;r<s.length;r++)s[r]=s[r].trim().replace(/\\\|/g,"|");return s}function u(e,t,n){var s=e.length;if(0===s)return"";let r=0;for(;r<s;){var i=e.charAt(s-r-1);if(i!==t||n){if(i===t||!n)break;r++}else r++}return e.slice(0,s-r)}function j(e,t,n,s){var r=t.href,t=t.title?l(t.title):null,i=e[1].replace(/\\([\[\]])/g,"$1");return"!"!==e[0].charAt(0)?(s.state.inLink=!0,e={type:"link",raw:n,href:r,title:t,text:i,tokens:s.inlineTokens(i)},s.state.inLink=!1,e):{type:"image",raw:n,href:r,title:t,text:l(i)}}class m{options;rules;lexer;constructor(e){this.options=e||n.defaults}space(e){e=this.rules.block.newline.exec(e);if(e&&0<e[0].length)return{type:"space",raw:e[0]}}code(e){const t=this.rules.block.code.exec(e);if(t)return e=t[0].replace(/^ {1,4}/gm,""),{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?e:u(e,"\n")}}fences(e){const t=this.rules.block.fences.exec(e);var n;if(t)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+/);if(null===t)return e;var[t]=t;return t.length>=n.length?e.slice(n.length):e}).join("\n")}(e=t[0],t[3]||""),{type:"code",raw:e,lang:t[2]&&t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"),text:n}}heading(e){const t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(/#$/.test(e)){const n=u(e,"#");!this.options.pedantic&&n&&!/ $/.test(n)||(e=n.trim())}return{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:u(e[0],"\n")}}blockquote(e){e=this.rules.block.blockquote.exec(e);if(e){let n=u(e[0],"\n").split("\n"),s="",r="";const o=[];for(;0<n.length;){let e=!1;const c=[];let t;for(t=0;t<n.length;t++)if(/^ {0,3}>/.test(n[t]))c.push(n[t]),e=!0;else{if(e)break;c.push(n[t])}n=n.slice(t);const h=c.join("\n");var i=h.replace(/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,"\n $1").replace(/^ {0,3}>[ \t]?/gm,""),l=(s=s?s+`
|
||
|
`+h:h,r=r?r+`
|
||
|
`+i:i,this.lexer.state.top);if(this.lexer.state.top=!0,this.lexer.blockTokens(i,o,!0),this.lexer.state.top=l,0===n.length)break;i=o[o.length-1];if("code"===i?.type)break;if("blockquote"===i?.type){var l=i,a=l.raw+"\n"+n.join("\n"),a=this.blockquote(a);o[o.length-1]=a,s=s.substring(0,s.length-l.raw.length)+a.raw,r=r.substring(0,r.length-l.text.length)+a.text;break}if("list"===i?.type){l=i;const p=l.raw+"\n"+n.join("\n");a=this.list(p);o[o.length-1]=a,s=s.substring(0,s.length-i.raw.length)+a.raw,r=r.substring(0,r.length-l.raw.length)+a.raw,n=p.substring(o[o.length-1].raw.length).split("\n")}}return{type:"blockquote",raw:s,tokens:o,text:r}}}list(h){let p=this.rules.block.list.exec(h);if(p){let e=p[1].trim();var t=1<e.length;const g={type:"list",raw:"",ordered:t,start:t?+e.slice(0,-1):"",loose:!1,items:[]},k=(e=t?"\\d{1,9}\\"+e.slice(-1):"\\"+e,this.options.pedantic&&(e=t?e:"[*+-]"),new RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`));let c=!1;for(;h;){let e=!1,t="",n="";if(!(p=k.exec(h)))break;if(this.rules.block.hr.test(h))break;t=p[0],h=h.substring(t.length);let s=p[2].split("\n",1)[0].replace(/^\t+/,e=>" ".repeat(3*e.length)),r=h.split("\n",1)[0],i=!s.trim(),l=0;if(this.options.pedantic?(l=2,n=s.trimStart()):i?l=p[1].length+1:(l=4<(l=p[2].search(/[^ ]/))?1:l,n=s.slice(l),l+=p[1].length),i&&/^ *$/.test(r)&&(t+=r+"\n",h=h.substring(r.length+1),e=!0),!e){const f=new RegExp(`^ {0,${Math.min(3,l-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),d=new RegExp(`^ {0,${Math.min(3,l-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),x=new RegExp(`^ {0,${Math.min(3,l-1)}}(?:\`\`\`|~~~)`),b=new RegExp(`^ {0,${Math.min(3,l-1)}}#`);for(;h;){var u=h.split("\n",1)[0];if(r=u,this.options.pedantic&&(r=r.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),x.test(r))break;if(b.test(r))break;if(f.test(r))break;if(d.test(h))break;if(r.search(/[^ ]/)>=l||!r.trim())n+="\n"+r.slice(l);else{if(i)break;if(4<=s.search(/[^ ]/))break;if(x.test(s))break;if(b.test(s))break;if(d.test(s))break;n+="\n"+r}i||r.trim()||(i=!0),t+=u+"\n",h=h.substring(u.length+1),s=r.slice(l)}}g.loose||(c?g.loose=!0:/\n *\n *$/.test(t)&&(c=!0));let a=null,o;this.options.gfm&&(a=/^\[[ xX]\] /.exec(n))&&(o="[ ] "!==a[0],n=n.replace(/^\[[ xX]\] +/,"")),g.items.push({type:"list_item",raw:t,task:!!a,checked:o,loose:!1,text:n,tokens:[]}),g.raw+=t}g.items[g.items.length-1].raw=g.items[g.items.length-1].raw.trimEnd(),g.items[g.items.length-1].text=g.items[g.items.length-1].text.trimEnd(),g.raw=g.raw.trimEnd();for(let e=0;e<g.items.length;e++)if(this.lexer.state.top=!1,g.items[e].tokens=this.lexer.blockTokens(g.items[e].text,[]),!g.loose){const s=g.items[e].tokens.filter(e=>"space"===e.type);var n=0<s.length&&s.some(e=>/\n.*\n/.test(e.raw));g.loose=n}if(g.loose)for(let e=0;e<g.items.length;e++)g.items[e].loose=!0;return g}}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){const t=this.rules.block.def.exec(e);var n,s;if(t)return e=t[1].toLowerCase().replace(/\s+/g," "),n=t[2]?t[2].replace(/^<(.*)>$/,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",s=t[3]&&t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"),{type:"def",tag:e,raw:t[0],href:n,title:s}}table(e){const t=this.rules.block.table.exec(e);if(t&&/[:|]/.test(t[2])){var n=h(t[1]),e=t[2].replace(/^\||\| *$/g,"").split("|"),s=t[3]&&t[3].trim()?t[3].replace(/\n[ \t]*$/,"").split("\n"):[];const r={type:"table",raw:t[0],header:[],align:[],rows:[]};if(n.length===e.length){for(const i of e)/^ *-+: *$/.test(i)?r.align.push("right"):/^ *:-+: *$/.test(i)?r.align.push("center"):/^ *:-+ *$/.test(i)?r.align.push("left"):r.align.push(null);for(let e=0;e<n.length;e++)r.header.push({text:n[e],tokens:this.lexer.inline(n[e]),header:!0,align:r.align[e]});for(const l of s)r.rows.push(h(l,r.header.length).map((e,t)=>({text:e,tokens:this.lexer.inline(e),header:!1,align:r.align[t]})));return r}}}lheading(e){const t=this.rules.block.lheading.exec(e);if(t)return{type:"heading",raw:t[0],depth:"="===t[2].charAt(0)?1:2,text
|
||
|
${this.parser.parse(e)}</blockquote>
|
||
|
`}html({text:e}){return e}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>
|
||
|
`}hr(e){return"<hr>\n"}list(t){var e=t.ordered,n=t.start;let s="";for(let e=0;e<t.items.length;e++){var r=t.items[e];s+=this.listitem(r)}var i=e?"ol":"ul";return"<"+i+(e&&1!==n?' start="'+n+'"':"")+">\n"+s+"</"+i+">\n"}listitem(e){let t="";var n;return e.task&&(n=this.checkbox({checked:!!e.checked}),e.loose?0<e.tokens.length&&"paragraph"===e.tokens[0].type?(e.tokens[0].text=n+" "+e.tokens[0].text,e.tokens[0].tokens&&0<e.tokens[0].tokens.length&&"text"===e.tokens[0].tokens[0].type&&(e.tokens[0].tokens[0].text=n+" "+e.tokens[0].tokens[0].text)):e.tokens.unshift({type:"text",raw:n+" ",text:n+" "}):t+=n+" "),`<li>${t+=this.parser.parse(e.tokens,!!e.loose)}</li>
|
||
|
`}checkbox({checked:e}){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox">'}paragraph({tokens:e}){return`<p>${this.parser.parseInline(e)}</p>
|
||
|
`}table(t){var e="";let n="";for(let e=0;e<t.header.length;e++)n+=this.tablecell(t.header[e]);e+=this.tablerow({text:n});let s="";for(let e=0;e<t.rows.length;e++){var r=t.rows[e];n="";for(let e=0;e<r.length;e++)n+=this.tablecell(r[e]);s+=this.tablerow({text:n})}return"<table>\n<thead>\n"+e+"</thead>\n"+(s=s&&`<tbody>${s}</tbody>`)+"</table>\n"}tablerow({text:e}){return`<tr>
|
||
|
${e}</tr>
|
||
|
`}tablecell(e){var t=this.parser.parseInline(e.tokens),n=e.header?"th":"td";return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>
|
||
|
`}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${e}</code>`}br(e){return"<br>"}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:n}){var n=this.parser.parseInline(n),s=o(e);if(null===s)return n;let r='<a href="'+(e=s)+'"';return t&&(r+=' title="'+t+'"'),r+=">"+n+"</a>"}image({href:e,title:t,text:n}){var s=o(e);if(null===s)return n;let r=`<img src="${e=s}" alt="${n}"`;return t&&(r+=` title="${t}"`),r+=">"}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):e.text}}class E{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return""+e}image({text:e}){return""+e}br(){return""}}class q{options;renderer;textRenderer;constructor(e){this.options=e||n.defaults,this.options.renderer=this.options.renderer||new I,this.renderer=this.options.renderer,this.renderer.options=this.options,(this.renderer.parser=this).textRenderer=new E}static parse(e,t){const n=new q(t);return n.parse(e)}static parseInline(e,t){const n=new q(t);return n.parseInline(e)}parse(n,s=!0){let r="";for(let t=0;t<n.length;t++){var e=n[t];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[e.type]){var i=e,l=this.options.extensions.renderers[i.type].call({parser:this},i);if(!1!==l||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(i.type)){r+=l||"";continue}}var a=e;switch(a.type){case"space":r+=this.renderer.space(a);continue;case"hr":r+=this.renderer.hr(a);continue;case"heading":r+=this.renderer.heading(a);continue;case"code":r+=this.renderer.code(a);continue;case"table":r+=this.renderer.table(a);continue;case"blockquote":r+=this.renderer.blockquote(a);continue;case"list":r+=this.renderer.list(a);continue;case"html":r+=this.renderer.html(a);continue;case"paragraph":r+=this.renderer.paragraph(a);continue;case"text":{var o;let e=this.renderer.text(a);for(;t+1<n.length&&"text"===n[t+1].type;)o=n[++t],e+="\n"+this.renderer.text(o);r+=s?this.renderer.paragraph({type:"paragraph",raw:e,text:e,tokens:[{type:"text",raw:e,text:e}]}):e;continue}default:var c='Token with "'+a.type+'" type was not found.';if(this.options.silent)return console.error(c),"";throw new Error(c)}}return r}parseInline(t,n){n=n||this.renderer;let s="";for(let e=0;e<t.length;e++){var r=t[e];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[r.type]){var i=this.options.extensions.renderers[r.type].call({parser:this},r);if(!1!==i||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(r.type)){s+=i||"";continue}}var l=r;switch(l.type){case"escape":s+=n.text(l);break;case"html":s+=n.html(l);break;case"link":s+=n.link(l);break;case"image":s+=n.image(l);break;case"strong":s+=n.strong(l);break;case"em":s+=n.em(l);break;case"codespan":s+=n.codespan(l);break;case"br":s+=n.br(l);break;case"del":s+=n.del(l);break;case"text":s+=n.text(l);break;default:var a='Token with "'+l.type+'" type was not found.';if(this.options.silent)return console.error(a),"";throw new Error(a)}}return s}}class Z{options;constructor(e){this.options=e||n.defaults}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}}class H{defaults=e();options=this.setOptions;parse=this.parseMarkdown(S.lex,q.parse);parseInline=this.parseMarkdown(S.lexInline,q.parseInline);Parser=q;Renderer=I;TextRenderer=E;Lexer=S;Tokenizer=m;Hooks=Z;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(this,r)),r.type){case"table":var s=r;for(const i of s.header)n=n.concat(this.walkTokens(i.tokens,t));for(const l of s.rows)for(const a of l)n=n.concat(this.walkTokens(a.tokens,t));break;case"list":s=r;n=n.concat(this.walkTokens(s.items,t));break;default:{const o=r;this
|