mirror of
https://github.com/stefanpejcic/openpanel
synced 2025-06-26 18:28:26 +00:00
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import React from "react";
|
|
import HighlightPrism, { Language, defaultProps } from "prism-react-renderer";
|
|
import theme from "prism-react-renderer/themes/nightOwl";
|
|
|
|
type Props = {
|
|
code: string;
|
|
language: Language;
|
|
size?: string;
|
|
};
|
|
|
|
export const Highlight = ({ code, language, size }: Props) => {
|
|
return (
|
|
<HighlightPrism
|
|
{...defaultProps}
|
|
theme={{
|
|
plain: {
|
|
...theme.plain,
|
|
backgroundColor: "transparent",
|
|
...(size ? { fontSize: size } : {}),
|
|
},
|
|
styles: theme.styles,
|
|
}}
|
|
code={code}
|
|
language={language}
|
|
>
|
|
{({ className, style, tokens, getLineProps, getTokenProps }) => (
|
|
<pre className={className} style={style}>
|
|
{tokens.map((line, i) => (
|
|
<div key={i} {...getLineProps({ line, key: i })}>
|
|
{line.map((token, key) => (
|
|
<span
|
|
key={key}
|
|
{...getTokenProps({
|
|
token,
|
|
key,
|
|
})}
|
|
/>
|
|
))}
|
|
</div>
|
|
))}
|
|
</pre>
|
|
)}
|
|
</HighlightPrism>
|
|
);
|
|
};
|