Load extensions using simple require() and index.js

Also don't load anything if we're in a browser
This commit is contained in:
Robbie Mackay 2014-12-16 15:12:38 +13:00
parent 053288f2fe
commit fd771cc7e8
2 changed files with 9 additions and 17 deletions

7
src/extensions/index.js Normal file
View File

@ -0,0 +1,7 @@
// Return all extensions
module.exports = {
github : require('./github'),
prettify : require('./prettify'),
table : require('./table'),
twitter : require('./twitter')
};

View File

@ -116,23 +116,8 @@ var g_output_modifiers = [];
// //
// Automatic Extension Loading (node only): // Automatic Extension Loading (node only):
// //
if (typeof window === 'undefined' && typeof module !== 'undefined' && typeof exports !== 'undefined' && typeof require !== 'undefined') {
if (typeof module !== 'undefind' && typeof exports !== 'undefined' && typeof require !== 'undefind') { Showdown.extensions = require('./extensions');
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);
});
}
} }
this.makeHtml = function(text) { this.makeHtml = function(text) {