-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
36 lines (33 loc) · 1.13 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { createHighlighterCoreSync } from "shiki/core";
import { createJavaScriptRegexEngine } from "shiki/engine/javascript";
import { bundledLanguages } from "shiki/langs";
import { bundledThemes } from "shiki/themes";
import type { SyntaxHighlighterFunctions } from "@asciidoctor/core";
const engine = createJavaScriptRegexEngine();
const langs = await Promise.all(
Object.values(bundledLanguages).map((importFn) =>
importFn().then((m) => m.default)
),
);
const themes = await Promise.all(
Object.values(bundledThemes).map((importFn) =>
importFn().then((m) => m.default)
),
);
const shiki = createHighlighterCoreSync({ themes, langs, engine });
const AsciidoctorShiki: SyntaxHighlighterFunctions = {
initialize(_name, _backend, { document }) {
this.options = { theme: "github-light-default" };
if (document.hasAttribute("shiki-theme")) {
this.options.theme = document.getAttribute("shiki-theme");
}
this.super();
},
highlight(_node, content, lang) {
return shiki.codeToHtml(content, { lang, ...this.options });
},
handlesHighlighting() {
return true;
},
};
export default AsciidoctorShiki;