UNPKG

smarkdown

Version:

Markdown parser, simplicity and extensibility.

2 lines (1 loc) 32.8 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).Smarkdown=t()}(this,function(){"use strict";var s=function(){return(s=Object.assign||function(e){for(var t,s=1,n=arguments.length;s<n;s++)for(var r in t=arguments[s])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)},n=/[&<>"']/,r=/[&<>"']/g,i={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},o=/[<>"']|&(?!#?\w+;)/,l=/[<>"']|&(?!#?\w+;)/g,t=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi;function e(e,t){if(t){if(n.test(e))return e.replace(r,function(e){return i[e]})}else if(o.test(e))return e.replace(l,function(e){return i[e]});return e}function h(e){return e.replace(t,function(e,t){return"colon"===(t=t.toLowerCase())?":":"#"===t.charAt(0)?"x"===t.charAt(1)?String.fromCharCode(parseInt(t.substring(2),16)):String.fromCharCode(+t.substring(1)):""})}var a=/<[!\/a-z](?:.|\n)*?>/gim,u=/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g,p=/(\s|\.)/g;function c(){this.seen={}}var g=new(c.prototype.slug=function(e,t){var s=e.trim().toLowerCase().replace(a,"").replace(u,"").replace(p,"-");if(!1!==t){if(this.seen.hasOwnProperty(s))for(var n=s;this.seen[n]++,s=n+"-"+this.seen[n],this.seen.hasOwnProperty(s););this.seen[s]=0}return s},c);function f(e,t,s){if(void 0===s&&(s=!1),0===e.length)return"";for(var n=0;n<e.length;){var r=e.charAt(e.length-n-1);if(r!==t||s){if(r===t||!s)break;n++}else n++}return e.substr(0,e.length-n)}var d=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i,k=/^[^:]+:\/*[^/]*$/,x=/^([^:]+:)[\s\S]*$/,b=/^([^:]+:\/*[^/]*)[\s\S]*$/,m={};function y(e,t){if(d.test(t))return t;var s=" "+e;m[s]||(k.test(e)?m[s]=e+"/":m[s]=f(e,"/",!0));var n=-1===(e=m[s]).indexOf(":");return"//"===t.slice(0,2)?n?t:e.replace(x,"$1")+t:"/"===t.charAt(0)?n?t:e.replace(b,"$1")+t:e+t}var R=/[^\w:]/g;function v(e,t,s){if(e){var n=void 0;try{n=decodeURIComponent(h(s)).replace(R,"").toLowerCase()}catch(e){return null}if(0===n.indexOf("javascript:")||0===n.indexOf("vbscript:")||0===n.indexOf("data:"))return null}t&&!d.test(s)&&(s=y(t,s));try{s=encodeURI(s).replace(/%25/g,"%")}catch(e){return null}return s}var w=/(^|[^\[])\^/g,_=(G.prototype.setGroup=function(e,t){var s="string"==typeof t?t:t.source;return s=s.replace(w,"$1"),this.source=this.source.replace(e,s),this},G.prototype.getRegex=function(){return new RegExp(this.source,this.flags)},G);function G(e,t){void 0===t&&(t=""),this.source=e.source,this.flags=t}var S=/S^/,$=/^\^\(*\\*./;function A(e){return e.source}function z(e){return-1<e.source.indexOf("\\n")}var O,E,L=/<!--(?!-?>)[\s\S]*?-->/;(E=O||(O={}))[E.blockquoteEnd=1]="blockquoteEnd",E[E.blockquoteStart=2]="blockquoteStart",E[E.code=3]="code",E[E.footnote=4]="footnote",E[E.heading=5]="heading",E[E.hr=6]="hr",E[E.html=7]="html",E[E.listEnd=8]="listEnd",E[E.listItemEnd=9]="listItemEnd",E[E.listItemStart=10]="listItemStart",E[E.listStart=11]="listStart",E[E.looseItemEnd=12]="looseItemEnd",E[E.looseItemStart=13]="looseItemStart",E[E.paragraph=14]="paragraph",E[E.raw=15]="raw",E[E.space=16]="space",E[E.table=17]="table",E[E.text=18]="text";var B=function(){this.baseUrl=null,this.breaks=!1,this.disabledRules=[],this.extra=!1,this.gfm=!0,this.headerId=!1,this.headerPrefix="",this.langAttribute=!1,this.langPrefix="language-",this.linksInNewTab=!1,this.mangle=!0,this.pedantic=!1,this.sanitize=!1,this.silent=!1,this.smartLists=!1,this.smartypants=!1,this.xhtml=!1,this.escape=e,this.unescape=h,this.slug=function(e,t){return g.slug(e,t)},this.rtrim=f,this.resolveUrl=y,this.cleanUrl=v,this.nop=!1},C={_comment:L,blockquote:/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,bullet:/(?:[*+-]|\d{1,9}\.)/,code:/^( {4}[^\n]+\n*)+/,def:/^ {0,3}\[(label)\]: *\n? *<?([^\s>]+)>?(?:(?: +\n? *| *\n *)(title))? *(?:\n+|$)/,fences:/^ {0,3}(`{3,}|~{3,})([^`~\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/,heading:/^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/,hr:/^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,html:new RegExp("^ {0,3}(?:<(script|pre|style)[\\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{2,}|$)|<(?!script|pre|style)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$)|</(?!script|pre|style)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:\\n{2,}|$))"),item:/^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/,lheading:/^([^\n]+)\n {0,3}(=+|-+) *(?:\n+|$)/,list:/^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,newline:/^\n+/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html)[^\n]+)*)/,text:/^[^\n]+/};C.def=new _(C.def).setGroup("label",/(?!\s*\])(?:\\[\[\]]|[^\[\]])+/).setGroup("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),C.item=new _(C.item,"gm").setGroup(/bull/g,C.bullet).getRegex(),C.list=new _(C.list).setGroup(/bull/g,C.bullet).setGroup("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").setGroup("def","\\n+(?="+C.def.source+")").getRegex();var q="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|options|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul";C.html=new _(C.html,"i").setGroup("comment",C._comment).setGroup("tag",q).setGroup("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),C.paragraph=new _(C._paragraph).setGroup("hr",C.hr).setGroup("heading"," {0,3}#{1,6} ").setGroup("|lheading","").setGroup("blockquote"," {0,3}>").setGroup("fences"," {0,3}(?:`{3,}|~{3,})[^`\\n]*\\n").setGroup("list"," {0,3}(?:[*+-]|1[.)]) ").setGroup("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)").setGroup("tag",q).getRegex(),C.blockquote=new _(C.blockquote).setGroup("paragraph",C.paragraph).getRegex();var T=new _(new RegExp("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:\"[^\"]*\"|'[^']*'|\\s[^'\"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))")).setGroup("comment",C._comment).setGroup(/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(),Z=s(s({},C),{def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^ *(#{1,6}) *([^\n]+?) *(?:#+ *)?(?:\n+|$)/,fences:S,paragraph:new _(C._paragraph).setGroup("hr",C.hr).setGroup("heading"," *#{1,6} *[^\n]").setGroup("lheading",C.lheading).setGroup("blockquote"," {0,3}>").setGroup("|fences","").setGroup("|list","").setGroup("|html","").getRegex(),html:T}),I=new _(new RegExp("^ *([^|\\n ].*\\|.*)\\n *([-:]+ *\\|[-| :]*)(?:\\n((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)")).setGroup("hr",C.hr).setGroup("heading"," {0,3}#{1,6} ").setGroup("blockquote"," {0,3}>").setGroup("code"," {4}[^\\n]").setGroup("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").setGroup("list"," {0,3}(?:[*+-]|1[.)]) ").setGroup("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)").setGroup("tag",q).getRegex(),P=new _(new RegExp("^ *\\|(.+)\\n *\\|?( *[-:]+[-| :]*)(?:\\n *((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)")).setGroup("hr",C.hr).setGroup("heading"," {0,3}#{1,6} ").setGroup("lheading","([^\\n]+)\\n {0,3}(=+|-+) *(?:\\n+|$)").setGroup("blockquote"," {0,3}>").setGroup("code"," {4}[^\\n]").setGroup("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").setGroup("list"," {0,3}(?:[*+-]|1[.)]) ").setGroup("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|!--)").setGroup("tag",q).getRegex(),j=s(s({},C),{checkbox:/^\[([ xX])\] +/,nptable:I,table:P}),U=s(s({},j),{paragraph:new _(j.paragraph).setGroup("footnote",/^\[\^([^\]]+)\]: *([^\n]*(?:\n+|$)(?: {1,}[^\n]*(?:\n+|$))*)/).getRegex(),footnote:/^\[\^([^\]]+)\]: ([^\n]+)/}),F={_escapes:/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,_label:/(?:\[[^\[\]]*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,br:/^( {2,}|\\)\n(?!\s*$)/,code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,em:/^_([^\s_])_(?!_)|^\*([^\s*<\[])\*(?!\*)|^_([^\s<][\s\S]*?[^\s_])_(?!_|[^\spunctuation])|^_([^\s_<][\s\S]*?[^\s])_(?!_|[^\spunctuation])|^\*([^\s<"][\s\S]*?[^\s\*])\*(?!\*|[^\spunctuation])|^\*([^\s*"<\[][\s\S]*?[^\s])\*(?!\*)/,escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,link:/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,nolink:/^!?\[(?!\s*\])((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\](?:\[\])?/,reflink:/^!?\[(label)\]\[(?!\s*\])((?:\\[\[\]]?|[^\[\]\\])+)\]/,strong:/^__([^\s_])__(?!_)|^\*\*([^\s*])\*\*(?!\*)|^__([^\s][\s\S]*?[^\s])__(?!_)|^\*\*([^\s][\s\S]*?[^\s])\*\*(?!\*)/,tag:new RegExp("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>"),text:/^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*]|\b_|$)|[^ ](?= {2,}\n))|(?= {2,}\n))/};F.em=new _(F.em).setGroup(/punctuation/g,"!\"#$%&'()*+,\\-./:;<=>?@\\[^_{|}~").getRegex(),F.autolink=new _(F.autolink).setGroup("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).setGroup("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(),F.tag=new _(F.tag).setGroup("comment",L).setGroup("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),F.link=new _(F.link).setGroup("label",F._label).setGroup("href",/<(?:\\[<>]?|[^\s<>\\])*>|[^\s\x00-\x1f]*/).setGroup("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),F.reflink=new _(F.reflink).setGroup("label",F._label).getRegex();var D=new _(/^!?\[(label)\]\((.*?)\)/).setGroup("label",F._label).getRegex(),N=new _(/^!?\[(label)\]\s*\[([^\]]*)\]/).setGroup("label",F._label).getRegex(),M=s(s({},F),{em:/^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/,link:D,reflink:N,strong:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/}),W=new _(F.escape).setGroup("])","~|])").getRegex(),X=new _(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,"i").setGroup("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),H=s(s({},F),{_backpedal:/(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,del:/^~~(?=\S)([\s\S]*?\S)~~/,escape:W,text:/^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*~]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))|(?= {2,}\n|[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))/,url:X}),J=s(s({},H),{br:new _(H.br).setGroup("{2,}","*").getRegex(),text:new _(H.text).setGroup("\\b_","\\b_| {2,}\\n").setGroup(/\{2,\}/g,"*").getRegex()}),K={fnref:new _(/^!?\[\^(label)\]/).setGroup("label",H._label).getRegex()},Q=(V.lex=function(e,t,s){return new this(this,t).getTokens(e,s)},V.setRule=function(e,t,s){void 0===s&&(s={});var n=A(e);V.newRules.some(function(e){return e.type===n})&&this.unsetRule(e),V.newRules.push({options:s,rule:e,type:n}),this.blockRenderers.push({renderer:t,type:n})},V.unsetRule=function(e){var t=A(e);V.newRules=V.newRules.filter(function(e){return e.type!==t}),this.blockRenderers=this.blockRenderers.filter(function(e){return e.type!==t})},V.getBaseRules=function(){return this.baseRules?this.baseRules:this.baseRules=C},V.getPedanticRules=function(){return this.pedanticRules?this.pedanticRules:this.pedanticRules=Z},V.getGfmRules=function(){return this.gfmRules?this.gfmRules:this.gfmRules=j},V.getExtraRules=function(){return this.extraRules?this.extraRules:this.extraRules=U},V.prototype.setRules=function(){var t=this;this.options.pedantic?this.rules=this.self.getPedanticRules():this.options.extra?this.rules=this.self.getExtraRules():this.options.gfm?this.rules=this.self.getGfmRules():this.rules=this.self.getBaseRules(),this.options.disabledRules.forEach(function(e){t.rules[e]=S}),this.isGfm=void 0!==this.rules.fences,this.isExtra=void 0!==this.rules.footnote},V.prototype.getTokens=function(e,t){var s,n=e,r=this.self.newRules||[],i=r.filter(function(e){return e.options.priority}).sort(function(e,t){return t.options.priority-e.options.priority}),o=r.filter(function(e){return!e.options.priority});e:for(;n;){(s=this.rules.newline.exec(n))&&(n=n.substring(s[0].length),1<s[0].length&&this.tokens.push({type:O.space}));for(var l=0,h=i;l<h.length;l++)if(s=(C=h[l]).rule.exec(n)){n=n.substring(s[0].length),this.tokens.push({type:C.type,execArr:s});continue e}if(s=this.rules.code.exec(n)){var a=this.tokens[this.tokens.length-1];if(n=n.substring(s[0].length),a&&"paragraph"===a.type)a.text+="\n"+s[0].trimRight();else{var u=s[0].replace(/^ {4}/gm,"");this.tokens.push({type:O.code,codeBlockStyle:"indented",text:this.options.pedantic?u:this.options.rtrim(u,"\n")})}}else if(this.isGfm&&(s=this.rules.fences.exec(n)))n=n.substring(s[0].length),this.tokens.push({type:O.code,lang:s[2]?s[2].trim():s[2],text:s[3]||""});else if(this.isExtra&&(s=this.rules.footnote.exec(n))){n=n.substring(s[0].length);var p={type:O.footnote,refname:this.options.slug(s[1],!1),text:s[2]};this.tokens.push(p)}else if(s=this.rules.heading.exec(n))n=n.substring(s[0].length),this.tokens.push({type:O.heading,depth:s[1].length,text:s[2],ends:s[3]||""});else{if(this.isGfm&&(s=this.rules.nptable.exec(n))&&(p={type:O.table,header:this.splitCells(s[1].replace(/^ *| *\| *$/g,"")),align:s[2].replace(/^ *|\| *$/g,"").split(/ *\| */),cells:[]}).header.length===p.align.length){n=n.substring(s[0].length);for(var c=0;c<p.align.length;c++)/^ *-+: *$/.test(p.align[c])?p.align[c]="right":/^ *:-+: *$/.test(p.align[c])?p.align[c]="center":/^ *:-+ *$/.test(p.align[c])?p.align[c]="left":p.align[c]=null;var g=s[3]?s[3].replace(/\n$/,"").split("\n"):[];for(c=0;c<g.length;c++)p.cells[c]=this.splitCells(g[c],p.header.length);this.tokens.push(p);continue}if(s=this.rules.hr.exec(n))n=n.substring(s[0].length),this.tokens.push({type:O.hr,text:s[0]});else if(s=this.rules.blockquote.exec(n)){n=n.substring(s[0].length),this.tokens.push({type:O.blockquoteStart});var f=s[0].replace(/^ *> ?/gm,"");this.getTokens(f,t),this.tokens.push({type:O.blockquoteEnd})}else if(s=this.rules.list.exec(n)){n=n.substring(s[0].length);var d=s[2],k=1<d.length,x={type:O.listStart,ordered:k,start:k?+d:"",loose:!1};this.tokens.push(x);var b=s[0].match(this.rules.item),m=[],y=b.length,R=!1,v=void 0,w=void 0,_=void 0,G=void(p=void 0);for(c=0;c<y;c++){G=null,v=(p=b[c]).length,p=p.replace(/^ *([*+-]|\d+\.) */,""),this.isGfm&&(s=this.rules.checkbox.exec(p))&&(G=" "!==s[1],p=p.replace(this.rules.checkbox,"")),-1!==p.indexOf("\n ")&&(v-=p.length,p=this.options.pedantic?p.replace(/^ {1,4}/gm,""):p.replace(new RegExp("^ {1,"+v+"}","gm"),"")),c!==y-1&&(w=this.self.getBaseRules().bullet.exec(b[c+1])[0],(1<d.length?1===w.length:1<w.length||this.options.smartLists&&w!==d)&&(n=b.slice(c+1).join("\n")+n,c=y-1)),_=R||/\n\n(?!\s*$)/.test(p),c!==y-1&&(R="\n"===p.charAt(p.length-1),_||(_=R)),_&&(x.loose=!0);var S={loose:_,checked:G,type:O.listItemStart};m.push(S),this.tokens.push(S),this.getTokens(p,!1),this.tokens.push({type:O.listItemEnd})}if(x.loose)for(c=0;c<m.length;c++)m[c].loose=!0;this.tokens.push({type:O.listEnd})}else if(s=this.rules.html.exec(n)){n=n.substring(s[0].length);var $=s[1],A="pre"===$||"script"===$||"style"===$;this.tokens.push({type:this.options.sanitize?O.paragraph:O.html,pre:!this.options.sanitizer&&A,text:this.options.sanitize?this.options.sanitizer?this.options.sanitizer(s[0]):escape(s[0]):s[0]})}else if(t&&(s=this.rules.def.exec(n))){n=n.substring(s[0].length);var z=s[1].toLowerCase().replace(/\s+/g," ");if(!this.links[z]){var E=s[3];E&&(E=E.substring(1,E.length-1)),this.links[z]={title:E,href:s[2]}}}else{if(this.isGfm&&(s=this.rules.table.exec(n))&&(p={type:O.table,header:this.splitCells(s[1].replace(/^ *| *\| *$/g,"")),align:s[2].replace(/^ *|\| *$/g,"").split(/ *\| */),cells:[]}).header.length===p.align.length){for(n=n.substring(s[0].length),c=0;c<p.align.length;c++)/^ *-+: *$/.test(p.align[c])?p.align[c]="right":/^ *:-+: *$/.test(p.align[c])?p.align[c]="center":/^ *:-+ *$/.test(p.align[c])?p.align[c]="left":p.align[c]=null;for(g=s[3]?s[3].replace(/\n$/,"").split("\n"):[],c=0;c<g.length;c++)p.cells[c]=this.splitCells(g[c].replace(/^ *\| *| *\| *$/g,""),p.header.length);this.tokens.push(p);continue}for(var L=0,B=o;L<B.length;L++){var C;if(s=(C=B[L]).rule.exec(n)){n=n.substring(s[0].length),this.tokens.push({type:C.type,execArr:s});continue e}}if(s=this.rules.lheading.exec(n))n=n.substring(s[0].length),this.tokens.push({type:O.heading,depth:"="===s[2].charAt(0)?1:2,text:s[1]});else if(t&&(s=this.rules.paragraph.exec(n)))n=n.substring(s[0].length),"\n"===s[1].slice(-1)?this.tokens.push({type:O.paragraph,text:s[1].slice(0,-1)}):this.tokens.push({type:0<this.tokens.length?O.paragraph:O.text,text:s[1]});else if(s=this.rules.text.exec(n))n=n.substring(s[0].length),this.tokens.push({type:O.text,text:s[0]});else if(n)throw new Error("Infinite loop on byte: "+n.charCodeAt(0)+", near text '"+n.slice(0,30)+"...'")}}}return{tokens:this.tokens,links:this.links}},V.prototype.splitCells=function(e,t){var s=e.replace(/\|/g,function(e,t,s){for(var n=!1,r=t;0<=--r&&"\\"===s[r];)n=!n;return n?"|":" |"}).split(/ \|/);if(s.length>t)s.splice(t);else for(;s.length<t;)s.push("");for(var n=0;n<s.length;n++)s[n]=s[n].trim().replace(/\\\|/g,"|");return s},V.blockRenderers=[],V.newRules=[],V);function V(e,t){this.self=e,this.links=Object.create(null),this.tokens=[],this.options=t,this.setRules()}var Y=(ee.prototype.blockquote=function(e){return"<blockquote>\n"+e+"</blockquote>\n"},ee.prototype.code=function(e,t,s){var n=(t||"").match(/\S*/)[0];if(this.options.highlight){var r=this.options.highlight(e,n);null!==r&&r!==e&&(s=!0,e=r)}return n?"<pre"+(this.options.langAttribute?' data-lang="'+this.options.escape(n,!0)+'"':"")+'><code class="'+this.options.langPrefix+this.options.escape(n,!0)+'">'+(s?e:this.options.escape(e,!0))+"</code></pre>\n":"<pre><code>"+(s?e:this.options.escape(e,!0))+"</code></pre>"},ee.prototype.footnote=function(e){for(var t='<div class="footnotes" role="doc-endnotes">'+this.hr()+"<ol>",s=0,n=this._footnotes;s<n.length;s++){var r=n[s];t+='<li id="fn:'+r+'" role="doc-endnote"><span class="cite-text">'+(e[r]||"?")+'</span><a href="#fnref:'+r+'" class="footnote-backref" role="doc-backlink">&#8617;</a></li>'}return t+="</ol></div>",this._footnotes=[],t},ee.prototype.heading=function(e,t,s,n){var r=this.options.headerId,i="";if(!0===r||"off"===r&&n||"on"===r&&!n){var o=this.options.slug(s),l=this._headings.filter(function(e){return e===s}).length;0<l&&(o+="-"+l),i+=' id="'+this.options.headerPrefix+o+'"',this._headings.push(s)}return"<h"+t+i+">"+e+"</h"+t+">\n"},ee.prototype.hr=function(e){return this.options.xhtml?"<hr/>\n":"<hr>\n"},ee.prototype.html=function(e){return e},ee.prototype.list=function(e,t,s,n){var r=t?"ol":"ul",i=t&&1!==s?' start="'+s+'"':"";return n&&(i+=' class="task-list"'),"<"+r+i+">\n"+e+"</"+r+">\n"},ee.prototype.listitem=function(e,t){return null===t?"<li>"+e+"</li>\n":'<li class="task-list-item"><input type="checkbox" class="task-list-item-checkbox"'+(t?" checked":"")+" disabled> "+e+"</li>\n"},ee.prototype.paragraph=function(e){return"<p>"+e+"</p>\n"},ee.prototype.table=function(e,t){return t&&(t="<tbody>"+t+"</tbody>"),"\n<table>\n<thead>\n"+e+"</thead>\n"+t+"</table>\n"},ee.prototype.tablerow=function(e){return"<tr>\n"+e+"</tr>\n"},ee.prototype.tablecell=function(e,t){var s=t.header,n=t.align,r=s?"th":"td";return(n?"<"+r+' align="'+n+'">':"<"+r+">")+e+"</"+r+">\n"},ee.prototype.br=function(){return this.options.xhtml?"<br/>":"<br>"},ee.prototype.codespan=function(e){return"<code>"+e+"</code>"},ee.prototype.del=function(e){return"<del>"+e+"</del>"},ee.prototype.em=function(e){return"<em>"+e+"</em>"},ee.prototype.fnref=function(e){return-1===this._footnotes.indexOf(e)&&this._footnotes.push(e),'<sup id="fnref:'+e+'"><a href="#fn:'+e+'" class="footnote-ref" role="doc-noteref">'+this._footnotes.length+"</a></sup>"},ee.prototype.image=function(e,t,s){if(null===(e=this.options.cleanUrl(this.options.sanitize,this.options.baseUrl,e)))return s;var n='<img src="'+e+'" alt="'+s+'"';return t&&(n+=' title="'+t+'"'),n+=this.options.xhtml?"/>":">"},ee.prototype.link=function(e,t,s){if(null===(e=this.options.cleanUrl(this.options.sanitize,this.options.baseUrl,e)))return s;var n='<a href="'+this.options.escape(e)+'"';t&&(n+=' title="'+t+'"');var r=this.options,i=r.linksInNewTab,o=r.trimLinkText,l=!0===i||"function"==typeof i&&i.call(this,e);return"string"==typeof l?n+=l:l&&(n+=' target="_blank"'),o&&(s=o(s)),n+=">"+s+"</a>"},ee.prototype.strong=function(e){return"<strong>"+e+"</strong>"},ee.prototype.text=function(e){return e},ee);function ee(e){this._footnotes=[],this._headings=[],this.options=e||{}}var te=(se.prototype.br=function(){return""},se.prototype.html=function(e){return e},se.prototype.codespan=function(e){return e},se.prototype.del=function(e){return e},se.prototype.em=function(e){return e},se.prototype.image=function(e,t,s){return""+s},se.prototype.link=function(e,t,s){return""+s},se.prototype.strong=function(e){return e},se.prototype.text=function(e){return e},se);function se(){}var ne=(re.output=function(e,t,s){return new this(this,t,s).output(e)},re.setRule=function(e,t,s){void 0===s&&(s={});var n=A(e);this.newRules.some(function(e){return e.type!==n})&&this.unsetRule(e),this.newRules.push({breakChar:function(e){return e.source.match($)[0].slice(1)}(e),options:s,render:t,rule:e,type:n}),this.isTextBreakSync=!1},re.unsetRule=function(e){var t=A(e);re.newRules=re.newRules.filter(function(e){return e.type!==t}),this.isTextBreakSync=!1},re.getBaseRules=function(){return this.baseRules?this.baseRules:this.baseRules=F},re.getPedanticRules=function(){return this.pedanticRules?this.pedanticRules:this.pedanticRules=M},re.getGfmRules=function(){return this.gfmRules?this.gfmRules:this.gfmRules=H},re.getBreaksRules=function(){return this.breaksRules?this.breaksRules:this.breaksRules=J},re.getExtraRules=function(e){if(this.extraRules)return this.extraRules;var t=e.breaks?this.getBreaksRules():this.getGfmRules();return this.extraRules=s(s({},t),K)},re.prototype.setRules=function(){var t=this;if(this.options.pedantic?this.rules=this.self.getPedanticRules():this.options.extra?this.rules=this.self.getExtraRules(this.options):this.options.gfm?this.rules=this.options.breaks?this.self.getBreaksRules():this.self.getGfmRules():this.rules=this.self.getBaseRules(),!this.self.isTextBreakSync){var e=this.rules.text.source;this.defaultTextBreak||(this.defaultTextBreak=e.match(/\?=\[(.+?)\]/)[1]);var s=this.defaultTextBreak+re.newRules.filter(function(e){return-1===t.defaultTextBreak.indexOf(e.breakChar)}).map(function(e){return e.breakChar}).filter(function(e,t,s){return s.indexOf(e)===t}).join("");this.rules.text=new RegExp(e.replace(this.defaultTextBreak,s))}this.options.disabledRules.forEach(function(e){t.rules[e]=S}),this.isGfm=void 0!==this.rules.url,this.isExtra=void 0!==this.rules.fnref},re.prototype.escapes=function(e){return e?e.replace(this.rules._escapes,"$1"):e},re.prototype.findClosingBracket=function(e,t){if(-1===e.indexOf(t[1]))return-1;for(var s=0,n=0;n<e.length;n++)if("\\"===e[n])n++;else if(e[n]===t[0])s++;else if(e[n]===t[1]&&--s<0)return n;return-1},re.prototype.output=function(e){for(var t,s="",n=[e,e],r=[],i=[],o=0,l=this.self.newRules.sort(this.sortByPriority)||[];o<l.length;o++)(y=l[o]).options.priority?r.push(y):i.push(y);e:for(;e;)if(t=this.rules.escape.exec(e))e=e.substring(t[0].length),s+=this.options.escape(t[1]);else{for(var h=0,a=r;h<a.length;h++)if((t=(y=a[h]).rule.exec(e))&&(n[0]=n[1],n[1]=e,!y.options.checkPreChar||y.options.checkPreChar(n[0].charAt(n[0].length-e.length-1)))){e=e.substring(t[0].length),s+=y.render.call(this,t);continue e}if(t=this.rules.tag.exec(e))!this.inLink&&/^<a /i.test(t[0])?this.inLink=!0:this.inLink&&/^<\/a>/i.test(t[0])&&(this.inLink=!1),!this.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(t[0])?this.inRawBlock=!0:this.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(t[0])&&(this.inRawBlock=!1),e=e.substring(t[0].length),s+=this.renderer.html(this.options.sanitize?this.options.sanitizer?this.options.sanitizer.call(this,t[0]):this.options.escape(t[0]):t[0]);else if(t=this.rules.link.exec(e)){var u=this.findClosingBracket(t[2],"()");if(-1<u){var p=(0===t[0].indexOf("!")?5:4)+t[1].length+u;t[2]=t[2].substring(0,u),t[0]=t[0].substring(0,p).trim(),t[3]=""}e=e.substring(t[0].length),this.inLink=!0;var c=t[2],g=void 0;g=this.options.pedantic?(f=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(c))?(c=f[1],f[3]):"":t[3]?t[3].slice(1,-1):"",c=c.trim().replace(/^<([\s\S]*)>$/,"$1"),s+=this.outputLink(t,{href:this.escapes(c),title:this.escapes(g)}),this.inLink=!1}else if(this.isExtra&&(t=this.rules.fnref.exec(e)))e=e.substring(t[0].length),s+=this.renderer.fnref(this.options.slug(t[1]));else if((t=this.rules.reflink.exec(e))||(t=this.rules.nolink.exec(e))){e=e.substring(t[0].length);var f,d=(t[2]||t[1]).replace(/\s+/g," ");if(!(f=this.links[d.toLowerCase()])||!f.href){s+=t[0].charAt(0),e=t[0].substring(1)+e;continue}this.inLink=!0,s+=this.outputLink(t,f),this.inLink=!1}else if(t=this.rules.strong.exec(e))e=e.substring(t[0].length),s+=this.renderer.strong(this.output(t[4]||t[3]||t[2]||t[1]));else if(t=this.rules.em.exec(e))e=e.substring(t[0].length),s+=this.renderer.em(this.output(t[6]||t[5]||t[4]||t[3]||t[2]||t[1]));else if(t=this.rules.code.exec(e))e=e.substring(t[0].length),s+=this.renderer.codespan(this.options.escape(t[2].trim(),!0));else if(t=this.rules.br.exec(e))e=e.substring(t[0].length),s+=this.renderer.br();else if(this.isGfm&&(t=this.rules.del.exec(e)))e=e.substring(t[0].length),s+=this.renderer.del(this.output(t[1]));else if(t=this.rules.autolink.exec(e)){var k=void 0;c=void 0,e=e.substring(t[0].length),c="@"===t[2]?"mailto:"+(k=this.options.escape(this.mangle(t[1]))):k=this.options.escape(t[1]),s+=this.renderer.link(c,null,k)}else if(!this.inLink&&this.isGfm&&(t=this.rules.url.exec(e))){var x=c=k=void 0;if("@"===t[2])c="mailto:"+(k=this.options.escape(t[0]));else{for(;x=t[0],t[0]=this.rules._backpedal.exec(t[0])[0],x!==t[0];);k=this.options.escape(t[0]),c="www."===t[1]?"http://"+k:k}e=e.substring(t[0].length),s+=this.renderer.link(c,null,k)}else{for(var b=0,m=i;b<m.length;b++){var y;if((t=(y=m[b]).rule.exec(e))&&(n[0]=n[1],n[1]=e,!y.options.checkPreChar||y.options.checkPreChar(n[0].charAt(n[0].length-e.length-1)))){e=e.substring(t[0].length),s+=y.render.call(this,t);continue e}}if(t=this.rules.text.exec(e))e=e.substring(t[0].length),this.inRawBlock?s+=this.renderer.text(this.options.sanitize?this.options.sanitizer?this.options.sanitizer(t[0]):escape(t[0]):t[0]):s+=this.renderer.text(this.options.escape(this.smartypants(t[0])));else if(e)throw new Error("Infinite loop on byte: "+e.charCodeAt(0))}}return s},re.prototype.outputLink=function(e,t){var s=t.href,n=t.title?this.options.escape(t.title):null;return"!"!==e[0].charAt(0)?this.renderer.link(s,n,this.output(e[1])):this.renderer.image(s,n,this.options.escape(e[1]))},re.prototype.smartypants=function(e){return this.options.smartypants?e.replace(/---/g,"—").replace(/--/g,"–").replace(/(^|[-\u2014/(\[{"\s])'/g,"$1‘").replace(/'/g,"’").replace(/(^|[-\u2014/(\[{\u2018\s])"/g,"$1“").replace(/"/g,"”").replace(/\.{3}/g,"…"):e},re.prototype.mangle=function(e){if(!this.options.mangle)return e;for(var t="",s=0;s<e.length;s++){var n=e.charCodeAt(s);.5<Math.random()&&(n="x"+n.toString(16)),t+="&#"+n+";"}return t},re.isTextBreakSync=!0,re.newRules=[],re);function re(e,t,s,n){void 0===t&&(t={}),this.self=e,this.links=t,this.options=s,this.sortByPriority=function(e,t){return t.options.priority-e.options.priority},this.renderer=n||this.options.renderer||new Y(this.options),this.renderer.options=this.options,this.setRules()}var ie=(oe.parse=function(e,t,s){return new this(s).parse(t,e)},oe.prototype.parse=function(e,t){this.inlineLexer=new ne(ne,e,this.options,this.renderer),this.inlineTextLexer=new ne(ne,e,this.textOptions),this.tokens=t.reverse();for(var s="";this.next();)s+=this.tok();return Object.keys(this.footnotes).length&&(s+=this.renderer.footnote(this.footnotes),this.footnotes={}),this.renderer._headings=[],s},oe.prototype.next=function(){return this.token=this.tokens.pop(),this.token},oe.prototype.peek=function(){return this.tokens[this.tokens.length-1]||{type:""}},oe.prototype.parseText=function(){for(var e=this.token.text;this.peek().type===O.text;)e+="\n"+this.next().text;return this.inlineLexer.output(e)},oe.prototype.tok=function(){switch(this.token.type){case O.space:return"";case O.paragraph:return this.renderer.paragraph(this.inlineLexer.output(this.token.text));case O.text:return this.options.nop?this.parseText():this.renderer.paragraph(this.parseText());case O.heading:return this.renderer.heading(this.inlineLexer.output(this.token.text),this.token.depth,this.options.unescape(this.inlineTextLexer.output(this.token.text)),this.token.ends);case O.listStart:for(var e="",t=this.token.ordered,s=this.token.start,n=!1;this.next().type!==O.listEnd;)null!==this.token.checked&&(n=!0),e+=this.tok();return this.renderer.list(e,t,s,n);case O.listItemStart:e="";var r=this.token.loose,i=this.token.checked;for((n=null!==i)&&r&&(g=this.peek()).type===O.text&&(g.text=this.inlineLexer.output(g.text),g.type=O.raw);this.next().type!==O.listItemEnd;)e+=r||this.token.type!==O.text?this.tok():this.parseText();return this.renderer.listitem(e,i);case O.footnote:return this.footnotes[this.token.refname]=this.inlineLexer.output(this.token.text),"";case O.code:return this.renderer.code(this.token.text,this.token.lang,this.token.escaped);case O.table:for(var o="",l=e="",h=void 0,a=0;a<this.token.header.length;a++){var u={header:!0,align:this.token.align[a]},p=this.inlineLexer.output(this.token.header[a]);l+=this.renderer.tablecell(p,u)}for(o+=this.renderer.tablerow(l),a=0;a<this.token.cells.length;a++){h=this.token.cells[a],l="";for(var c=0;c<h.length;c++)l+=this.renderer.tablecell(this.inlineLexer.output(h[c]),{header:!1,align:this.token.align[c]});e+=this.renderer.tablerow(l)}return this.renderer.table(o,e);case O.blockquoteStart:e="";for(var g=void 0;(g=this.next())&&g.type!==O.blockquoteEnd;)e+=this.tok();return this.renderer.blockquote(e);case O.hr:return this.renderer.hr(this.token.text);case O.html:return this.renderer.html(this.token.text);case O.raw:return this.token.text;default:for(var f=0,d=this.blockRenderers;f<d.length;f++){var k=d[f];if(this.token.type===k.type)return k.renderer.call(this.renderer,this.token.execArr)}var x='Smarkdown: token with "'+this.token.type+'" type was not found.';if(!this.options.silent)throw new Error(x);console.log(x)}},oe);function oe(e){this.footnotes={},this.blockRenderers=[],this.tokens=[],this.token=null,this.options=e,this.renderer=this.options.renderer||new Y(this.options),this.renderer.options=this.options,this.textOptions=Object.assign({},this.options,{renderer:new te})}function le(){}return le.getOptions=function(e){return e?("function"==typeof e.renderer&&(e.renderer=new e.renderer(this.options)),s(s({},this.options),e)):this.options},le.setOptions=function(e){this.options=this.getOptions(e)},le.resetOptions=function(){this.options=new B},le.resolveRule=function(e){var t=e;return t.source.startsWith("^")||(t=new RegExp("^"+t.source)),t},le.setRule=function(e,t,s){void 0===s&&(s={}),z(e=this.resolveRule(e))?Q.setRule(e,t,s):ne.setRule(e,t,s)},le.unsetRule=function(e){z(e=this.resolveRule(e))?Q.unsetRule(e):ne.unsetRule(e)},le.inlineParse=function(e,t){return new ne(ne,{},this.getOptions(t)).output(e)},le.parse=function(e,t){try{var s=this.getOptions(t),n=this.callBlockLexer(e,s),r=n.tokens,i=n.links;return this.callParser(r,i,s)}catch(e){return this.callError(e)}},le.callBlockLexer=function(e,t){if(void 0===e&&(e=""),"string"!=typeof e)throw new Error("Smarkdown: Expected that the 'src' parameter would have a 'string' type, got '"+typeof e+"'");return e=e.replace(/\r\n|\r/g,"\n").replace(/\t/g," ").replace(/^ +$/gm,""),Q.lex(e,t,!0)},le.callParser=function(e,t,s){if(Q.blockRenderers.length){var n=new ie(s);return n.blockRenderers=Q.blockRenderers,n.parse(t,e)}return ie.parse(e,t,s)},le.callError=function(e){if(this.options.silent)return"<p>An error occurred:</p><pre>"+this.options.escape(e.message+"",!0)+"</pre>";throw e},le.BlockLexer=Q,le.InlineLexer=ne,le.options=new B,le.Parser=ie,le.Renderer=Y,le});