Skip to content

Commit

Permalink
initialize plugins before the formatters (#822)
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 authored Jun 25, 2021
1 parent 576c691 commit 6cdfc5a
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 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 @@ -450,12 +449,21 @@ export default function SCEditor(original, userOptions) {

var FormatCtor = SCEditor.formats[options.format];
format = FormatCtor ? new FormatCtor() : {};
/*
* 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 @@ -491,17 +499,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 @@ -534,7 +531,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 6cdfc5a

Please sign in to comment.