mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
4 lines
11 KiB
JavaScript
4 lines
11 KiB
JavaScript
|
/*! showdown 16-01-2015 */
|
||
|
|
||
|
(function(){"use strict";function a(a){return"string"==typeof a||a instanceof String}function b(a,b){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)}}function c(a){return a.constructor===Array}function d(a){return"undefined"==typeof a}var e={},f={},g={omitExtraWLInCodeBlocks:!1};e.helper={},e.extensions={},e.setOption=function(a,b){return g[a]=b,this},e.subParser=function(a,b){if(e.helper.isString(a)){if("undefined"==typeof b){if(f.hasOwnProperty(a))return f[a];throw Error("SubParser named "+a+" not registered!")}f[a]=b}},e.Converter=function(a){a=a||{};var b=g,c=["detab","stripBlankLines","githubCodeBlocks","hashHTMLBlocks","stripLinkDefinitions","blockGamut","unescapeSpecialChars"];if("object"==typeof a)for(var d in a)a.hasOwnProperty(d)&&(b[d]=a[d]);var e=function(a){if(!a)return a;var d={gHtmlBlocks:[],gUrls:{},gTitles:{},gListLevel:0};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 e=0;e<c.length;++e){var g=c[e];a=f[g](a,b,d)}return a=a.replace(/~D/g,"$$"),a=a.replace(/~T/g,"~")};return{makeHtml:e}};var h=function(a,b){var c=b.charCodeAt(0);return"~E"+c+"E"},i=function(a,b,c){var d="(["+b.replace(/([\[\]\\])/g,"\\$1")+"])";c&&(d="\\\\"+d);var e=new RegExp(d,"g");return a=a.replace(e,h)};e.hasOwnProperty("helper")||(e.helper={}),e.helper.isString=a,e.helper.forEach=b,e.helper.isArray=c,e.helper.isUndefined=d,e.helper.escapeCharactersCallback=h,e.helper.escapeCharacters=i,e.subParser("anchors",function(a,b,c){var d=function(a,b,d,f,g,h,i,j){e.helper.isUndefined(j)&&(j=""),a=b;var k=d,l=f.toLowerCase(),m=g,n=j;if(!m)if(l||(l=k.toLowerCase().replace(/ ?\n/g," ")),m="#"+l,e.helper.isUndefined(c.gUrls[l])){if(!(a.search(/\(\s*\)$/m)>-1))return a;m=""}else m=c.gUrls[l],e.helper.isUndefined(c.gTitles[l])||(n=c.gTitles[l]);m=e.helper.escapeCharacters(m,"*_");var o='<a href="'+m+'"';return""!==n&&null!==n&&(n=n.replace(/"/g,"""),n=e.helper.escapeCharacters(n,"*_"),o+=' title="'+n+'"'),o+=">"+k+"</a>"};return a=a.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g,d),a=a.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\]\([ \t]*()<?(.*?(?:\(.*?\).*?)?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,d),a=a.replace(/(\[([^\[\]]+)\])()()()()()/g,d)}),e.subParser("autoLinks",function(a){return a=a.replace(/<((https?|ftp|dict):[^'">\s]+)>/gi,'<a href="$1">$1</a>'),a=a.replace(/<(?:mailto:)?([-.\w]+\@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi,function(a,b){var c=e.subParser("unescapeSpecialChars")(b);return e.subParser("encodeEmailAddress")(c)})}),e.subParser("blockGamut",function(a,b,c){a=e.subParser("headers")(a,b,c);var d=e.subParser("hashBlock")("<hr />",b,c);return a=a.replace(/^[ ]{0,2}([ ]?\*[ ]?){3,}[ \t]*$/gm,d),a=a.replace(/^[ ]{0,2}([ ]?\-[ ]?){3,}[ \t]*$/gm,d),a=a.replace(/^[ ]{0,2}([ ]?\_[ ]?){3,}[ \t]*$/gm,d),a=e.subParser("lists")(a,b,c),a=e.subParser("codeBlocks")(a,b,c),a=e.subParser("blockQuotes")(a,b,c),a=e.subParser("hashHTMLBlocks")(a,b,c),a=e.subParser("paragraphs")(a,b,c)}),e.subParser("blockQuotes",function(a,b,c){return a=a.replace(/((^[ \t]*>[ \t]?.+\n(.+\n)*\n*)+)/gm,function(a,d){var f=d;return f=f.replace(/^[ \t]*>[ \t]?/gm,"~0"),f=f.replace(/~0/g,""),f=f.replace(/^[ \t]+$/gm,""),f=e.subParser("blockGamut")(f,b,c),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,"")}),e.subParser("hashBlock")("<blockquote>\n"+f+"\n</blockquote>",b,c)})}),e.subParser("codeBlocks",function(a,b,c){return a+="~0",a=a.replace(/(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=~0))/g,function(a,d,f){var g=d,h=f;return g=e.subParser("outdent")(g),g=e.subParser("encodeCode")(g),g=e.subParser("detab")(g),g=g.replace(/^\n+/g,""),g=g.replace(/\n+$/g,""),g="<pre><code>"+g+"\n</code></pre>",e.subParser("hashBlock")(g,b,c)+h}),a=a.replace(/~0/,"")}),e.subParser("codeSpans",function(a){return a=a.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,function(a,b,c,d){var f=d;return f=f.replace(/^([ \t]*)/g,""),f=f.repla
|
||
|
//# sourceMappingURL=showdown.min.js.map
|