import { Loading3QuartersOutlined as Loading } from '@ant-design/icons'; import { useThemeMode } from 'antd-style'; import { memo, useState } from 'react'; import { Center, Flexbox } from 'react-layout-kit'; import { useStyles } from './Highlighter.style'; import type { HighlighterProps } from './index'; import { Prism } from './Prism'; import { useShiki } from './useShiki'; type SyntaxHighlighterProps = Pick< HighlighterProps, 'language' | 'type' | 'children' | 'syntaxThemes' >; const SyntaxHighlighter = memo( ({ children, language, type = 'shiki', syntaxThemes: syntaxTheme }) => { const { styles, theme } = useStyles(); const { isDarkMode } = useThemeMode(); const [loading, setLoading] = useState(false); const codeToHtml = useShiki({ onLoadingChange: setLoading, theme: syntaxTheme?.shiki }); switch (type) { case 'prism': return ( {children} ); default: case 'shiki': return ( <> {loading ? ( {children} ) : (
)} {loading && (
shiki 着色器准备中...
)} ); } }, ); export default SyntaxHighlighter;