highlight/highlight-worker.js

24 lines
572 B
JavaScript
Raw Normal View History

2019-11-15 00:09:40 +08:00
/*!
* WordPress highlight
* https://github.com/ineo6/wordpress-highlight
*/
importScripts('https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.16.2/build/highlight.min.js');
onmessage = function (event) {
var data = JSON.parse(event.data);
2019-11-19 14:41:33 +08:00
try {
var result = self.hljs.highlight(data.lang, data.code);
} catch (e) {
var result = self.hljs.highlightAuto(data.code);
}
2019-11-15 00:09:40 +08:00
2019-11-18 18:12:37 +08:00
postMessage(JSON.stringify({
result: {
value: result.value,
2019-11-19 14:41:33 +08:00
language: result.language,
2019-11-18 18:12:37 +08:00
}, index: data.index
}));
2019-11-15 00:09:40 +08:00
};