From fd771cc7e8d934cf06aefb1f7b32d68fbdb4ff09 Mon Sep 17 00:00:00 2001 From: Robbie Mackay Date: Tue, 16 Dec 2014 15:12:38 +1300 Subject: [PATCH] Load extensions using simple require() and index.js Also don't load anything if we're in a browser --- src/extensions/index.js | 7 +++++++ src/showdown.js | 19 ++----------------- 2 files changed, 9 insertions(+), 17 deletions(-) create mode 100644 src/extensions/index.js diff --git a/src/extensions/index.js b/src/extensions/index.js new file mode 100644 index 0000000..2380be3 --- /dev/null +++ b/src/extensions/index.js @@ -0,0 +1,7 @@ +// Return all extensions +module.exports = { + github : require('./github'), + prettify : require('./prettify'), + table : require('./table'), + twitter : require('./twitter') +}; diff --git a/src/showdown.js b/src/showdown.js index b488bad..4ec8082 100644 --- a/src/showdown.js +++ b/src/showdown.js @@ -116,23 +116,8 @@ var g_output_modifiers = []; // // Automatic Extension Loading (node only): // - -if (typeof module !== 'undefind' && typeof exports !== 'undefined' && typeof require !== 'undefind') { - var fs = require('fs'); - - if (fs) { - // Search extensions folder - var extensions = fs.readdirSync((__dirname || '.')+'/extensions').filter(function(file){ - return ~file.indexOf('.js'); - }).map(function(file){ - return file.replace(/\.js$/, ''); - }); - // Load extensions into Showdown namespace - Showdown.forEach(extensions, function(ext){ - var name = stdExtName(ext); - Showdown.extensions[name] = require('./extensions/' + ext); - }); - } +if (typeof window === 'undefined' && typeof module !== 'undefined' && typeof exports !== 'undefined' && typeof require !== 'undefined') { + Showdown.extensions = require('./extensions'); } this.makeHtml = function(text) {