import type { HighlighterCore } from "shiki"; import * as shikiModule from "shiki"; import { transformerColorizedBrackets } from "@shikijs/colorized-brackets"; import { createShikiState, initializeHighlighter, highlightCodeWithShiki, escapeHtml as coreEscapeHtml, ShikiState } from "dxUtils/shikiCore"; /** * Static loading version of Shiki. * Uses static imports - shiki is bundled with this module. * Use this for SSG compatibility and it is very specific to SSG generated components using LWR. */ const shikiState: ShikiState = createShikiState(); async function initializeShiki(): Promise { return initializeHighlighter(shikiState, shikiModule); } export async function highlightCode( code: string, language: string, theme: "light" | "dark" = "light" ): Promise { try { const highlighter = await initializeShiki(); return highlightCodeWithShiki( code, language, theme, highlighter, transformerColorizedBrackets ); } catch (error) { console.error("Failed to highlight code with Shiki:", error); return `
${escapeHtml(code)}
`; } } export function escapeHtml(text: string): string { return coreEscapeHtml(text); }