From 7c28d3752c8a20aa62fe267dfa1f2651bfefdbed Mon Sep 17 00:00:00 2001 From: Corey Innis Date: Thu, 1 Nov 2012 00:50:03 -0700 Subject: [PATCH] [#36] iterate with Showdown.forEach * browser support: [].forEach is not always available. * also using Showdown.forEach in the test suite, to set the pattern. --- src/showdown.js | 10 +++++----- test/run.js | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/showdown.js b/src/showdown.js index 6c24396..e47f882 100644 --- a/src/showdown.js +++ b/src/showdown.js @@ -128,7 +128,7 @@ if (typeof module !== 'undefind' && typeof exports !== 'undefined' && typeof req return file.replace(/\.js$/, ''); }); // Load extensions into Showdown namespace - extensions.forEach(function(ext){ + Showdown.forEach(extensions, function(ext){ var name = stdExtName(ext); Showdown.extensions[name] = require('./extensions/' + ext); }); @@ -143,7 +143,7 @@ if (typeof module !== 'undefind' && typeof exports !== 'undefined' && typeof req if (converter_options && converter_options.extensions) { // Iterate over each plugin - converter_options.extensions.forEach(function(plugin){ + Showdown.forEach(converter_options.extensions, function(plugin){ // Assume it's a bundled plugin if a string is given if (typeof plugin === 'string') { @@ -152,7 +152,7 @@ if (converter_options && converter_options.extensions) { if (typeof plugin === 'function') { // Iterate over each extension within that plugin - plugin(this).forEach(function(ext){ + Showdown.forEach(plugin(this), function(ext){ // Sort extensions by type if (ext.type) { if (ext.type === 'language' || ext.type === 'lang') { @@ -215,7 +215,7 @@ this.makeHtml = function(text) { text = text.replace(/^[ \t]+$/mg,""); // Run language extensions - g_lang_extensions.forEach(function(x){ + Showdown.forEach(g_lang_extensions, function(x){ text = _ExecuteExtension(x, text); }); @@ -240,7 +240,7 @@ this.makeHtml = function(text) { text = text.replace(/~T/g,"~"); // Run output modifiers - g_output_modifiers.forEach(function(x){ + Showdown.forEach(g_output_modifiers, function(x){ text = _ExecuteExtension(x, text); }); diff --git a/test/run.js b/test/run.js index 73a0b49..c10baf1 100644 --- a/test/run.js +++ b/test/run.js @@ -14,7 +14,7 @@ var runTestsInDir = function(dir, converter) { }); // Run each test case (markdown -> html) - cases.forEach(function(test){ + showdown.forEach(cases, function(test){ var name = test.replace(/[-.]/g, ' '); it (name, function(){ var mdpath = path.join(dir, test + '.md'), @@ -70,7 +70,7 @@ if (path.existsSync('test/extensions')) { }); // Run tests in each extension sub-folder - extensions.forEach(function(ext){ + showdown.forEach(extensions, function(ext){ // Make sure extension exists var src = 'src/extensions/' + ext + '.js'; if (!path.existsSync(src)) {