mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
4 lines
12 KiB
JavaScript
4 lines
12 KiB
JavaScript
/*! showdown 19-01-2015 */
|
|
|
|
(function(){function a(a,b){"use strict";var c=b.charCodeAt(0);return"~E"+c+"E"}var b={},c={},d={omitExtraWLInCodeBlocks:!1,prefixHeaderId:!1};b.helper={},b.extensions={},b.setOption=function(a,b){"use strict";return d[a]=b,this},b.getOption=function(a){"use strict";return d[a]},b.getOptions=function(){"use strict";return d},b.subParser=function(a,d){"use strict";if(b.helper.isString(a)){if("undefined"==typeof d){if(c.hasOwnProperty(a))return c[a];throw Error("SubParser named "+a+" not registered!")}c[a]=d}},b.Converter=function(a){"use strict";a=a||{};var b=d,e=["detab","stripBlankLines","githubCodeBlocks","hashHTMLBlocks","stripLinkDefinitions","blockGamut","unescapeSpecialChars"];if("object"==typeof a)for(var f in a)a.hasOwnProperty(f)&&(b[f]=a[f]);var g=function(a){if(!a)return a;var d={gHtmlBlocks:[],gUrls:{},gTitles:{},gListLevel:0,hashLinkCounts:{}};a=a.replace(/~/g,"~T"),a=a.replace(/\$/g,"~D"),a=a.replace(/\r\n/g,"\n"),a=a.replace(/\r/g,"\n"),a="\n\n"+a+"\n\n";for(var f=0;f<e.length;++f){var g=e[f];a=c[g](a,b,d)}return a=a.replace(/~D/g,"$$"),a=a.replace(/~T/g,"~")};return{makeHtml:g}},b.hasOwnProperty("helper")||(b.helper={}),b.helper.isString=function(a){"use strict";return"string"==typeof a||a instanceof String},b.helper.forEach=function(a,b){"use strict";if("function"==typeof a.forEach)a.forEach(b);else{var c,d=a.length;for(c=0;d>c;c++)b(a[c],c,a)}},b.helper.isArray=function(a){"use strict";return a.constructor===Array},b.helper.isUndefined=function(a){"use strict";return"undefined"==typeof a},b.helper.escapeCharactersCallback=a,b.helper.escapeCharacters=function(b,c,d){"use strict";var e="(["+c.replace(/([\[\]\\])/g,"\\$1")+"])";d&&(e="\\\\"+e);var f=new RegExp(e,"g");return b=b.replace(f,a)},b.subParser("anchors",function(a,c,d){"use strict";var e=function(a,c,e,f,g,h,i,j){b.helper.isUndefined(j)&&(j=""),a=c;var k=e,l=f.toLowerCase(),m=g,n=j;if(!m)if(l||(l=k.toLowerCase().replace(/ ?\n/g," ")),m="#"+l,b.helper.isUndefined(d.gUrls[l])){if(!(a.search(/\(\s*\)$/m)>-1))return a;m=""}else m=d.gUrls[l],b.helper.isUndefined(d.gTitles[l])||(n=d.gTitles[l]);m=b.helper.escapeCharacters(m,"*_",!1);var o='<a href="'+m+'"';return""!==n&&null!==n&&(n=n.replace(/"/g,"""),n=b.helper.escapeCharacters(n,"*_",!1),o+=' title="'+n+'"'),o+=">"+k+"</a>"};return a=a.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g,e),a=a.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\]\([ \t]*()<?(.*?(?:\(.*?\).*?)?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,e),a=a.replace(/(\[([^\[\]]+)\])()()()()()/g,e)}),b.subParser("autoLinks",function(a){"use strict";a=a.replace(/<((https?|ftp|dict):[^'">\s]+)>/gi,'<a href="$1">$1</a>');var c=/<(?:mailto:)?([-.\w]+\@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi;return a=a.replace(c,function(a,c){var d=b.subParser("unescapeSpecialChars")(c);return b.subParser("encodeEmailAddress")(d)})}),b.subParser("blockGamut",function(a,c,d){"use strict";a=b.subParser("headers")(a,c,d);var e=b.subParser("hashBlock")("<hr />",c,d);return a=a.replace(/^[ ]{0,2}([ ]?\*[ ]?){3,}[ \t]*$/gm,e),a=a.replace(/^[ ]{0,2}([ ]?\-[ ]?){3,}[ \t]*$/gm,e),a=a.replace(/^[ ]{0,2}([ ]?\_[ ]?){3,}[ \t]*$/gm,e),a=b.subParser("lists")(a,c,d),a=b.subParser("codeBlocks")(a,c,d),a=b.subParser("blockQuotes")(a,c,d),a=b.subParser("hashHTMLBlocks")(a,c,d),a=b.subParser("paragraphs")(a,c,d)}),b.subParser("blockQuotes",function(a,c,d){"use strict";return a=a.replace(/((^[ \t]*>[ \t]?.+\n(.+\n)*\n*)+)/gm,function(a,e){var f=e;return f=f.replace(/^[ \t]*>[ \t]?/gm,"~0"),f=f.replace(/~0/g,""),f=f.replace(/^[ \t]+$/gm,""),f=b.subParser("blockGamut")(f,c,d),f=f.replace(/(^|\n)/g,"$1 "),f=f.replace(/(\s*<pre>[^\r]+?<\/pre>)/gm,function(a,b){var c=b;return c=c.replace(/^ /gm,"~0"),c=c.replace(/~0/g,"")}),b.subParser("hashBlock")("<blockquote>\n"+f+"\n</blockquote>",c,d)})}),b.subParser("codeBlocks",function(a,c,d){"use strict";a+="~0";var e=/(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=~0))/g;return a=a.replace(e,function(a,e,f){var g=e,h=f;return g=b.subParser("outdent")(g),g=b.subParser("encodeCode")(g),g=b.subParser("detab")(g),g=g.replace(/^\n+/g,""),g=g.replace(/\n+$/g,""),g="<pre><code>"+g+"\n</code></pre>",b.subParser("hashBlock")(g,c,d)+h}),a=a.replace(/~0/,"")}),b.subParser("codeSpans",function(a){"use strict";return a=a.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,function(a,c,d,e){var f=e;return f=f.replace(/^([ \t]*)/g,""),f=f.replace(/[ \t]*$/g,""),f=b.subParser("encodeCode")(f),c+"<code>"+f+"</code>"})}),b.subParser("detab",function(a){"use strict";return a=a.replace(/\t(?=\t)/g," "),a=a.replace(/\t/g,"~A~B"),a=a.replace(/~B(.+?)~A/g,function(a,b){for(var c=b,d=4-c.length%4,e=0;d>e;e++)c+=" ";return c}),a=a.replace(/~A/g," "),a=a.replace(/~B/g,"")}),b.subParser("encodeAmpsAndAngles",function(a){"use strict";return a=a.replace(/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/g,"&"),a=a.replace(/<(?![a-z\/?\$!])/gi,"<")}),b.subParser("encodeBackslashEscapes",function(a){"use strict";return a=a.replace(/\\(\\)/g,b.helper.escapeCharactersCallback),a=a.replace(/\\([`*_{}\[\]()>#+-.!])/g,b.helper.escapeCharactersCallback)}),b.subParser("encodeCode",function(a){"use strict";return a=a.replace(/&/g,"&"),a=a.replace(/</g,"<"),a=a.replace(/>/g,">"),a=b.helper.escapeCharacters(a,"*_{}[]\\",!1)}),b.subParser("encodeEmailAddress",function(a){"use strict";var b=[function(a){return"&#"+a.charCodeAt(0)+";"},function(a){return"&#x"+a.charCodeAt(0).toString(16)+";"},function(a){return a}];return a="mailto:"+a,a=a.replace(/./g,function(a){if("@"===a)a=b[Math.floor(2*Math.random())](a);else if(":"!==a){var c=Math.random();a=c>.9?b[2](a):c>.45?b[1](a):b[0](a)}return a}),a='<a href="'+a+'">'+a+"</a>",a=a.replace(/">.+:/g,'">')}),b.subParser("escapeSpecialCharsWithinTagAttributes",function(a){"use strict";var c=/(<[a-z\/!$]("[^"]*"|'[^']*'|[^'">])*>|<!(--.*?--\s*)+>)/gi;return a=a.replace(c,function(a){var c=a.replace(/(.)<\/?code>(?=.)/g,"$1`");return c=b.helper.escapeCharacters(c,"\\`*_",!1)})}),b.subParser("githubCodeBlocks",function(a,c,d){"use strict";return a+="~0",a=a.replace(/(?:^|\n)```(.*)\n([\s\S]*?)\n```/g,function(a,e,f){var g=e,h=f,i="\n";return c.omitExtraWLInCodeBlocks&&(i=""),h=b.subParser("encodeCode")(h),h=b.subParser("detab")(h),h=h.replace(/^\n+/g,""),h=h.replace(/\n+$/g,""),h="<pre><code"+(g?' class="'+g+'"':"")+">"+h+i+"</code></pre>",b.subParser("hashBlock")(h,c,d)}),a=a.replace(/~0/,"")}),b.subParser("hashBlock",function(a,b,c){"use strict";return a=a.replace(/(^\n+|\n+$)/g,""),"\n\n~K"+(c.gHtmlBlocks.push(a)-1)+"K\n\n"}),b.subParser("hashElement",function(a,b,c){"use strict";return function(a,b){var d=b;return d=d.replace(/\n\n/g,"\n"),d=d.replace(/^\n/,""),d=d.replace(/\n+$/g,""),d="\n\n~K"+(c.gHtmlBlocks.push(d)-1)+"K\n\n"}}),b.subParser("hashHTMLBlocks",function(a,c,d){"use strict";return a=a.replace(/\n/g,"\n\n"),a=a.replace(/^(<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del)\b[^\r]*?\n<\/\2>[ \t]*(?=\n+))/gm,b.subParser("hashElement")(a,c,d)),a=a.replace(/^(<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|style|section|header|footer|nav|article|aside)\b[^\r]*?<\/\2>[ \t]*(?=\n+)\n)/gm,b.subParser("hashElement")(a,c,d)),a=a.replace(/(\n[ ]{0,3}(<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g,b.subParser("hashElement")(a,c,d)),a=a.replace(/(\n\n[ ]{0,3}<!(--[^\r]*?--\s*)+>[ \t]*(?=\n{2,}))/g,b.subParser("hashElement")(a,c,d)),a=a.replace(/(?:\n\n)([ ]{0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g,b.subParser("hashElement")(a,c,d)),a=a.replace(/\n\n/g,"\n")}),b.subParser("headers",function(a,c,d){"use strict";function e(a){var c,e=a.replace(/[^\w]/g,"").toLowerCase();return d.hashLinkCounts[e]?c=e+"-"+d.hashLinkCounts[e]++:(c=e,d.hashLinkCounts[e]=1),f===!0&&(f="section"),b.helper.isString(f)?f+c:c}var f=c.prefixHeaderId;return a=a.replace(/^(.+)[ \t]*\n=+[ \t]*\n+/gm,function(a,f){var g=b.subParser("spanGamut")(f,c,d),h='<h1 id="'+e(f)+'">'+g+"</h1>";return b.subParser("hashBlock")(h,c,d)}),a=a.replace(/^(.+)[ \t]*\n-+[ \t]*\n+/gm,function(a,f){var g=b.subParser("spanGamut")(f,c,d),h='<h2 id="'+e(f)+'">'+g+"</h2>";return b.subParser("hashBlock")(h,c,d)}),a=a.replace(/^(\#{1,6})[ \t]*(.+?)[ \t]*\#*\n+/gm,function(a,f,g){var h=b.subParser("spanGamut")(g,c,d),i="<h"+f.length+' id="'+e(g)+'">'+h+"</h"+f.length+">";return b.subParser("hashBlock")(i,c,d)})}),b.subParser("images",function(a,c,d){"use strict";var e=function(a,c,e,f,g,h,i,j){a=c;var k=e,l=f.toLowerCase(),m=g,n=j,o=d.gUrls,p=d.gTitles;if(n||(n=""),""===m||null===m){if((""===l||null===l)&&(l=k.toLowerCase().replace(/ ?\n/g," ")),m="#"+l,"undefined"==typeof o[l])return a;m=o[l],"undefined"!=typeof p[l]&&(n=p[l])}k=k.replace(/"/g,"""),m=b.helper.escapeCharacters(m,"*_",!1);var q='<img src="'+m+'" alt="'+k+'"';return n=n.replace(/"/g,"""),n=b.helper.escapeCharacters(n,"*_",!1),q+=' title="'+n+'"',q+=" />"};return a=a.replace(/(!\[(.*?)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g,e),a=a.replace(/(!\[(.*?)\]\s?\([ \t]*()<?(\S+?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,e)}),b.subParser("italicsAndBold",function(a){"use strict";return a=a.replace(/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g,"<strong>$2</strong>"),a=a.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g,"<em>$2</em>")}),b.subParser("lists",function(a,c,d){"use strict";var e=function(a){return d.gListLevel++,a=a.replace(/\n{2,}$/,"\n"),a+="~0",a=a.replace(/(\n)?(^[ \t]*)([*+-]|\d+[.])[ \t]+([^\r]+?(\n{1,2}))(?=\n*(~0|\2([*+-]|\d+[.])[ \t]+))/gm,function(a,e,f,g,h){var i=b.subParser("outdent")(h,c,d);return e||i.search(/\n{2,}/)>-1?i=b.subParser("blockGamut")(i,c,d):(i=b.subParser("lists")(i,c,d),i=i.replace(/\n$/,""),i=b.subParser("spanGamut")(i,c,d)),"<li>"+i+"</li>\n"}),a=a.replace(/~0/g,""),d.gListLevel--,a};a+="~0";var f=/^(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm;return d.gListLevel?a=a.replace(f,function(a,b,c){var d=b,f=c.search(/[*+-]/g)>-1?"ul":"ol";d=d.replace(/\n{2,}/g,"\n\n\n");var g=e(d);return g=g.replace(/\s+$/,""),g="<"+f+">"+g+"</"+f+">\n"}):(f=/(\n\n|^\n?)(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/g,a=a.replace(f,function(a,b,c,d){var f=c.replace(/\n{2,}/g,"\n\n\n"),g=d.search(/[*+-]/g)>-1?"ul":"ol",h=e(f);return b+"<"+g+">\n"+h+"</"+g+">\n"})),a=a.replace(/~0/,"")}),b.subParser("outdent",function(a){"use strict";return a=a.replace(/^(\t|[ ]{1,4})/gm,"~0"),a=a.replace(/~0/g,"")}),b.subParser("paragraphs",function(a,c,d){"use strict";a=a.replace(/^\n+/g,""),a=a.replace(/\n+$/g,"");for(var e=a.split(/\n{2,}/g),f=[],g=e.length,h=0;g>h;h++){var i=e[h];i.search(/~K(\d+)K/g)>=0?f.push(i):i.search(/\S/)>=0&&(i=b.subParser("spanGamut")(i,c,d),i=i.replace(/^([ \t]*)/g,"<p>"),i+="</p>",f.push(i))}for(g=f.length,h=0;g>h;h++)for(;f[h].search(/~K(\d+)K/)>=0;){var j=d.gHtmlBlocks[RegExp.$1];j=j.replace(/\$/g,"$$$$"),f[h]=f[h].replace(/~K\d+K/,j)}return f.join("\n\n")}),b.subParser("spanGamut",function(a,c,d){"use strict";return a=b.subParser("codeSpans")(a,c,d),a=b.subParser("escapeSpecialCharsWithinTagAttributes")(a,c,d),a=b.subParser("encodeBackslashEscapes")(a,c,d),a=b.subParser("images")(a,c,d),a=b.subParser("anchors")(a,c,d),a=b.subParser("autoLinks")(a,c,d),a=b.subParser("encodeAmpsAndAngles")(a,c,d),a=b.subParser("italicsAndBold")(a,c,d),a=a.replace(/ +\n/g," <br />\n")}),b.subParser("stripBlankLines",function(a){"use strict";return a.replace(/^[ \t]+$/gm,"")}),b.subParser("stripLinkDefinitions",function(a,c,d){"use strict";var e=/^[ ]{0,3}\[(.+)]:[ \t]*\n?[ \t]*<?(\S+?)>?[ \t]*\n?[ \t]*(?:(\n*)["(](.+?)[")][ \t]*)?(?:\n+|(?=~0))/gm;return a+="~0",a=a.replace(e,function(a,c,e,f,g){return c=c.toLowerCase(),d.gUrls[c]=b.subParser("encodeAmpsAndAngles")(e),f?f+g:(g&&(d.gTitles[c]=g.replace(/"/g,""")),"")}),a=a.replace(/~0/,"")}),b.subParser("unescapeSpecialChars",function(a){"use strict";return a=a.replace(/~E(\d+)E/g,function(a,b){var c=parseInt(b);return String.fromCharCode(c)})});var e=this;"undefined"!=typeof module&&module.exports?module.exports=b:"function"==typeof define&&define.amd?define("showdown",function(){"use strict";return b}):e.showdown=b}).call(this);
|
|
//# sourceMappingURL=showdown.min.js.map
|