Files
shadcn-ui/apps/www/lib/highlight-code.ts
shadcn 7590fb7636 feat: lift mode (#3380)
* feat(www): wip break everything

* feat(www): wip chunks

* feat(www): wip chunk mode

* feat: lift mode

* feat: update chunks

* fix: resize in lift mode

* fix: hasLiftMode

* fix: types

* fix: toolbar

Thanks @mrnbpt

* chore: format check

* feat: add tracking for enable_lift_mode

* chore: format write

* docs: add changelog
2024-04-05 21:28:05 +04:00

36 lines
822 B
TypeScript

"use server"
import { promises as fs } from "fs"
import path from "path"
import { getHighlighter } from "shiki"
// Highlighting is failing in server components.
// Disabling this in development.
// TODO: Remove this when we figure out the issue.
const highlightCodeEnabled = process.env.NODE_ENV !== "development"
export async function highlightCode(code: string) {
if (!highlightCodeEnabled) {
return code
}
const editorTheme = await fs.readFile(
path.join(process.cwd(), "lib/themes/dark.json"),
"utf-8"
)
const highlighter = await getHighlighter({
langs: ["typescript"],
themes: [],
})
await highlighter.loadTheme(JSON.parse(editorTheme))
const html = await highlighter.codeToHtml(code, {
lang: "typescript",
theme: "Lambda Studio — Blackout",
})
return html
}