Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
1.8 kB · 58 lines
TSX
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859import type { OctaneNode } from "octane";import { ShikiProvider, type SupportedLanguage } from "octane-kumo/code/custom";
export const chatSyntaxLanguages = [ "javascript", "typescript", "json", "bash", "python", "html", "css", "sql",] as const satisfies readonly SupportedLanguage[];
const languageLoaders = { javascript: () => import("@shikijs/langs/javascript"), typescript: () => import("@shikijs/langs/typescript"), json: () => import("@shikijs/langs/json"), bash: () => import("@shikijs/langs/bash"), python: () => import("@shikijs/langs/python"), html: () => import("@shikijs/langs/html"), css: () => import("@shikijs/langs/css"), sql: () => import("@shikijs/langs/sql"),} as const;
async function createChatHighlighter(languages: SupportedLanguage[]) { const [{ createHighlighterCore }, engine, light, dark, ...grammars] = await Promise.all([ import("shiki/core"), import("shiki/engine/javascript"), import("@shikijs/themes/github-light"), import("@shikijs/themes/vesper"), ...languages.map((language) => { const load = languageLoaders[language as keyof typeof languageLoaders]; if (!load) throw new Error( `Unsupported chat syntax language requested: ${language}`, ); return load(); }), ]); return createHighlighterCore({ engine: engine.createJavaScriptRegexEngine(), themes: [light.default, dark.default], langs: grammars.map((grammar) => grammar.default), });}
export function ChatSyntaxProvider({ children }: { children: OctaneNode }) { return ( <ShikiProvider createHighlighter={createChatHighlighter} languages={[...chatSyntaxLanguages]} > {children} </ShikiProvider> );}