Files
hatchet/frontend/docs/components/code/CodeStyleRender.tsx
Gabe Ruttner c88a18180a docs: git driven snips -- on failure page (#1043)
* feat: universal tabs

* fix: consistent tab naming

* feat: paths

* wip: chunk parser

* wip: dynamic snips

* wip: components

* docs: annotated go

* docs: improved annotations

* chore: fix

* feat: on-failure

* todo: switch branch to main

* chore: lint

* chore: lint

* fix: resolved theme

* cache

* fix: theme again...

* todo list

* docs: shadcn

* docs: code example uses shadcn

* fix: build

* python note

* chore: lint

* chore: swap main

* feat: local story

* fix: is dev

* revert the change that broke vercel

* fix: redirect?

* feat: seo title
2024-11-18 15:50:51 -08:00

39 lines
941 B
TypeScript

"use client";
import { useTheme } from "nextra-theme-docs";
import React, { useEffect, useState, useMemo } from "react";
import { codeToHtml } from "shiki";
interface CodeStyleRenderProps {
parsed: string
language: string
}
const CodeStyleRender = ({ parsed, language }: CodeStyleRenderProps) => {
const [html, setHtml] = useState<string>("");
const theme = useTheme();
const themeName = useMemo(() => {
return theme.resolvedTheme === "dark" ? "github-dark" : "github-light"
}, [theme.resolvedTheme])
useEffect(() => {
const asyncHighlight = async () => {
const highlightedHtml = await codeToHtml(parsed, {
lang: language.toLowerCase(),
theme: themeName,
});
setHtml(highlightedHtml);
}
asyncHighlight();
}, [parsed, language, themeName]);
return <>
<div dangerouslySetInnerHTML={{ __html: html }}></div>
</>
};
export default CodeStyleRender;