12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454 |
- var Showdown = { extensions: {} };
- var forEach = Showdown.forEach = function(obj, callback) {
- if (typeof obj.forEach === 'function') {
- obj.forEach(callback);
- } else {
- var i, len = obj.length;
- for (i = 0; i < len; i++) {
- callback(obj[i], i, obj);
- }
- }
- };
- var stdExtName = function(s) {
- return s.replace(/[_-]||\s/g, '').toLowerCase();
- };
- Showdown.converter = function(converter_options) {
- var g_urls;
- var g_titles;
- var g_html_blocks;
- var g_list_level = 0;
- var g_lang_extensions = [];
- var g_output_modifiers = [];
- if (typeof module !== 'undefind' && typeof exports !== 'undefined' && typeof require !== 'undefind') {
- var fs = require('fs');
- if (fs) {
-
- var extensions = fs.readdirSync((__dirname || '.')+'/extensions').filter(function(file){
- return ~file.indexOf('.js');
- }).map(function(file){
- return file.replace(/\.js$/, '');
- });
-
- Showdown.forEach(extensions, function(ext){
- var name = stdExtName(ext);
- Showdown.extensions[name] = require('./extensions/' + ext);
- });
- }
- }
- this.makeHtml = function(text) {
-
-
-
-
- g_urls = {};
- g_titles = {};
- g_html_blocks = [];
-
-
-
-
- text = text.replace(/~/g,"~T");
-
-
-
- text = text.replace(/\$/g,"~D");
-
- text = text.replace(/\r\n/g,"\n");
- text = text.replace(/\r/g,"\n");
-
- text = "\n\n" + text + "\n\n";
-
- text = _Detab(text);
-
-
-
-
- text = text.replace(/^[ \t]+$/mg,"");
-
- Showdown.forEach(g_lang_extensions, function(x){
- text = _ExecuteExtension(x, text);
- });
-
-
- text = _DoGithubCodeBlocks(text);
-
- text = _HashHTMLBlocks(text);
-
- text = _StripLinkDefinitions(text);
- text = _RunBlockGamut(text);
- text = _UnescapeSpecialChars(text);
-
- text = text.replace(/~D/g,"$$");
-
- text = text.replace(/~T/g,"~");
-
- Showdown.forEach(g_output_modifiers, function(x){
- text = _ExecuteExtension(x, text);
- });
- return text;
- };
- if (converter_options && converter_options.extensions) {
- var self = this;
-
- Showdown.forEach(converter_options.extensions, function(plugin){
-
- if (typeof plugin === 'string') {
- plugin = Showdown.extensions[stdExtName(plugin)];
- }
- if (typeof plugin === 'function') {
-
- Showdown.forEach(plugin(self), function(ext){
-
- if (ext.type) {
- if (ext.type === 'language' || ext.type === 'lang') {
- g_lang_extensions.push(ext);
- } else if (ext.type === 'output' || ext.type === 'html') {
- g_output_modifiers.push(ext);
- }
- } else {
-
- g_output_modifiers.push(ext);
- }
- });
- } else {
- throw "Extension '" + plugin + "' could not be loaded. It was either not found or is not a valid extension.";
- }
- });
- }
- var _ExecuteExtension = function(ext, text) {
- if (ext.regex) {
- var re = new RegExp(ext.regex, 'g');
- return text.replace(re, ext.replace);
- } else if (ext.filter) {
- return ext.filter(text);
- }
- };
- var _StripLinkDefinitions = function(text) {
-
-
-
- text += "~0";
- text = text.replace(/^[ ]{0,3}\[(.+)\]:[ \t]*\n?[ \t]*<?(\S+?)>?[ \t]*\n?[ \t]*(?:(\n*)["(](.+?)[")][ \t]*)?(?:\n+|(?=~0))/gm,
- function (wholeMatch,m1,m2,m3,m4) {
- m1 = m1.toLowerCase();
- g_urls[m1] = _EncodeAmpsAndAngles(m2);
- if (m3) {
-
-
- return m3+m4;
- } else if (m4) {
- g_titles[m1] = m4.replace(/"/g,""");
- }
-
- return "";
- }
- );
-
- text = text.replace(/~0/,"");
- return text;
- }
- var _HashHTMLBlocks = function(text) {
-
- text = text.replace(/\n/g,"\n\n");
-
-
-
-
-
-
- var block_tags_a = "p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del|style|section|header|footer|nav|article|aside";
- var block_tags_b = "p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|style|section|header|footer|nav|article|aside";
-
-
-
-
-
-
-
-
-
-
-
-
-
- text = text.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,hashElement);
-
-
-
-
- text = text.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,hashElement);
-
-
-
- text = text.replace(/(\n[ ]{0,3}(<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g,hashElement);
-
-
- text = text.replace(/(\n\n[ ]{0,3}<!(--[^\r]*?--\s*)+>[ \t]*(?=\n{2,}))/g,hashElement);
-
-
- text = text.replace(/(?:\n\n)([ ]{0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g,hashElement);
-
- text = text.replace(/\n\n/g,"\n");
- return text;
- }
- var hashElement = function(wholeMatch,m1) {
- var blockText = m1;
-
- blockText = blockText.replace(/\n\n/g,"\n");
- blockText = blockText.replace(/^\n/,"");
-
- blockText = blockText.replace(/\n+$/g,"");
-
- blockText = "\n\n~K" + (g_html_blocks.push(blockText)-1) + "K\n\n";
- return blockText;
- };
- var _RunBlockGamut = function(text) {
- text = _DoHeaders(text);
-
- var key = hashBlock("<hr />");
- text = text.replace(/^[ ]{0,2}([ ]?\*[ ]?){3,}[ \t]*$/gm,key);
- text = text.replace(/^[ ]{0,2}([ ]?\-[ ]?){3,}[ \t]*$/gm,key);
- text = text.replace(/^[ ]{0,2}([ ]?\_[ ]?){3,}[ \t]*$/gm,key);
- text = _DoLists(text);
- text = _DoCodeBlocks(text);
- text = _DoBlockQuotes(text);
-
-
-
-
- text = _HashHTMLBlocks(text);
- text = _FormParagraphs(text);
- return text;
- };
- var _RunSpanGamut = function(text) {
- text = _DoCodeSpans(text);
- text = _EscapeSpecialCharsWithinTagAttributes(text);
- text = _EncodeBackslashEscapes(text);
-
-
- text = _DoImages(text);
- text = _DoAnchors(text);
-
-
-
- text = _DoAutoLinks(text);
- text = _EncodeAmpsAndAngles(text);
- text = _DoItalicsAndBold(text);
-
- text = text.replace(/ +\n/g," <br />\n");
- return text;
- }
- var _EscapeSpecialCharsWithinTagAttributes = function(text) {
-
-
- var regex = /(<[a-z\/!$]("[^"]*"|'[^']*'|[^'">])*>|<!(--.*?--\s*)+>)/gi;
- text = text.replace(regex, function(wholeMatch) {
- var tag = wholeMatch.replace(/(.)<\/?code>(?=.)/g,"$1`");
- tag = escapeCharacters(tag,"\\`*_");
- return tag;
- });
- return text;
- }
- var _DoAnchors = function(text) {
-
-
-
-
- text = text.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g,writeAnchorTag);
-
-
-
-
- text = text.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\]\([ \t]*()<?(.*?(?:\(.*?\).*?)?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,writeAnchorTag);
-
-
-
-
-
-
- text = text.replace(/(\[([^\[\]]+)\])()()()()()/g, writeAnchorTag);
- return text;
- }
- var writeAnchorTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {
- if (m7 == undefined) m7 = "";
- var whole_match = m1;
- var link_text = m2;
- var link_id = m3.toLowerCase();
- var url = m4;
- var title = m7;
- if (url == "") {
- if (link_id == "") {
-
- link_id = link_text.toLowerCase().replace(/ ?\n/g," ");
- }
- url = "#"+link_id;
- if (g_urls[link_id] != undefined) {
- url = g_urls[link_id];
- if (g_titles[link_id] != undefined) {
- title = g_titles[link_id];
- }
- }
- else {
- if (whole_match.search(/\(\s*\)$/m)>-1) {
-
- url = "";
- } else {
- return whole_match;
- }
- }
- }
- url = escapeCharacters(url,"*_");
- var result = "<a href=\"" + url + "\"";
- if (title != "") {
- title = title.replace(/"/g,""");
- title = escapeCharacters(title,"*_");
- result += " title=\"" + title + "\"";
- }
- result += ">" + link_text + "</a>";
- return result;
- }
- var _DoImages = function(text) {
-
-
-
-
- text = text.replace(/(!\[(.*?)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g,writeImageTag);
-
-
-
-
- text = text.replace(/(!\[(.*?)\]\s?\([ \t]*()<?(\S+?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,writeImageTag);
- return text;
- }
- var writeImageTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {
- var whole_match = m1;
- var alt_text = m2;
- var link_id = m3.toLowerCase();
- var url = m4;
- var title = m7;
- if (!title) title = "";
- if (url == "") {
- if (link_id == "") {
-
- link_id = alt_text.toLowerCase().replace(/ ?\n/g," ");
- }
- url = "#"+link_id;
- if (g_urls[link_id] != undefined) {
- url = g_urls[link_id];
- if (g_titles[link_id] != undefined) {
- title = g_titles[link_id];
- }
- }
- else {
- return whole_match;
- }
- }
- alt_text = alt_text.replace(/"/g,""");
- url = escapeCharacters(url,"*_");
- var result = "<img src=\"" + url + "\" alt=\"" + alt_text + "\"";
-
-
-
- title = title.replace(/"/g,""");
- title = escapeCharacters(title,"*_");
- result += " title=\"" + title + "\"";
-
- result += " />";
- return result;
- }
- var _DoHeaders = function(text) {
-
-
-
-
-
-
-
- text = text.replace(/^(.+)[ \t]*\n=+[ \t]*\n+/gm,
- function(wholeMatch,m1){return hashBlock('<h1 id="' + headerId(m1) + '">' + _RunSpanGamut(m1) + "</h1>");});
- text = text.replace(/^(.+)[ \t]*\n-+[ \t]*\n+/gm,
- function(matchFound,m1){return hashBlock('<h2 id="' + headerId(m1) + '">' + _RunSpanGamut(m1) + "</h2>");});
-
-
-
-
-
-
-
-
- text = text.replace(/^(\#{1,6})[ \t]*(.+?)[ \t]*\#*\n+/gm,
- function(wholeMatch,m1,m2) {
- var h_level = m1.length;
- return hashBlock("<h" + h_level + ' id="' + headerId(m2) + '">' + _RunSpanGamut(m2) + "</h" + h_level + ">");
- });
- function headerId(m) {
- return m.replace(/[^\w]/g, '').toLowerCase();
- }
- return text;
- }
- var _ProcessListItems;
- var _DoLists = function(text) {
-
-
- text += "~0";
-
-
- var whole_list = /^(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm;
- if (g_list_level) {
- text = text.replace(whole_list,function(wholeMatch,m1,m2) {
- var list = m1;
- var list_type = (m2.search(/[*+-]/g)>-1) ? "ul" : "ol";
-
-
- list = list.replace(/\n{2,}/g,"\n\n\n");;
- var result = _ProcessListItems(list);
-
-
-
-
- result = result.replace(/\s+$/,"");
- result = "<"+list_type+">" + result + "</"+list_type+">\n";
- return result;
- });
- } else {
- whole_list = /(\n\n|^\n?)(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/g;
- text = text.replace(whole_list,function(wholeMatch,m1,m2,m3) {
- var runup = m1;
- var list = m2;
- var list_type = (m3.search(/[*+-]/g)>-1) ? "ul" : "ol";
-
-
- var list = list.replace(/\n{2,}/g,"\n\n\n");;
- var result = _ProcessListItems(list);
- result = runup + "<"+list_type+">\n" + result + "</"+list_type+">\n";
- return result;
- });
- }
-
- text = text.replace(/~0/,"");
- return text;
- }
- _ProcessListItems = function(list_str) {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- g_list_level++;
-
- list_str = list_str.replace(/\n{2,}$/,"\n");
-
- list_str += "~0";
-
- list_str = list_str.replace(/(\n)?(^[ \t]*)([*+-]|\d+[.])[ \t]+([^\r]+?(\n{1,2}))(?=\n*(~0|\2([*+-]|\d+[.])[ \t]+))/gm,
- function(wholeMatch,m1,m2,m3,m4){
- var item = m4;
- var leading_line = m1;
- var leading_space = m2;
- if (leading_line || (item.search(/\n{2,}/)>-1)) {
- item = _RunBlockGamut(_Outdent(item));
- }
- else {
-
- item = _DoLists(_Outdent(item));
- item = item.replace(/\n$/,"");
- item = _RunSpanGamut(item);
- }
- return "<li>" + item + "</li>\n";
- }
- );
-
- list_str = list_str.replace(/~0/g,"");
- g_list_level--;
- return list_str;
- }
- var _DoCodeBlocks = function(text) {
-
-
- text += "~0";
- text = text.replace(/(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=~0))/g,
- function(wholeMatch,m1,m2) {
- var codeblock = m1;
- var nextChar = m2;
- codeblock = _EncodeCode( _Outdent(codeblock));
- codeblock = _Detab(codeblock);
- codeblock = codeblock.replace(/^\n+/g,"");
- codeblock = codeblock.replace(/\n+$/g,"");
- codeblock = "<pre><code>" + codeblock + "\n</code></pre>";
- return hashBlock(codeblock) + nextChar;
- }
- );
-
- text = text.replace(/~0/,"");
- return text;
- };
- var _DoGithubCodeBlocks = function(text) {
-
- text += "~0";
- text = text.replace(/(?:^|\n)```(.*)\n([\s\S]*?)\n```/g,
- function(wholeMatch,m1,m2) {
- var language = m1;
- var codeblock = m2;
- codeblock = _EncodeCode(codeblock);
- codeblock = _Detab(codeblock);
- codeblock = codeblock.replace(/^\n+/g,"");
- codeblock = codeblock.replace(/\n+$/g,"");
- codeblock = "<pre><code" + (language ? " class=\"" + language + '"' : "") + ">" + codeblock + "\n</code></pre>";
- return hashBlock(codeblock);
- }
- );
-
- text = text.replace(/~0/,"");
- return text;
- }
- var hashBlock = function(text) {
- text = text.replace(/(^\n+|\n+$)/g,"");
- return "\n\n~K" + (g_html_blocks.push(text)-1) + "K\n\n";
- }
- var _DoCodeSpans = function(text) {
-
- text = text.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,
- function(wholeMatch,m1,m2,m3,m4) {
- var c = m3;
- c = c.replace(/^([ \t]*)/g,"");
- c = c.replace(/[ \t]*$/g,"");
- c = _EncodeCode(c);
- return m1+"<code>"+c+"</code>";
- });
- return text;
- }
- var _EncodeCode = function(text) {
-
-
- text = text.replace(/&/g,"&");
-
- text = text.replace(/</g,"<");
- text = text.replace(/>/g,">");
-
- text = escapeCharacters(text,"\*_{}[]\\",false);
- return text;
- }
- var _DoItalicsAndBold = function(text) {
-
- text = text.replace(/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g,
- "<strong>$2</strong>");
- text = text.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g,
- "<em>$2</em>");
- return text;
- }
- var _DoBlockQuotes = function(text) {
-
- text = text.replace(/((^[ \t]*>[ \t]?.+\n(.+\n)*\n*)+)/gm,
- function(wholeMatch,m1) {
- var bq = m1;
-
-
- bq = bq.replace(/^[ \t]*>[ \t]?/gm,"~0");
-
- bq = bq.replace(/~0/g,"");
- bq = bq.replace(/^[ \t]+$/gm,"");
- bq = _RunBlockGamut(bq);
- bq = bq.replace(/(^|\n)/g,"$1 ");
-
- bq = bq.replace(
- /(\s*<pre>[^\r]+?<\/pre>)/gm,
- function(wholeMatch,m1) {
- var pre = m1;
-
- pre = pre.replace(/^ /mg,"~0");
- pre = pre.replace(/~0/g,"");
- return pre;
- });
- return hashBlock("<blockquote>\n" + bq + "\n</blockquote>");
- });
- return text;
- }
- var _FormParagraphs = function(text) {
-
- text = text.replace(/^\n+/g,"");
- text = text.replace(/\n+$/g,"");
- var grafs = text.split(/\n{2,}/g);
- var grafsOut = [];
-
-
-
- var end = grafs.length;
- for (var i=0; i<end; i++) {
- var str = grafs[i];
-
- if (str.search(/~K(\d+)K/g) >= 0) {
- grafsOut.push(str);
- }
- else if (str.search(/\S/) >= 0) {
- str = _RunSpanGamut(str);
- str = str.replace(/^([ \t]*)/g,"<p>");
- str += "</p>"
- grafsOut.push(str);
- }
- }
-
-
-
- end = grafsOut.length;
- for (var i=0; i<end; i++) {
-
- while (grafsOut[i].search(/~K(\d+)K/) >= 0) {
- var blockText = g_html_blocks[RegExp.$1];
- blockText = blockText.replace(/\$/g,"$$$$");
- grafsOut[i] = grafsOut[i].replace(/~K\d+K/,blockText);
- }
- }
- return grafsOut.join("\n\n");
- }
- var _EncodeAmpsAndAngles = function(text) {
-
-
- text = text.replace(/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/g,"&");
-
- text = text.replace(/<(?![a-z\/?\$!])/gi,"<");
- return text;
- }
- var _EncodeBackslashEscapes = function(text) {
-
-
-
-
-
-
-
-
- text = text.replace(/\\(\\)/g,escapeCharacters_callback);
- text = text.replace(/\\([`*_{}\[\]()>#+-.!])/g,escapeCharacters_callback);
- return text;
- }
- var _DoAutoLinks = function(text) {
- text = text.replace(/<((https?|ftp|dict):[^'">\s]+)>/gi,"<a href=\"$1\">$1</a>");
-
-
- text = text.replace(/<(?:mailto:)?([-.\w]+\@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi,
- function(wholeMatch,m1) {
- return _EncodeEmailAddress( _UnescapeSpecialChars(m1) );
- }
- );
- return text;
- }
- var _EncodeEmailAddress = function(addr) {
- var encode = [
- function(ch){return "&#"+ch.charCodeAt(0)+";";},
- function(ch){return "&#x"+ch.charCodeAt(0).toString(16)+";";},
- function(ch){return ch;}
- ];
- addr = "mailto:" + addr;
- addr = addr.replace(/./g, function(ch) {
- if (ch == "@") {
-
- ch = encode[Math.floor(Math.random()*2)](ch);
- } else if (ch !=":") {
-
- var r = Math.random();
-
- ch = (
- r > .9 ? encode[2](ch) :
- r > .45 ? encode[1](ch) :
- encode[0](ch)
- );
- }
- return ch;
- });
- addr = "<a href=\"" + addr + "\">" + addr + "</a>";
- addr = addr.replace(/">.+:/g,"\">");
- return addr;
- }
- var _UnescapeSpecialChars = function(text) {
- text = text.replace(/~E(\d+)E/g,
- function(wholeMatch,m1) {
- var charCodeToReplace = parseInt(m1);
- return String.fromCharCode(charCodeToReplace);
- }
- );
- return text;
- }
- var _Outdent = function(text) {
-
-
- text = text.replace(/^(\t|[ ]{1,4})/gm,"~0");
-
- text = text.replace(/~0/g,"")
- return text;
- }
- var _Detab = function(text) {
-
- text = text.replace(/\t(?=\t)/g," ");
-
- text = text.replace(/\t/g,"~A~B");
-
- text = text.replace(/~B(.+?)~A/g,
- function(wholeMatch,m1,m2) {
- var leadingText = m1;
- var numSpaces = 4 - leadingText.length % 4;
-
- for (var i=0; i<numSpaces; i++) leadingText+=" ";
- return leadingText;
- }
- );
-
- text = text.replace(/~A/g," ");
- text = text.replace(/~B/g,"");
- return text;
- }
- var escapeCharacters = function(text, charsToEscape, afterBackslash) {
-
-
- var regexString = "([" + charsToEscape.replace(/([\[\]\\])/g,"\\$1") + "])";
- if (afterBackslash) {
- regexString = "\\\\" + regexString;
- }
- var regex = new RegExp(regexString,"g");
- text = text.replace(regex,escapeCharacters_callback);
- return text;
- }
- var escapeCharacters_callback = function(wholeMatch,m1) {
- var charCodeToEscape = m1.charCodeAt(0);
- return "~E"+charCodeToEscape+"E";
- }
- }
- if (typeof module !== 'undefined') module.exports = Showdown;
- if (typeof define === 'function' && define.amd) {
- define('showdown', function() {
- return Showdown;
- });
- }
|