showdown.js 29 KB

1
  1. function getDefaultOpts(e){"use strict";var r={omitExtraWLInCodeBlocks:{defaultValue:!1,describe:"Omit the default extra whiteline added to code blocks",type:"boolean"},noHeaderId:{defaultValue:!1,describe:"Turn on/off generated header id",type:"boolean"},prefixHeaderId:{defaultValue:!1,describe:"Specify a prefix to generated header ids",type:"string"},headerLevelStart:{defaultValue:!1,describe:"The header blocks level start",type:"integer"},parseImgDimensions:{defaultValue:!1,describe:"Turn on/off image dimension parsing",type:"boolean"},simplifiedAutoLink:{defaultValue:!1,describe:"Turn on/off GFM autolink style",type:"boolean"},literalMidWordUnderscores:{defaultValue:!1,describe:"Parse midword underscores as literal underscores",type:"boolean"},strikethrough:{defaultValue:!1,describe:"Turn on/off strikethrough support",type:"boolean"},tables:{defaultValue:!1,describe:"Turn on/off tables support",type:"boolean"},tablesHeaderId:{defaultValue:!1,describe:"Add an id to table headers",type:"boolean"},ghCodeBlocks:{defaultValue:!0,describe:"Turn on/off GFM fenced code blocks support",type:"boolean"},tasklists:{defaultValue:!1,describe:"Turn on/off GFM tasklist support",type:"boolean"},smoothLivePreview:{defaultValue:!1,describe:"Prevents weird effects in live previews due to incomplete input",type:"boolean"},smartIndentationFix:{defaultValue:!1,description:"Tries to smartly fix identation in es6 strings",type:"boolean"}};if(!1===e)return JSON.parse(JSON.stringify(r));var t={};for(var n in r)r.hasOwnProperty(n)&&(t[n]=r[n].defaultValue);return t}var showdown={},parsers={},extensions={},globalOptions=getDefaultOpts(!0),flavor={github:{omitExtraWLInCodeBlocks:!0,prefixHeaderId:"user-content-",simplifiedAutoLink:!0,literalMidWordUnderscores:!0,strikethrough:!0,tables:!0,tablesHeaderId:!0,ghCodeBlocks:!0,tasklists:!0},vanilla:getDefaultOpts(!0)};function validate(e,r){"use strict";var t=r?"Error in "+r+" extension->":"Error in unnamed extension",n={valid:!0,error:""};showdown.helper.isArray(e)||(e=[e]);for(var s=0;s<e.length;++s){var o=t+" sub-extension "+s+": ",a=e[s];if("object"!=typeof a)return n.valid=!1,n.error=o+"must be an object, but "+typeof a+" given",n;if(!showdown.helper.isString(a.type))return n.valid=!1,n.error=o+'property "type" must be a string, but '+typeof a.type+" given",n;var i=a.type=a.type.toLowerCase();if("language"===i&&(i=a.type="lang"),"html"===i&&(i=a.type="output"),"lang"!==i&&"output"!==i&&"listener"!==i)return n.valid=!1,n.error=o+"type "+i+' is not recognized. Valid values: "lang/language", "output/html" or "listener"',n;if("listener"===i){if(showdown.helper.isUndefined(a.listeners))return n.valid=!1,n.error=o+'. Extensions of type "listener" must have a property called "listeners"',n}else if(showdown.helper.isUndefined(a.filter)&&showdown.helper.isUndefined(a.regex))return n.valid=!1,n.error=o+i+' extensions must define either a "regex" property or a "filter" method',n;if(a.listeners){if("object"!=typeof a.listeners)return n.valid=!1,n.error=o+'"listeners" property must be an object but '+typeof a.listeners+" given",n;for(var c in a.listeners)if(a.listeners.hasOwnProperty(c)&&"function"!=typeof a.listeners[c])return n.valid=!1,n.error=o+'"listeners" property must be an hash of [event name]: [callback]. listeners.'+c+" must be a function but "+typeof a.listeners[c]+" given",n}if(a.filter){if("function"!=typeof a.filter)return n.valid=!1,n.error=o+'"filter" must be a function, but '+typeof a.filter+" given",n}else if(a.regex){if(showdown.helper.isString(a.regex)&&(a.regex=new RegExp(a.regex,"g")),!a.regex instanceof RegExp)return n.valid=!1,n.error=o+'"regex" property must either be a string or a RegExp object, but '+typeof a.regex+" given",n;if(showdown.helper.isUndefined(a.replace))return n.valid=!1,n.error=o+'"regex" extensions must implement a replace string or function',n}}return n}function escapeCharactersCallback(e,r){"use strict";return"~E"+r.charCodeAt(0)+"E"}showdown.helper={},showdown.extensions={},showdown.setOption=function(e,r){"use strict";return globalOptions[e]=r,this},showdown.getOption=function(e){"use strict";return globalOptions[e]},showdown.getOptions=function(){"use strict";return globalOptions},showdown.resetOptions=function(){"use strict";globalOptions=getDefaultOpts(!0)},showdown.setFlavor=function(e){"use strict";if(flavor.hasOwnProperty(e)){var r=flavor[e];for(var t in r)r.hasOwnProperty(t)&&(globalOptions[t]=r[t])}},showdown.getDefaultOptions=function(e){"use strict";return getDefaultOpts(e)},showdown.subParser=function(e,r){"use strict";if(showdown.helper.isString(e)){if(void 0===r){if(parsers.hasOwnProperty(e))return parsers[e];throw Error("SubParser named "+e+" not registered!")}parsers[e]=r}},showdown.extension=function(e,r){"use strict";if(!showdown.helper.isString(e))throw Error("Extension 'name' must be a string");if(e=showdown.helper.stdExtName(e),showdown.helper.isUndefined(r)){if(!extensions.hasOwnProperty(e))throw Error("Extension named "+e+" is not registered!");return extensions[e]}"function"==typeof r&&(r=r()),showdown.helper.isArray(r)||(r=[r]);var t=validate(r,e);if(!t.valid)throw Error(t.error);extensions[e]=r},showdown.getAllExtensions=function(){"use strict";return extensions},showdown.removeExtension=function(e){"use strict";delete extensions[e]},showdown.resetExtensions=function(){"use strict";extensions={}},showdown.validateExtension=function(e){"use strict";var r=validate(e,null);return!!r.valid||(console.warn(r.error),!1)},showdown.hasOwnProperty("helper")||(showdown.helper={}),showdown.helper.isString=function(e){"use strict";return"string"==typeof e||e instanceof String},showdown.helper.isFunction=function(e){"use strict";return e&&"[object Function]"==={}.toString.call(e)},showdown.helper.forEach=function(e,r){"use strict";if("function"==typeof e.forEach)e.forEach(r);else for(var t=0;t<e.length;t++)r(e[t],t,e)},showdown.helper.isArray=function(e){"use strict";return e.constructor===Array},showdown.helper.isUndefined=function(e){"use strict";return void 0===e},showdown.helper.stdExtName=function(e){"use strict";return e.replace(/[_-]||\s/g,"").toLowerCase()},showdown.helper.escapeCharactersCallback=escapeCharactersCallback,showdown.helper.escapeCharacters=function(e,r,t){"use strict";var n="(["+r.replace(/([\[\]\\])/g,"\\$1")+"])";t&&(n="\\\\"+n);var s=new RegExp(n,"g");return e=e.replace(s,escapeCharactersCallback)};var rgxFindMatchPos=function(e,r,t,n){"use strict";var s,o,a,i,c,l=n||"",u=l.indexOf("g")>-1,h=new RegExp(r+"|"+t,"g"+l.replace(/g/g,"")),d=new RegExp(r,l.replace(/g/g,"")),p=[];do{for(s=0;a=h.exec(e);)if(d.test(a[0]))s++||(i=(o=h.lastIndex)-a[0].length);else if(s&&!--s){c=a.index+a[0].length;var w={left:{start:i,end:o},match:{start:o,end:a.index},right:{start:a.index,end:c},wholeMatch:{start:i,end:c}};if(p.push(w),!u)return p}}while(s&&(h.lastIndex=o));return p};showdown.helper.matchRecursiveRegExp=function(e,r,t,n){"use strict";for(var s=rgxFindMatchPos(e,r,t,n),o=[],a=0;a<s.length;++a)o.push([e.slice(s[a].wholeMatch.start,s[a].wholeMatch.end),e.slice(s[a].match.start,s[a].match.end),e.slice(s[a].left.start,s[a].left.end),e.slice(s[a].right.start,s[a].right.end)]);return o},showdown.helper.replaceRecursiveRegExp=function(e,r,t,n,s){"use strict";if(!showdown.helper.isFunction(r)){var o=r;r=function(){return o}}var a=rgxFindMatchPos(e,t,n,s),i=e,c=a.length;if(c>0){var l=[];0!==a[0].wholeMatch.start&&l.push(e.slice(0,a[0].wholeMatch.start));for(var u=0;u<c;++u)l.push(r(e.slice(a[u].wholeMatch.start,a[u].wholeMatch.end),e.slice(a[u].match.start,a[u].match.end),e.slice(a[u].left.start,a[u].left.end),e.slice(a[u].right.start,a[u].right.end))),u<c-1&&l.push(e.slice(a[u].wholeMatch.end,a[u+1].wholeMatch.start));a[c-1].wholeMatch.end<e.length&&l.push(e.slice(a[c-1].wholeMatch.end)),i=l.join("")}return i},showdown.helper.isUndefined(console)&&(console={warn:function(e){"use strict";alert(e)},log:function(e){"use strict";alert(e)},error:function(e){"use strict";throw e}}),showdown.Converter=function(e){"use strict";var r={},t=[],n=[],s={};function o(e,r){if(r=r||null,showdown.helper.isString(e)){if(r=e=showdown.helper.stdExtName(e),showdown.extensions[e])return console.warn("DEPRECATION WARNING: "+e+" is an old extension that uses a deprecated loading method.Please inform the developer that the extension should be updated!"),void function(e,r){"function"==typeof e&&(e=e(new showdown.Converter));showdown.helper.isArray(e)||(e=[e]);var s=validate(e,r);if(!s.valid)throw Error(s.error);for(var o=0;o<e.length;++o)switch(e[o].type){case"lang":t.push(e[o]);break;case"output":n.push(e[o]);break;default:throw Error("Extension loader error: Type unrecognized!!!")}}(showdown.extensions[e],e);if(showdown.helper.isUndefined(extensions[e]))throw Error('Extension "'+e+'" could not be loaded. It was either not found or is not a valid extension.');e=extensions[e]}"function"==typeof e&&(e=e()),showdown.helper.isArray(e)||(e=[e]);var o=validate(e,r);if(!o.valid)throw Error(o.error);for(var i=0;i<e.length;++i){switch(e[i].type){case"lang":t.push(e[i]);break;case"output":n.push(e[i])}if(e[i].hasOwnProperty(s))for(var c in e[i].listeners)e[i].listeners.hasOwnProperty(c)&&a(c,e[i].listeners[c])}}function a(e,r){if(!showdown.helper.isString(e))throw Error("Invalid argument in converter.listen() method: name must be a string, but "+typeof e+" given");if("function"!=typeof r)throw Error("Invalid argument in converter.listen() method: callback must be a function, but "+typeof r+" given");s.hasOwnProperty(e)||(s[e]=[]),s[e].push(r)}!function(){for(var t in e=e||{},globalOptions)globalOptions.hasOwnProperty(t)&&(r[t]=globalOptions[t]);if("object"!=typeof e)throw Error("Converter expects the passed parameter to be an object, but "+typeof e+" was passed instead.");for(var n in e)e.hasOwnProperty(n)&&(r[n]=e[n]);r.extensions&&showdown.helper.forEach(r.extensions,o)}(),this._dispatch=function(e,r,t,n){if(s.hasOwnProperty(e))for(var o=0;o<s[e].length;++o){var a=s[e][o](e,r,this,t,n);a&&void 0!==a&&(r=a)}return r},this.listen=function(e,r){return a(e,r),this},this.makeHtml=function(e){if(!e)return e;var s={gHtmlBlocks:[],gHtmlMdBlocks:[],gHtmlSpans:[],gUrls:{},gTitles:{},gDimensions:{},gListLevel:0,hashLinkCounts:{},langExtensions:t,outputModifiers:n,converter:this,ghCodeBlocks:[]};return e=(e=(e=(e=e.replace(/~/g,"~T")).replace(/\$/g,"~D")).replace(/\r\n/g,"\n")).replace(/\r/g,"\n"),r.smartIndentationFix&&(e=function(e){var r=e.match(/^\s*/)[0].length,t=new RegExp("^\\s{0,"+r+"}","gm");return e.replace(t,"")}(e)),e=e,e=showdown.subParser("detab")(e,r,s),e=showdown.subParser("stripBlankLines")(e,r,s),showdown.helper.forEach(t,(function(t){e=showdown.subParser("runExtension")(t,e,r,s)})),e=showdown.subParser("hashPreCodeTags")(e,r,s),e=showdown.subParser("githubCodeBlocks")(e,r,s),e=showdown.subParser("hashHTMLBlocks")(e,r,s),e=showdown.subParser("hashHTMLSpans")(e,r,s),e=showdown.subParser("stripLinkDefinitions")(e,r,s),e=showdown.subParser("blockGamut")(e,r,s),e=showdown.subParser("unhashHTMLSpans")(e,r,s),e=(e=(e=showdown.subParser("unescapeSpecialChars")(e,r,s)).replace(/~D/g,"$$")).replace(/~T/g,"~"),showdown.helper.forEach(n,(function(t){e=showdown.subParser("runExtension")(t,e,r,s)})),e},this.setOption=function(e,t){r[e]=t},this.getOption=function(e){return r[e]},this.getOptions=function(){return r},this.addExtension=function(e,r){o(e,r=r||null)},this.useExtension=function(e){o(e)},this.setFlavor=function(e){if(flavor.hasOwnProperty(e)){var t=flavor[e];for(var n in t)t.hasOwnProperty(n)&&(r[n]=t[n])}},this.removeExtension=function(e){showdown.helper.isArray(e)||(e=[e]);for(var r=0;r<e.length;++r){for(var s=e[r],o=0;o<t.length;++o)t[o]===s&&t[o].splice(o,1);for(;0<n.length;++o)n[0]===s&&n[0].splice(o,1)}},this.getAllExtensions=function(){return{language:t,output:n}}},showdown.subParser("anchors",(function(e,r,t){"use strict";var n=function(e,r,n,s,o,a,i,c){showdown.helper.isUndefined(c)&&(c=""),e=r;var l=n,u=s.toLowerCase(),h=o,d=c;if(!h)if(u||(u=l.toLowerCase().replace(/ ?\n/g," ")),h="#"+u,showdown.helper.isUndefined(t.gUrls[u])){if(!(e.search(/\(\s*\)$/m)>-1))return e;h=""}else h=t.gUrls[u],showdown.helper.isUndefined(t.gTitles[u])||(d=t.gTitles[u]);var p='<a href="'+(h=showdown.helper.escapeCharacters(h,"*_",!1))+'"';return""!==d&&null!==d&&(d=d.replace(/"/g,"&quot;"),p+=' title="'+(d=showdown.helper.escapeCharacters(d,"*_",!1))+'"'),p+=">"+l+"</a>"};return e=(e=(e=(e=t.converter._dispatch("anchors.before",e,r,t)).replace(/(\[((?:\[[^\]]*]|[^\[\]])*)][ ]?(?:\n[ ]*)?\[(.*?)])()()()()/g,n)).replace(/(\[((?:\[[^\]]*]|[^\[\]])*)]\([ \t]*()<?(.*?(?:\(.*?\).*?)?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,n)).replace(/(\[([^\[\]]+)])()()()()()/g,n),e=t.converter._dispatch("anchors.after",e,r,t)})),showdown.subParser("autoLinks",(function(e,r,t){"use strict";function n(e,r){var t=r;return/^www\./i.test(r)&&(r=r.replace(/^www\./i,"http://www.")),'<a href="'+r+'">'+t+"</a>"}function s(e,r){var t=showdown.subParser("unescapeSpecialChars")(r);return showdown.subParser("encodeEmailAddress")(t)}return e=(e=(e=t.converter._dispatch("autoLinks.before",e,r,t)).replace(/<(((https?|ftp|dict):\/\/|www\.)[^'">\s]+)>/gi,n)).replace(/<(?:mailto:)?([-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi,s),r.simplifiedAutoLink&&(e=(e=e.replace(/\b(((https?|ftp|dict):\/\/|www\.)[^'">\s]+\.[^'">\s]+)(?=\s|$)(?!["<>])/gi,n)).replace(/(?:^|[ \n\t])([A-Za-z0-9!#$%&'*+-/=?^_`\{|}~\.]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)(?:$|[ \n\t])/gi,s)),e=t.converter._dispatch("autoLinks.after",e,r,t)})),showdown.subParser("blockGamut",(function(e,r,t){"use strict";e=t.converter._dispatch("blockGamut.before",e,r,t),e=showdown.subParser("blockQuotes")(e,r,t),e=showdown.subParser("headers")(e,r,t);var n=showdown.subParser("hashBlock")("<hr />",r,t);return e=(e=(e=e.replace(/^[ ]{0,2}([ ]?\*[ ]?){3,}[ \t]*$/gm,n)).replace(/^[ ]{0,2}([ ]?\-[ ]?){3,}[ \t]*$/gm,n)).replace(/^[ ]{0,2}([ ]?_[ ]?){3,}[ \t]*$/gm,n),e=showdown.subParser("lists")(e,r,t),e=showdown.subParser("codeBlocks")(e,r,t),e=showdown.subParser("tables")(e,r,t),e=showdown.subParser("hashHTMLBlocks")(e,r,t),e=showdown.subParser("paragraphs")(e,r,t),e=t.converter._dispatch("blockGamut.after",e,r,t)})),showdown.subParser("blockQuotes",(function(e,r,t){"use strict";return e=(e=t.converter._dispatch("blockQuotes.before",e,r,t)).replace(/((^[ \t]{0,3}>[ \t]?.+\n(.+\n)*\n*)+)/gm,(function(e,n){var s=n;return s=(s=(s=s.replace(/^[ \t]*>[ \t]?/gm,"~0")).replace(/~0/g,"")).replace(/^[ \t]+$/gm,""),s=showdown.subParser("githubCodeBlocks")(s,r,t),s=(s=(s=showdown.subParser("blockGamut")(s,r,t)).replace(/(^|\n)/g,"$1 ")).replace(/(\s*<pre>[^\r]+?<\/pre>)/gm,(function(e,r){var t=r;return t=(t=t.replace(/^ /gm,"~0")).replace(/~0/g,"")})),showdown.subParser("hashBlock")("<blockquote>\n"+s+"\n</blockquote>",r,t)})),e=t.converter._dispatch("blockQuotes.after",e,r,t)})),showdown.subParser("codeBlocks",(function(e,r,t){"use strict";e=t.converter._dispatch("codeBlocks.before",e,r,t);return e=(e=(e+="~0").replace(/(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=~0))/g,(function(e,n,s){var o=n,a=s,i="\n";return o=showdown.subParser("outdent")(o),o=showdown.subParser("encodeCode")(o),o=(o=(o=showdown.subParser("detab")(o)).replace(/^\n+/g,"")).replace(/\n+$/g,""),r.omitExtraWLInCodeBlocks&&(i=""),o="<pre><code>"+o+i+"</code></pre>",showdown.subParser("hashBlock")(o,r,t)+a}))).replace(/~0/,""),e=t.converter._dispatch("codeBlocks.after",e,r,t)})),showdown.subParser("codeSpans",(function(e,r,t){"use strict";return void 0===(e=t.converter._dispatch("codeSpans.before",e,r,t))&&(e=""),e=e.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,(function(e,r,t,n){var s=n;return s=(s=s.replace(/^([ \t]*)/g,"")).replace(/[ \t]*$/g,""),r+"<code>"+(s=showdown.subParser("encodeCode")(s))+"</code>"})),e=t.converter._dispatch("codeSpans.after",e,r,t)})),showdown.subParser("detab",(function(e){"use strict";return e=(e=(e=(e=(e=e.replace(/\t(?=\t)/g," ")).replace(/\t/g,"~A~B")).replace(/~B(.+?)~A/g,(function(e,r){for(var t=r,n=4-t.length%4,s=0;s<n;s++)t+=" ";return t}))).replace(/~A/g," ")).replace(/~B/g,"")})),showdown.subParser("encodeAmpsAndAngles",(function(e){"use strict";return e=(e=e.replace(/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/g,"&amp;")).replace(/<(?![a-z\/?\$!])/gi,"&lt;")})),showdown.subParser("encodeBackslashEscapes",(function(e){"use strict";return e=(e=e.replace(/\\(\\)/g,showdown.helper.escapeCharactersCallback)).replace(/\\([`*_{}\[\]()>#+-.!])/g,showdown.helper.escapeCharactersCallback)})),showdown.subParser("encodeCode",(function(e){"use strict";return e=(e=(e=e.replace(/&/g,"&amp;")).replace(/</g,"&lt;")).replace(/>/g,"&gt;"),e=showdown.helper.escapeCharacters(e,"*_{}[]\\",!1)})),showdown.subParser("encodeEmailAddress",(function(e){"use strict";var r=[function(e){return"&#"+e.charCodeAt(0)+";"},function(e){return"&#x"+e.charCodeAt(0).toString(16)+";"},function(e){return e}];return e=(e='<a href="'+(e=(e="mailto:"+e).replace(/./g,(function(e){if("@"===e)e=r[Math.floor(2*Math.random())](e);else if(":"!==e){var t=Math.random();e=t>.9?r[2](e):t>.45?r[1](e):r[0](e)}return e})))+'">'+e+"</a>").replace(/">.+:/g,'">')})),showdown.subParser("escapeSpecialCharsWithinTagAttributes",(function(e){"use strict";return e=e.replace(/(<[a-z\/!$]("[^"]*"|'[^']*'|[^'">])*>|<!(--.*?--\s*)+>)/gi,(function(e){var r=e.replace(/(.)<\/?code>(?=.)/g,"$1`");return r=showdown.helper.escapeCharacters(r,"\\`*_",!1)}))})),showdown.subParser("githubCodeBlocks",(function(e,r,t){"use strict";return r.ghCodeBlocks?(e=t.converter._dispatch("githubCodeBlocks.before",e,r,t),e=(e=(e+="~0").replace(/(?:^|\n)```(.*)\n([\s\S]*?)\n```/g,(function(e,n,s){var o=r.omitExtraWLInCodeBlocks?"":"\n";return s=showdown.subParser("encodeCode")(s),s="<pre><code"+(n?' class="'+n+" language-"+n+'"':"")+">"+(s=(s=(s=showdown.subParser("detab")(s)).replace(/^\n+/g,"")).replace(/\n+$/g,""))+o+"</code></pre>",s=showdown.subParser("hashBlock")(s,r,t),"\n\n~G"+(t.ghCodeBlocks.push({text:e,codeblock:s})-1)+"G\n\n"}))).replace(/~0/,""),t.converter._dispatch("githubCodeBlocks.after",e,r,t)):e})),showdown.subParser("hashBlock",(function(e,r,t){"use strict";return e=e.replace(/(^\n+|\n+$)/g,""),"\n\n~K"+(t.gHtmlBlocks.push(e)-1)+"K\n\n"})),showdown.subParser("hashElement",(function(e,r,t){"use strict";return function(e,r){var n=r;return n=(n=(n=n.replace(/\n\n/g,"\n")).replace(/^\n/,"")).replace(/\n+$/g,""),n="\n\n~K"+(t.gHtmlBlocks.push(n)-1)+"K\n\n"}})),showdown.subParser("hashHTMLBlocks",(function(e,r,t){"use strict";for(var n=["pre","div","h1","h2","h3","h4","h5","h6","blockquote","table","dl","ol","ul","script","noscript","form","fieldset","iframe","math","style","section","header","footer","nav","article","aside","address","audio","canvas","figure","hgroup","output","video","p"],s=function(e,r,n,s){var o=e;return-1!==n.search(/\bmarkdown\b/)&&(o=n+t.converter.makeHtml(r)+s),"\n\n~K"+(t.gHtmlBlocks.push(o)-1)+"K\n\n"},o=0;o<n.length;++o)e=showdown.helper.replaceRecursiveRegExp(e,s,"^(?: |\\t){0,3}<"+n[o]+"\\b[^>]*>","</"+n[o]+">","gim");return e=(e=(e=e.replace(/(\n[ ]{0,3}(<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g,showdown.subParser("hashElement")(e,r,t))).replace(/(<!--[\s\S]*?-->)/g,showdown.subParser("hashElement")(e,r,t))).replace(/(?:\n\n)([ ]{0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g,showdown.subParser("hashElement")(e,r,t))})),showdown.subParser("hashHTMLSpans",(function(e,r,t){"use strict";for(var n=showdown.helper.matchRecursiveRegExp(e,"<code\\b[^>]*>","</code>","gi"),s=0;s<n.length;++s)e=e.replace(n[s][0],"~L"+(t.gHtmlSpans.push(n[s][0])-1)+"L");return e})),showdown.subParser("unhashHTMLSpans",(function(e,r,t){"use strict";for(var n=0;n<t.gHtmlSpans.length;++n)e=e.replace("~L"+n+"L",t.gHtmlSpans[n]);return e})),showdown.subParser("hashPreCodeTags",(function(e,r,t){"use strict";return e=showdown.helper.replaceRecursiveRegExp(e,(function(e,r,n,s){var o=n+showdown.subParser("encodeCode")(r)+s;return"\n\n~G"+(t.ghCodeBlocks.push({text:e,codeblock:o})-1)+"G\n\n"}),"^(?: |\\t){0,3}<pre\\b[^>]*>\\s*<code\\b[^>]*>","^(?: |\\t){0,3}</code>\\s*</pre>","gim")})),showdown.subParser("headers",(function(e,r,t){"use strict";e=t.converter._dispatch("headers.before",e,r,t);var n=r.prefixHeaderId,s=isNaN(parseInt(r.headerLevelStart))?1:parseInt(r.headerLevelStart),o=r.smoothLivePreview?/^(.+)[ \t]*\n={2,}[ \t]*\n+/gm:/^(.+)[ \t]*\n=+[ \t]*\n+/gm,a=r.smoothLivePreview?/^(.+)[ \t]*\n-{2,}[ \t]*\n+/gm:/^(.+)[ \t]*\n-+[ \t]*\n+/gm;function i(e){var r,s=e.replace(/[^\w]/g,"").toLowerCase();return t.hashLinkCounts[s]?r=s+"-"+t.hashLinkCounts[s]++:(r=s,t.hashLinkCounts[s]=1),!0===n&&(n="section"),showdown.helper.isString(n)?n+r:r}return e=(e=(e=e.replace(o,(function(e,n){var o=showdown.subParser("spanGamut")(n,r,t),a=r.noHeaderId?"":' id="'+i(n)+'"',c="<h"+s+a+">"+o+"</h"+s+">";return showdown.subParser("hashBlock")(c,r,t)}))).replace(a,(function(e,n){var o=showdown.subParser("spanGamut")(n,r,t),a=r.noHeaderId?"":' id="'+i(n)+'"',c=s+1,l="<h"+c+a+">"+o+"</h"+c+">";return showdown.subParser("hashBlock")(l,r,t)}))).replace(/^(#{1,6})[ \t]*(.+?)[ \t]*#*\n+/gm,(function(e,n,o){var a=showdown.subParser("spanGamut")(o,r,t),c=r.noHeaderId?"":' id="'+i(o)+'"',l=s-1+n.length,u="<h"+l+c+">"+a+"</h"+l+">";return showdown.subParser("hashBlock")(u,r,t)})),e=t.converter._dispatch("headers.after",e,r,t)})),showdown.subParser("images",(function(e,r,t){"use strict";function n(e,r,n,s,o,a,i,c){var l=t.gUrls,u=t.gTitles,h=t.gDimensions;if(n=n.toLowerCase(),c||(c=""),""===s||null===s){if(""!==n&&null!==n||(n=r.toLowerCase().replace(/ ?\n/g," ")),s="#"+n,showdown.helper.isUndefined(l[n]))return e;s=l[n],showdown.helper.isUndefined(u[n])||(c=u[n]),showdown.helper.isUndefined(h[n])||(o=h[n].width,a=h[n].height)}r=r.replace(/"/g,"&quot;"),r=showdown.helper.escapeCharacters(r,"*_",!1);var d='<img src="'+(s=showdown.helper.escapeCharacters(s,"*_",!1))+'" alt="'+r+'"';return c&&(c=c.replace(/"/g,"&quot;"),d+=' title="'+(c=showdown.helper.escapeCharacters(c,"*_",!1))+'"'),o&&a&&(d+=' width="'+(o="*"===o?"auto":o)+'"',d+=' height="'+(a="*"===a?"auto":a)+'"'),d+=" />"}return e=(e=(e=t.converter._dispatch("images.before",e,r,t)).replace(/!\[([^\]]*?)] ?(?:\n *)?\[(.*?)]()()()()()/g,n)).replace(/!\[(.*?)]\s?\([ \t]*()<?(\S+?)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(['"])(.*?)\6[ \t]*)?\)/g,n),e=t.converter._dispatch("images.after",e,r,t)})),showdown.subParser("italicsAndBold",(function(e,r,t){"use strict";return e=t.converter._dispatch("italicsAndBold.before",e,r,t),e=r.literalMidWordUnderscores?(e=(e=(e=e.replace(/(^|\s|>|\b)__(?=\S)([\s\S]+?)__(?=\b|<|\s|$)/gm,"$1<strong>$2</strong>")).replace(/(^|\s|>|\b)_(?=\S)([\s\S]+?)_(?=\b|<|\s|$)/gm,"$1<em>$2</em>")).replace(/(\*\*)(?=\S)([^\r]*?\S[*]*)\1/g,"<strong>$2</strong>")).replace(/(\*)(?=\S)([^\r]*?\S)\1/g,"<em>$2</em>"):(e=e.replace(/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g,"<strong>$2</strong>")).replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g,"<em>$2</em>"),e=t.converter._dispatch("italicsAndBold.after",e,r,t)})),showdown.subParser("lists",(function(e,r,t){"use strict";function n(e,n){t.gListLevel++,e=e.replace(/\n{2,}$/,"\n");var s=/\n[ \t]*\n(?!~0)/.test(e+="~0");return e=(e=e.replace(/(\n)?(^[ \t]*)([*+-]|\d+[.])[ \t]+((\[(x|X| )?])?[ \t]*[^\r]+?(\n{1,2}))(?=\n*(~0|\2([*+-]|\d+[.])[ \t]+))/gm,(function(e,n,o,a,i,c,l){l=l&&""!==l.trim();var u=showdown.subParser("outdent")(i,r,t),h="";return c&&r.tasklists&&(h=' class="task-list-item" style="list-style-type: none;"',u=u.replace(/^[ \t]*\[(x|X| )?]/m,(function(){var e='<input type="checkbox" disabled style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;"';return l&&(e+=" checked"),e+=">"}))),n||u.search(/\n{2,}/)>-1?(u=showdown.subParser("githubCodeBlocks")(u,r,t),u=showdown.subParser("blockGamut")(u,r,t)):(u=(u=showdown.subParser("lists")(u,r,t)).replace(/\n$/,""),u=s?showdown.subParser("paragraphs")(u,r,t):showdown.subParser("spanGamut")(u,r,t)),u="\n<li"+h+">"+u+"</li>\n"}))).replace(/~0/g,""),t.gListLevel--,n&&(e=e.replace(/\s+$/,"")),e}function s(e,r,t){var s="ul"===r?/^ {0,2}\d+\.[ \t]/gm:/^ {0,2}[*+-][ \t]/gm,o=[],a="";if(-1!==e.search(s)){!function e(o){var i=o.search(s);-1!==i?(a+="\n\n<"+r+">"+n(o.slice(0,i),!!t)+"</"+r+">\n\n",s="ul"===(r="ul"===r?"ol":"ul")?/^ {0,2}\d+\.[ \t]/gm:/^ {0,2}[*+-][ \t]/gm,e(o.slice(i))):a+="\n\n<"+r+">"+n(o,!!t)+"</"+r+">\n\n"}(e);for(var i=0;i<o.length;++i);}else a="\n\n<"+r+">"+n(e,!!t)+"</"+r+">\n\n";return a}e=t.converter._dispatch("lists.before",e,r,t),e+="~0";var o=/^(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm;return t.gListLevel?e=e.replace(o,(function(e,r,t){return s(r,t.search(/[*+-]/g)>-1?"ul":"ol",!0)})):(o=/(\n\n|^\n?)(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm,e=e.replace(o,(function(e,r,t,n){return s(t,n.search(/[*+-]/g)>-1?"ul":"ol")}))),e=e.replace(/~0/,""),e=t.converter._dispatch("lists.after",e,r,t)})),showdown.subParser("outdent",(function(e){"use strict";return e=(e=e.replace(/^(\t|[ ]{1,4})/gm,"~0")).replace(/~0/g,"")})),showdown.subParser("paragraphs",(function(e,r,t){"use strict";for(var n=(e=(e=(e=t.converter._dispatch("paragraphs.before",e,r,t)).replace(/^\n+/g,"")).replace(/\n+$/g,"")).split(/\n{2,}/g),s=[],o=n.length,a=0;a<o;a++){var i=n[a];i.search(/~(K|G)(\d+)\1/g)>=0||(i=(i=showdown.subParser("spanGamut")(i,r,t)).replace(/^([ \t]*)/g,"<p>"),i+="</p>"),s.push(i)}for(o=s.length,a=0;a<o;a++){for(var c="",l=s[a],u=!1;l.search(/~(K|G)(\d+)\1/)>=0;){var h=RegExp.$1,d=RegExp.$2;c=(c="K"===h?t.gHtmlBlocks[d]:u?showdown.subParser("encodeCode")(t.ghCodeBlocks[d].text):t.ghCodeBlocks[d].codeblock).replace(/\$/g,"$$$$"),l=l.replace(/(\n\n)?~(K|G)\d+\2(\n\n)?/,c),/^<pre\b[^>]*>\s*<code\b[^>]*>/.test(l)&&(u=!0)}s[a]=l}return e=(e=(e=s.join("\n\n")).replace(/^\n+/g,"")).replace(/\n+$/g,""),t.converter._dispatch("paragraphs.after",e,r,t)})),showdown.subParser("runExtension",(function(e,r,t,n){"use strict";if(e.filter)r=e.filter(r,n.converter,t);else if(e.regex){var s=e.regex;!s instanceof RegExp&&(s=new RegExp(s,"g")),r=r.replace(s,e.replace)}return r})),showdown.subParser("spanGamut",(function(e,r,t){"use strict";return e=t.converter._dispatch("spanGamut.before",e,r,t),e=showdown.subParser("codeSpans")(e,r,t),e=showdown.subParser("escapeSpecialCharsWithinTagAttributes")(e,r,t),e=showdown.subParser("encodeBackslashEscapes")(e,r,t),e=showdown.subParser("images")(e,r,t),e=showdown.subParser("anchors")(e,r,t),e=showdown.subParser("autoLinks")(e,r,t),e=showdown.subParser("encodeAmpsAndAngles")(e,r,t),e=showdown.subParser("italicsAndBold")(e,r,t),e=(e=showdown.subParser("strikethrough")(e,r,t)).replace(/ +\n/g," <br />\n"),e=t.converter._dispatch("spanGamut.after",e,r,t)})),showdown.subParser("strikethrough",(function(e,r,t){"use strict";return r.strikethrough&&(e=(e=t.converter._dispatch("strikethrough.before",e,r,t)).replace(/(?:~T){2}([\s\S]+?)(?:~T){2}/g,"<del>$1</del>"),e=t.converter._dispatch("strikethrough.after",e,r,t)),e})),showdown.subParser("stripBlankLines",(function(e){"use strict";return e.replace(/^[ \t]+$/gm,"")})),showdown.subParser("stripLinkDefinitions",(function(e,r,t){"use strict";return e=(e=(e+="~0").replace(/^ {0,3}\[(.+)]:[ \t]*\n?[ \t]*<?(\S+?)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*\n?[ \t]*(?:(\n*)["|'(](.+?)["|')][ \t]*)?(?:\n+|(?=~0))/gm,(function(e,n,s,o,a,i,c){return n=n.toLowerCase(),t.gUrls[n]=showdown.subParser("encodeAmpsAndAngles")(s),i?i+c:(c&&(t.gTitles[n]=c.replace(/"|'/g,"&quot;")),r.parseImgDimensions&&o&&a&&(t.gDimensions[n]={width:o,height:a}),"")}))).replace(/~0/,"")})),showdown.subParser("tables",(function(e,r,t){"use strict";if(!r.tables)return e;function n(e,n){return"<td"+n+">"+showdown.subParser("spanGamut")(e,r,t)+"</td>\n"}return e=(e=t.converter._dispatch("tables.before",e,r,t)).replace(/^[ \t]{0,3}\|?.+\|.+\n[ \t]{0,3}\|?[ \t]*:?[ \t]*(?:-|=){2,}[ \t]*:?[ \t]*\|[ \t]*:?[ \t]*(?:-|=){2,}[\s\S]+?(?:\n\n|~0)/gm,(function(e){var s,o=e.split("\n");for(s=0;s<o.length;++s)/^[ \t]{0,3}\|/.test(o[s])&&(o[s]=o[s].replace(/^[ \t]{0,3}\|/,"")),/\|[ \t]*$/.test(o[s])&&(o[s]=o[s].replace(/\|[ \t]*$/,""));var a,i,c,l,u=o[0].split("|").map((function(e){return e.trim()})),h=o[1].split("|").map((function(e){return e.trim()})),d=[],p=[],w=[],f=[];for(o.shift(),o.shift(),s=0;s<o.length;++s)""!==o[s].trim()&&d.push(o[s].split("|").map((function(e){return e.trim()})));if(u.length<h.length)return e;for(s=0;s<h.length;++s)w.push((a=h[s],/^:[ \t]*--*$/.test(a)?' style="text-align:left;"':/^--*[ \t]*:[ \t]*$/.test(a)?' style="text-align:right;"':/^:[ \t]*--*[ \t]*:$/.test(a)?' style="text-align:center;"':""));for(s=0;s<u.length;++s)showdown.helper.isUndefined(w[s])&&(w[s]=""),p.push((i=u[s],c=w[s],l=void 0,l="",i=i.trim(),r.tableHeaderId&&(l=' id="'+i.replace(/ /g,"_").toLowerCase()+'"'),"<th"+l+c+">"+(i=showdown.subParser("spanGamut")(i,r,t))+"</th>\n"));for(s=0;s<d.length;++s){for(var g=[],b=0;b<p.length;++b)showdown.helper.isUndefined(d[s][b]),g.push(n(d[s][b],w[b]));f.push(g)}return function(e,r){for(var t="<table>\n<thead>\n<tr>\n",n=e.length,s=0;s<n;++s)t+=e[s];for(t+="</tr>\n</thead>\n<tbody>\n",s=0;s<r.length;++s){t+="<tr>\n";for(var o=0;o<n;++o)t+=r[s][o];t+="</tr>\n"}return t+"</tbody>\n</table>\n"}(p,f)})),e=t.converter._dispatch("tables.after",e,r,t)})),showdown.subParser("unescapeSpecialChars",(function(e){"use strict";return e=e.replace(/~E(\d+)E/g,(function(e,r){var t=parseInt(r);return String.fromCharCode(t)}))})),module.exports=showdown;