mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-01-02 14:49:54 -06:00
* feat: initial work expanding instrumentation * feat: automatically inject traceparent into metadata in instrumentor * feat: deprecate old attrs * feat: add new namespaced attrs * chore: version * fix: type bug * feat: tracing scheduled workflows * fix: don't need duplication * feat: convert timestamps to ISO * fix: warn on use of old methods * feat: changelog * fix: enum breakages * fix: docs * feat: add a couple of additional attrs to bulk events * cleanup: types * fix: comment * fix: example * feat: langfuse example * tweak: edge cases * feat: example cleanup * feat: examples * chore: gen * feat: langfuse docs * feat: extend docs * fix: lint * fix: disclaimer * fix: start and end whitespace * fix: rm langfuse for now * fix: rm langfuse trace pic * fix: ci config
74 lines
1.6 KiB
TypeScript
74 lines
1.6 KiB
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 dedentedCode = dedent(parsed);
|
|
const highlightedHtml = await codeToHtml(dedentedCode, {
|
|
lang: language.toLowerCase(),
|
|
theme: themeName,
|
|
});
|
|
|
|
setHtml(highlightedHtml);
|
|
};
|
|
|
|
asyncHighlight();
|
|
}, [parsed, language, themeName]);
|
|
|
|
return (
|
|
<>
|
|
<div dangerouslySetInnerHTML={{ __html: html }}></div>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default CodeStyleRender;
|
|
|
|
function dedent(code: string) {
|
|
const trimmedCode = code.replace(/^\n+|\n+$/g, "");
|
|
|
|
const lines = trimmedCode.split("\n");
|
|
const nonEmptyLines = lines.filter((line) => line.trim().length > 0);
|
|
|
|
if (nonEmptyLines.length === 0) {
|
|
return trimmedCode;
|
|
}
|
|
|
|
const minIndent = Math.min(
|
|
...nonEmptyLines.map((line) => {
|
|
const match = line.match(/^(\s*)/);
|
|
return match ? match[1].length : 0;
|
|
})
|
|
);
|
|
|
|
if (minIndent > 0) {
|
|
return lines
|
|
.map((line) => {
|
|
if (line.trim().length > 0) {
|
|
return line.slice(minIndent);
|
|
}
|
|
|
|
return line;
|
|
})
|
|
.join("\n");
|
|
}
|
|
|
|
return trimmedCode;
|
|
}
|