Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: move syntax highlight to worker (closes #964)
- Loading branch information
1 parent
be87714
commit 94ad1fe
Showing
3 changed files
with
76 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
"use strict"; | ||
define([], function() { | ||
return new Worker("/worker/respec-worker.js"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,27 @@ | ||
// ReSpec Worker v0 | ||
// ReSpec Worker v0.1.0 | ||
"use strict"; | ||
importScripts("/js/deps/highlight.js"); | ||
|
||
hljs.configure({ | ||
tabReplace: " ", // 2 spaces | ||
languages: [ | ||
"css", | ||
"http", | ||
"javascript", | ||
"json", | ||
"markdown", | ||
"xml", | ||
"xquery", | ||
], | ||
}); | ||
|
||
self.addEventListener("message", function(e) { | ||
switch (e.data.action) { | ||
case "highlight": | ||
const code = e.data.code; | ||
const langs = e.data.languages.length ? e.data.languages : undefined; | ||
const result = self.hljs.highlightAuto(code, langs); | ||
const data = Object.assign({}, e.data, result); | ||
self.postMessage(data); | ||
} | ||
}); |