import { Icon } from '@lobehub/ui'; import { useThemeMode } from 'antd-style'; import { Loader2 } from 'lucide-react'; import { memo, useEffect } from 'react'; import { Center } from 'react-layout-kit'; import { type HighlighterOptions } from 'shiki-es'; import { useStyles } from './style'; import { useHighlight } from './useHighlight'; export interface SyntaxHighlighterProps { children: string; language: string; options?: HighlighterOptions; } const SyntaxHighlighter = memo(({ children, language, options }) => { const { styles } = useStyles(); const { isDarkMode } = useThemeMode(); const [codeToHtml, isLoading] = useHighlight((s) => [s.codeToHtml, !s.highlighter]); useEffect(() => { useHighlight.getState().initHighlighter(options); }, [options]); return ( <> {isLoading ? ( {children} ) : (
)} {isLoading && (
Highlighting...
)} ); }); export default SyntaxHighlighter;