From 8b96a42fbcbe91490cd953f78de4f0637c279e7f Mon Sep 17 00:00:00 2001 From: Pavel Lang Date: Fri, 10 Aug 2012 02:01:00 +0200 Subject: [PATCH 1/2] Code cleanup * Arrays used as hashes replaced by object initializer `{}` and Array constructor calls replaced with array literal `[]` * `function char2hex(ch)` used in email obfuscation replaced with inline call `ch.charCodeAt(0).toString(16)` * **For clarity I edited only src/showdown.js script. There are also copy of file in `example` directory and minified version in `compressed` directory.** --- src/showdown.js | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/showdown.js b/src/showdown.js index 869d753..5043e14 100644 --- a/src/showdown.js +++ b/src/showdown.js @@ -100,9 +100,9 @@ this.makeHtml = function(text) { // from other articles when generating a page which contains more than // one article (e.g. an index page that shows the N most recent // articles): - g_urls = new Array(); - g_titles = new Array(); - g_html_blocks = new Array(); + g_urls = {}; + g_titles = {}; + g_html_blocks = []; // attacklab: Replace ~ with ~T // This lets us use tilde as an escape char to avoid md5 hashes @@ -1089,7 +1089,7 @@ var _FormParagraphs = function(text) { text = text.replace(/\n+$/g,""); var grafs = text.split(/\n{2,}/g); - var grafsOut = new Array(); + var grafsOut = []; // // Wrap

tags. @@ -1208,16 +1208,9 @@ var _EncodeEmailAddress = function(addr) { // mailing list: // - // attacklab: why can't javascript speak hex? - function char2hex(ch) { - var hexDigits = '0123456789ABCDEF'; - var dec = ch.charCodeAt(0); - return(hexDigits.charAt(dec>>4) + hexDigits.charAt(dec&15)); - } - var encode = [ function(ch){return "&#"+ch.charCodeAt(0)+";";}, - function(ch){return "&#x"+char2hex(ch)+";";}, + function(ch){return "&#x"+ch.charCodeAt(0).toString(16)+";";}, function(ch){return ch;} ]; From a67421ba2ac31d7e0b581ce9c594131674a1a666 Mon Sep 17 00:00:00 2001 From: Pavel Lang Date: Fri, 10 Aug 2012 02:35:20 +0200 Subject: [PATCH 2/2] Extension autoloading fix --- src/showdown.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/showdown.js b/src/showdown.js index 32c56c7..4eebedd 100644 --- a/src/showdown.js +++ b/src/showdown.js @@ -122,10 +122,10 @@ if (typeof module !== 'undefind' && typeof exports !== 'undefined' && typeof req if (fs) { // Search extensions folder - var extensions = fs.readdirSync('./src/extensions').filter(function(file){ + var extensions = fs.readdirSync((__dirname || '.')+'/extensions').filter(function(file){ return ~file.indexOf('.js'); }).map(function(file){ - return file.replace('.js', ''); + return file.replace(/\.js$/, ''); }); // Load extensions into Showdown namespace extensions.forEach(function(ext){