diff --git a/docs/plugins/markdown/markdown-chart/echarts.md b/docs/plugins/markdown/markdown-chart/echarts.md index c85be5bed6..5f88c7df42 100644 --- a/docs/plugins/markdown/markdown-chart/echarts.md +++ b/docs/plugins/markdown/markdown-chart/echarts.md @@ -78,7 +78,7 @@ If you can generate your chart data easily, you can just provide echarts config If you need to use script to get the data, you can use `js` or `javascript` code block. -We will expose the echarts instance as `myChart` in the script, and you are expected to assign the echarts option object to `option` variable. Also, you can assign `width` and `height` variable to set the chart size. +We will expose the echarts instance as `echarts` in the script, and you are expected to assign the echarts option object to `option` variable. Also, you can assign `width` and `height` variable to set the chart size. ````md ::: echarts Title diff --git a/plugins/markdown/plugin-markdown-chart/src/client/components/ChartJS.ts b/plugins/markdown/plugin-markdown-chart/src/client/components/ChartJS.ts index 2747e13b1b..41a223deac 100644 --- a/plugins/markdown/plugin-markdown-chart/src/client/components/ChartJS.ts +++ b/plugins/markdown/plugin-markdown-chart/src/client/components/ChartJS.ts @@ -28,9 +28,9 @@ __chart_js_config__=config; } return __chart_js_config__;\ `, - ) + ) as () => ChartConfiguration - return runner() as ChartConfiguration + return runner() } export default defineComponent({ diff --git a/plugins/markdown/plugin-markdown-chart/src/client/components/ECharts.ts b/plugins/markdown/plugin-markdown-chart/src/client/components/ECharts.ts index be6620c2fd..f58044af6b 100644 --- a/plugins/markdown/plugin-markdown-chart/src/client/components/ECharts.ts +++ b/plugins/markdown/plugin-markdown-chart/src/client/components/ECharts.ts @@ -27,12 +27,12 @@ const AsyncFunction = (async (): Promise => {}).constructor const parseEChartsConfig = ( config: string, type: 'js' | 'json', - myChart: EChartsType, + echarts: EChartsType, ): Promise => { if (type === 'js') { - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + // eslint-disable-next-line @typescript-eslint/no-unsafe-call const runner = AsyncFunction( - 'myChart', + 'echarts', `\ let width,height,option,__echarts_config__; { @@ -41,10 +41,9 @@ __echarts_config__={width,height,option}; } return __echarts_config__; `, - ) + ) as (echarts: EChartsType) => Promise - // eslint-disable-next-line @typescript-eslint/no-unsafe-call - return runner(myChart) as Promise + return runner(echarts) } return Promise.resolve({ option: JSON.parse(config) as EChartsOption }) diff --git a/plugins/markdown/plugin-markdown-chart/src/client/components/Mermaid.ts b/plugins/markdown/plugin-markdown-chart/src/client/components/Mermaid.ts index 9f5e23db46..9bb1b9b2c2 100644 --- a/plugins/markdown/plugin-markdown-chart/src/client/components/Mermaid.ts +++ b/plugins/markdown/plugin-markdown-chart/src/client/components/Mermaid.ts @@ -80,7 +80,6 @@ const getThemeVariables = (isDarkmode: boolean): MermaidThemeVariables => ({ }) export default defineComponent({ - // eslint-disable-next-line vue/multi-word-component-names name: 'Mermaid', props: { diff --git a/plugins/markdown/plugin-markdown-chart/src/client/typings/index.ts b/plugins/markdown/plugin-markdown-chart/src/client/typings/index.ts index c5960d4847..8f807c7121 100644 --- a/plugins/markdown/plugin-markdown-chart/src/client/typings/index.ts +++ b/plugins/markdown/plugin-markdown-chart/src/client/typings/index.ts @@ -1 +1 @@ -export * from './mermaid.js' +export type * from './mermaid.js' diff --git a/plugins/markdown/plugin-markdown-chart/src/node/index.ts b/plugins/markdown/plugin-markdown-chart/src/node/index.ts index b7e48b30b6..67a63436c3 100644 --- a/plugins/markdown/plugin-markdown-chart/src/node/index.ts +++ b/plugins/markdown/plugin-markdown-chart/src/node/index.ts @@ -1,3 +1,3 @@ export * from './markdown-it-plugins/index.js' export * from './markdownChartPlugin.js' -export * from './options.js' +export type * from './options.js' diff --git a/plugins/markdown/plugin-markdown-chart/src/node/markdown-it-plugins/chartJs.ts b/plugins/markdown/plugin-markdown-chart/src/node/markdown-it-plugins/chartJs.ts deleted file mode 100644 index fe63603296..0000000000 --- a/plugins/markdown/plugin-markdown-chart/src/node/markdown-it-plugins/chartJs.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { container } from '@mdit/plugin-container' -import { encodeData } from '@vuepress/helper' -import type { PluginSimple } from 'markdown-it' - -export const chartJs: PluginSimple = (md) => { - container(md, { - name: 'chartjs', - openRender: (tokens, index) => { - const title = tokens[index].info - .trimStart() - // "chart" length - .slice(5) - .trim() - - const key = `chartjs-${index}` - - let config = '{}' - let configType = '' - - for (let i = index; i < tokens.length; i++) { - const { type, content, info } = tokens[i] - - if (type === 'container_chartjs_close') break - - if (!content) continue - if (type === 'fence') - if (info === 'json') { - config = encodeData(content) - configType = 'json' - } else if (info === 'js' || info === 'javascript') { - config = encodeData(content) - configType = 'js' - } - - // Set to an unknown token type - tokens[i].type = 'chartjs_empty' - // Hide token - tokens[i].hidden = true - } - - return `` - }, - closeRender: () => ``, - }) -}