浏览代码

fix: support echart function option (#19424)

tags/1.4.0
Good Wood 5 个月前
父节点
当前提交
198fbb9b3d
没有帐户链接到提交者的电子邮件
共有 1 个文件被更改,包括 8 次插入2 次删除
  1. 8
    2
      web/app/components/base/markdown.tsx

+ 8
- 2
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(() => {

正在加载...
取消
保存