Skip to content

Commit

Permalink
initialize plugins before the formatters
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
live627 committed Apr 14, 2021
1 parent f5f9976 commit a1602c5
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/lib/SCEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ export default function SCEditor(original, userOptions) {
replaceEmoticons,
handleCommand,
initEditor,
initPlugins,
initLocale,
initToolBar,
initOptions,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
*/
Expand Down

0 comments on commit a1602c5

Please sign in to comment.