Skip to content

Commit

Permalink
Add support for use inside of a web worker.
Browse files Browse the repository at this point in the history
With this change highlight.js can be loaded inside of a web worker using the importScripts function.
  • Loading branch information
frigus02 committed Oct 24, 2015
1 parent 125a9fa commit dd8bca9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ https://highlightjs.org/
// CommonJS.
if(typeof exports !== 'undefined') {
factory(exports);
} else {
} else if (typeof window !== 'undefined') {
// Export hljs globally even when using AMD for cases when this script
// is loaded with others that may still expect a global hljs.
window.hljs = factory({});
Expand All @@ -20,6 +20,11 @@ https://highlightjs.org/
return window.hljs;
});
}
} else if (typeof self !== 'undefined') {
// Export hljs to web worker.
self.hljs = factory({});
} else {
throw new Error('No global object found to bind hljs variable to.');
}

}(function(hljs) {
Expand Down

0 comments on commit dd8bca9

Please sign in to comment.