mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-01-04 15:52:25 -06:00
* 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
39 lines
941 B
TypeScript
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;
|