mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-04 23:26:02 -05:00
c997d1dc2b
GitOrigin-RevId: 32a43361cfc883aa1a5ed85f6be5432b6e838b9d
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { useRef, useEffect, type FC } from 'react'
|
|
import Linkify from 'react-linkify'
|
|
import useIsMounted from '../../../shared/hooks/use-is-mounted'
|
|
import { loadMathJax } from '../../mathjax/load-mathjax'
|
|
import { debugConsole } from '@/utils/debugging'
|
|
|
|
const MessageContent: FC<{ content: string }> = ({ content }) => {
|
|
const root = useRef<HTMLDivElement | null>(null)
|
|
const mounted = useIsMounted()
|
|
|
|
useEffect(() => {
|
|
if (root.current) {
|
|
// adds attributes to all the links generated by <Linkify/>, required due to https://github.com/tasti/react-linkify/issues/99
|
|
for (const a of root.current.getElementsByTagName('a')) {
|
|
a.setAttribute('target', '_blank')
|
|
a.setAttribute('rel', 'noreferrer noopener')
|
|
}
|
|
|
|
// MathJax v3 typesetting
|
|
loadMathJax()
|
|
.then(MathJax => {
|
|
if (mounted.current) {
|
|
MathJax.typesetPromise([root.current]).catch(debugConsole.error)
|
|
}
|
|
})
|
|
.catch(debugConsole.error)
|
|
}
|
|
}, [content, mounted])
|
|
|
|
return (
|
|
<p ref={root}>
|
|
<Linkify>{content}</Linkify>
|
|
</p>
|
|
)
|
|
}
|
|
|
|
export default MessageContent
|