fix: support echart function option (#19424)

This commit is contained in:
Good Wood 2025-05-09 13:49:40 +08:00 committed by GitHub
parent b4064fa092
commit 198fbb9b3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -128,13 +128,19 @@ const CodeBlock: any = memo(({ inline, className, children = '', ...props }: any
const language = match?.[1]
const languageShowName = getCorrectCapitalizationLanguageName(language || '')
const chartData = useMemo(() => {
const str = String(children).replace(/\n$/, '')
if (language === 'echarts') {
try {
return JSON.parse(String(children).replace(/\n$/, ''))
return JSON.parse(str)
}
catch { }
try {
// eslint-disable-next-line no-new-func, sonarjs/code-eval
return new Function(`return ${str}`)()
}
catch { }
}
return JSON.parse('{"title":{"text":"ECharts error - Wrong JSON format."}}')
return JSON.parse('{"title":{"text":"ECharts error - Wrong option."}}')
}, [language, children])
const renderCodeContent = useMemo(() => {