mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-05-30 01:55:17 +08:00
fix: support echart function option (#19424)
This commit is contained in:
parent
b4064fa092
commit
198fbb9b3d
@ -128,13 +128,19 @@ const CodeBlock: any = memo(({ inline, className, children = '', ...props }: any
|
|||||||
const language = match?.[1]
|
const language = match?.[1]
|
||||||
const languageShowName = getCorrectCapitalizationLanguageName(language || '')
|
const languageShowName = getCorrectCapitalizationLanguageName(language || '')
|
||||||
const chartData = useMemo(() => {
|
const chartData = useMemo(() => {
|
||||||
|
const str = String(children).replace(/\n$/, '')
|
||||||
if (language === 'echarts') {
|
if (language === 'echarts') {
|
||||||
try {
|
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 { }
|
catch { }
|
||||||
}
|
}
|
||||||
return JSON.parse('{"title":{"text":"ECharts error - Wrong JSON format."}}')
|
return JSON.parse('{"title":{"text":"ECharts error - Wrong option."}}')
|
||||||
}, [language, children])
|
}, [language, children])
|
||||||
|
|
||||||
const renderCodeContent = useMemo(() => {
|
const renderCodeContent = useMemo(() => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user