From a1602c518373a9e9835b479dd8f52936f787fe9e Mon Sep 17 00:00:00 2001 From: John Rayes Date: Wed, 3 Mar 2021 12:43:51 -0700 Subject: [PATCH] initialize plugins before the formatters 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. --- src/lib/SCEditor.js | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) 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. */