This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
forked from speced/respec
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e98ef2
commit a9a97c0
Showing
4 changed files
with
48 additions
and
17 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,33 @@ | ||
// ReSpec Worker v0 | ||
// ReSpec Worker v0.1.0 | ||
"use strict"; | ||
importScripts("https://www.w3.org/Tools/respec/respec-highlight.js"); | ||
|
||
hljs.configure({ | ||
tabReplace: " ", // 2 spaces | ||
languages: [ | ||
"css", | ||
"http", | ||
"javascript", | ||
"json", | ||
"markdown", | ||
"xml", | ||
], | ||
}); | ||
|
||
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); | ||
try { | ||
self.postMessage(data); | ||
} catch (err) { | ||
console.error("Could not transform some code?", err); | ||
// Post back the original unhighlighted code. | ||
const fallbackData = Object.assign({}, e.data, { value: e.data.code }); | ||
self.postMessage(fallbackData); | ||
} | ||
} | ||
}); |
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