Skip to content

Commit

Permalink
Explicitly make the Worker close itself after highlighting, so that u…
Browse files Browse the repository at this point in the history
…sers have control on this behaviour when directly using Prism inside a Worker. Fix #492
  • Loading branch information
Golmote committed Sep 3, 2015
1 parent 2d37800 commit e42a228
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
10 changes: 7 additions & 3 deletions components/prism-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ var _ = _self.Prism = {

worker.postMessage(JSON.stringify({
language: env.language,
code: env.code
code: env.code,
immediateClose: true
}));
}
else {
Expand Down Expand Up @@ -393,10 +394,13 @@ if (!_self.document) {
_self.addEventListener('message', function(evt) {
var message = JSON.parse(evt.data),
lang = message.language,
code = message.code;
code = message.code,
immediateClose = message.immediateClose;

_self.postMessage(JSON.stringify(_.util.encode(_.tokenize(code, _.languages[lang]))));
_self.close();
if (immediateClose) {
_self.close();
}
}, false);

return _self.Prism;
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.

10 changes: 7 additions & 3 deletions prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ var _ = _self.Prism = {

worker.postMessage(JSON.stringify({
language: env.language,
code: env.code
code: env.code,
immediateClose: true
}));
}
else {
Expand Down Expand Up @@ -398,10 +399,13 @@ if (!_self.document) {
_self.addEventListener('message', function(evt) {
var message = JSON.parse(evt.data),
lang = message.language,
code = message.code;
code = message.code,
immediateClose = message.immediateClose;

_self.postMessage(JSON.stringify(_.util.encode(_.tokenize(code, _.languages[lang]))));
_self.close();
if (immediateClose) {
_self.close();
}
}, false);

return _self.Prism;
Expand Down

0 comments on commit e42a228

Please sign in to comment.