fix: support echart function option (#19424)
This commit is contained in:
parent
b4064fa092
commit
198fbb9b3d
1 changed files with 8 additions and 2 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue