aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/app/highlight.ts
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-03-20 21:58:21 +0900
committernsfisis <nsfisis@gmail.com>2025-03-20 21:58:21 +0900
commitf1701822ed069d70841e8b40392e55bb28bf3eb6 (patch)
tree0e2ed30e98b3061dde4c83181af52fc081961590 /frontend/app/highlight.ts
parent1204620ab9852b5acf02d922e1679f28e58cc35d (diff)
downloadiosdc-japan-2025-albatross-f1701822ed069d70841e8b40392e55bb28bf3eb6.tar.gz
iosdc-japan-2025-albatross-f1701822ed069d70841e8b40392e55bb28bf3eb6.tar.zst
iosdc-japan-2025-albatross-f1701822ed069d70841e8b40392e55bb28bf3eb6.zip
fix(frontend): prevent flickering
Diffstat (limited to 'frontend/app/highlight.ts')
-rw-r--r--frontend/app/highlight.ts20
1 files changed, 20 insertions, 0 deletions
diff --git a/frontend/app/highlight.ts b/frontend/app/highlight.ts
new file mode 100644
index 0000000..1eea8a2
--- /dev/null
+++ b/frontend/app/highlight.ts
@@ -0,0 +1,20 @@
+import { toJsxRuntime } from "hast-util-to-jsx-runtime";
+import { Fragment, type JSX } from "react";
+import { jsx, jsxs } from "react/jsx-runtime";
+import { type BundledLanguage, codeToHast } from "./shiki.bundle";
+
+export type { BundledLanguage };
+
+// https://shiki.matsu.io/packages/next
+export async function highlight(code: string, lang: BundledLanguage) {
+ const out = await codeToHast(code.trimEnd(), {
+ lang,
+ theme: "github-light",
+ });
+
+ return toJsxRuntime(out, {
+ Fragment,
+ jsx,
+ jsxs,
+ }) as JSX.Element;
+}