Skip to content

Commit 47bdcfe

Browse files
Steve DaySteve Day
authored andcommitted
Move default highlight.js highlighting into a web worker
1 parent 2cd3622 commit 47bdcfe

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

public/js/highlight.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// A very simple web worker for highlight.js
2+
// See: https://highlightjs.org/usage/
3+
onmessage = function(event) {
4+
importScripts('/vendor/plugins/highlight/highlight.pack.js');
5+
var result = self.hljs.highlightAuto(event.data);
6+
postMessage(result.value);
7+
}

public/js/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1430,7 +1430,13 @@ $(document).ready(function () {
14301430

14311431
// Highlight JS
14321432
if (typeof hljs != 'undefined') {
1433-
hljs.initHighlightingOnLoad();
1433+
$('pre code').each(function (index, element) {
1434+
var worker = new Worker('/js/highlight-worker.js');
1435+
worker.onmessage = function(event) {
1436+
$(element).html(event.data);
1437+
}
1438+
worker.postMessage($(element).text());
1439+
});
14341440
}
14351441

14361442
// Dropzone

0 commit comments

Comments
 (0)