diff --git a/src/lib/SCEditor.js b/src/lib/SCEditor.js index cec07846..2baa0e9c 100644 --- a/src/lib/SCEditor.js +++ b/src/lib/SCEditor.js @@ -312,7 +312,6 @@ export default function SCEditor(original, userOptions) { replaceEmoticons, handleCommand, initEditor, - initPlugins, initLocale, initToolBar, initOptions, @@ -449,12 +448,26 @@ export default function SCEditor(original, userOptions) { var FormatCtor = SCEditor.formats[options.format]; format = FormatCtor ? new FormatCtor() : {}; + if (!FormatCtor) { + throw new Error(`Format plugin not found: ${options.format}`); + } + + /* + * Plugins should be initialized before the formatters since + * they may wish to add or change formatting handlers and + * since the bbcode format caches its handlers, + * such changes must be done first. + */ + pluginManager = new PluginManager(base); + (options.plugins || '').split(',').forEach(function (plugin) { + pluginManager.register(plugin.trim()); + }); + if ('init' in format) { format.init.call(base); } // create the editor - initPlugins(); initEmoticons(); initToolBar(); initEditor(); @@ -490,17 +503,6 @@ export default function SCEditor(original, userOptions) { } }; - initPlugins = function () { - var plugins = options.plugins; - - plugins = plugins ? plugins.toString().split(',') : []; - pluginManager = new PluginManager(base); - - plugins.forEach(function (plugin) { - pluginManager.register(plugin.trim()); - }); - }; - /** * Init the locale variable with the specified locale if possible * @private @@ -533,7 +535,8 @@ export default function SCEditor(original, userOptions) { allowfullscreen: true }); - /* This needs to be done right after they are created because, + /* + * This needs to be done right after they are created because, * for any reason, the user may not want the value to be tinkered * by any filters. */