|
|
|
@ -27,6 +27,7 @@ import ThinkBlock from '@/app/components/base/markdown-blocks/think-block'
|
|
|
|
import { Theme } from '@/types/app'
|
|
|
|
import { Theme } from '@/types/app'
|
|
|
|
import useTheme from '@/hooks/use-theme'
|
|
|
|
import useTheme from '@/hooks/use-theme'
|
|
|
|
import cn from '@/utils/classnames'
|
|
|
|
import cn from '@/utils/classnames'
|
|
|
|
|
|
|
|
import SVGRenderer from './svg-gallery'
|
|
|
|
|
|
|
|
|
|
|
|
// Available language https://github.com/react-syntax-highlighter/react-syntax-highlighter/blob/master/AVAILABLE_LANGUAGES_HLJS.MD
|
|
|
|
// Available language https://github.com/react-syntax-highlighter/react-syntax-highlighter/blob/master/AVAILABLE_LANGUAGES_HLJS.MD
|
|
|
|
const capitalizationLanguageNameMap: Record<string, string> = {
|
|
|
|
const capitalizationLanguageNameMap: Record<string, string> = {
|
|
|
|
@ -136,14 +137,13 @@ const CodeBlock: any = memo(({ inline, className, children, ...props }: any) =>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Attention: SVGRenderer has xss vulnerability
|
|
|
|
else if (language === 'svg' && isSVG) {
|
|
|
|
// else if (language === 'svg' && isSVG) {
|
|
|
|
return (
|
|
|
|
// return (
|
|
|
|
<ErrorBoundary>
|
|
|
|
// <ErrorBoundary>
|
|
|
|
<SVGRenderer content={content} />
|
|
|
|
// <SVGRenderer content={content} />
|
|
|
|
</ErrorBoundary>
|
|
|
|
// </ErrorBoundary>
|
|
|
|
)
|
|
|
|
// )
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<SyntaxHighlighter
|
|
|
|
<SyntaxHighlighter
|
|
|
|
@ -240,19 +240,11 @@ const Link = ({ node, ...props }: any) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function escapeSVGTags(htmlString: string): string {
|
|
|
|
|
|
|
|
return htmlString.replace(/(<svg[\s\S]*?>)([\s\S]*?)(<\/svg>)/gi, (match: string, openTag: string, innerContent: string, closeTag: string): string => {
|
|
|
|
|
|
|
|
return openTag.replace(/</g, '<').replace(/>/g, '>')
|
|
|
|
|
|
|
|
+ innerContent.replace(/</g, '<').replace(/>/g, '>')
|
|
|
|
|
|
|
|
+ closeTag.replace(/</g, '<').replace(/>/g, '>')
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function Markdown(props: { content: string; className?: string; customDisallowedElements?: string[] }) {
|
|
|
|
export function Markdown(props: { content: string; className?: string; customDisallowedElements?: string[] }) {
|
|
|
|
const latexContent = flow([
|
|
|
|
const latexContent = flow([
|
|
|
|
preprocessThinkTag,
|
|
|
|
preprocessThinkTag,
|
|
|
|
preprocessLaTeX,
|
|
|
|
preprocessLaTeX,
|
|
|
|
])(escapeSVGTags(props.content))
|
|
|
|
])(props.content)
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div className={cn('markdown-body', '!text-text-primary', props.className)}>
|
|
|
|
<div className={cn('markdown-body', '!text-text-primary', props.className)}>
|
|
|
|
|