Skip to content

Commit

Permalink
Invoke callback after after-highlight hook (#1588)
Browse files Browse the repository at this point in the history
Previously, `callback`, as passed to `Prism.highlightElement`, would get called before
all of the hooks had been run. This moves it after all the hooks, so it can truly be considered
a "complete" callback.

This could be a breaking change for any userland modifications that were expecting `callback`
to fire before plugins, but we expect this change to mostly conform with user expectations and
consider this a bugfix..
  • Loading branch information
Jocs authored and mAAdhaTTah committed Oct 23, 2018
1 parent b41fb8f commit bfbe446
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
7 changes: 4 additions & 3 deletions components/prism-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ var _ = _self.Prism = {

env.element.innerHTML = env.highlightedCode;

callback && callback.call(env.element);
_.hooks.run('after-highlight', env);
_.hooks.run('complete', env);
callback && callback.call(env.element);
};

worker.postMessage(JSON.stringify({
Expand All @@ -267,10 +267,11 @@ var _ = _self.Prism = {

env.element.innerHTML = env.highlightedCode;

callback && callback.call(element);

_.hooks.run('after-highlight', env);

_.hooks.run('complete', env);

callback && callback.call(element);
}
},

Expand Down
2 changes: 1 addition & 1 deletion components/prism-core.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/prism-css.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ var _ = _self.Prism = {

env.element.innerHTML = env.highlightedCode;

callback && callback.call(env.element);
_.hooks.run('after-highlight', env);
_.hooks.run('complete', env);
callback && callback.call(env.element);
};

worker.postMessage(JSON.stringify({
Expand All @@ -272,10 +272,11 @@ var _ = _self.Prism = {

env.element.innerHTML = env.highlightedCode;

callback && callback.call(element);

_.hooks.run('after-highlight', env);

_.hooks.run('complete', env);

callback && callback.call(element);
}
},

Expand Down Expand Up @@ -684,6 +685,7 @@ if (Prism.languages.markup) {
}, Prism.languages.markup.tag);
}


/* **********************************************
Begin prism-clike.js
********************************************** */
Expand Down Expand Up @@ -889,4 +891,4 @@ Prism.languages.js = Prism.languages.javascript;

document.addEventListener('DOMContentLoaded', self.Prism.fileHighlight);

})();
})();

0 comments on commit bfbe446

Please sign in to comment.