{children};
} else {
- return - +
{children};
- } else {
- return {children}
; -}); - -const Markdown = React.memo(({ content, message, showCursor }: TContentProps) => { - const [cursor, setCursor] = useState('█'); - const isSubmitting = useRecoilValue(store.isSubmitting); - const latestMessage = useRecoilValue(store.latestMessage); - const isInitializing = content === '█'; - - const { isEdited, messageId } = message ?? {}; - const isLatestMessage = messageId === latestMessage?.messageId; - const currentContent = content?.replace('z-index: 1;', '') ?? ''; - - useEffect(() => { - let timer1: NodeJS.Timeout, timer2: NodeJS.Timeout; - - if (!showCursor) { - setCursor('ㅤ'); - return; - } - - if (isSubmitting && isLatestMessage) { - timer1 = setInterval(() => { - setCursor('ㅤ'); - timer2 = setTimeout(() => { - setCursor('█'); - }, 200); - }, 1000); - } else { - setCursor('ㅤ'); - } - - // This is the cleanup function that React will run when the component unmounts - return () => { - clearInterval(timer1); - clearTimeout(timer2); - }; - }, [isSubmitting, isLatestMessage, showCursor]); - - const rehypePlugins: PluggableList = [ - [rehypeKatex, { output: 'mathml' }], - [ - rehypeHighlight, - { - detect: true, - ignoreMissing: true, - subset: langSubset, - }, - ], - [rehypeRaw], - ]; - - let isValidIframe: string | boolean | null = false; - if (!isEdited) { - isValidIframe = validateIframe(currentContent); - } - - if (isEdited || ((!isInitializing || !isLatestMessage) && !isValidIframe)) { - rehypePlugins.pop(); - } - - return ( -