Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: support echart function option (#19424)

Good Wood198fbb9b3de0
diff --git a/web/app/components/base/markdown.tsx b/web/app/components/base/markdown.tsx
index ca2ec727919..bc6fe0e43a2 100644
--- a/web/app/components/base/markdown.tsx
+++ b/web/app/components/base/markdown.tsx
@@ -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(() => {