diff --git a/README.md b/README.md
index 5c43866..869c864 100644
--- a/README.md
+++ b/README.md
@@ -51,6 +51,30 @@ export default () => {
};
```
+## 🛠 Custom renderer
+
+```jsx
+import { GPTVis, withDefaultChartCode, VisText } from '@antv/gpt-vis';
+
+const markdownContent = `
+本月共产生决策数量2,783个,环比增长15.2%。高优先级决策占比56.2%,呈现稳定上升趋势,预计下月将突破3,000大关。
+
+\`\`\`my-ui
+my data
+\`\`\`
+`;
+
+const customRenderers = { 'my-ui': ({ children }) =>
{children}
};
+const components = {
+ 'vis-text': VisText,
+ code: withDefaultChartCode({ languageRenderers: customRenderers }),
+};
+
+export default () => {
+ return {markdownContent};
+};
+```
+
## 💻 Development
```bash
diff --git a/README.zh-CN.md b/README.zh-CN.md
index c151971..c95bdf1 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -51,6 +51,30 @@ export default () => {
};
```
+## 🛠 定制渲染器
+
+```jsx
+import { GPTVis, withDefaultChartCode, VisText } from '@antv/gpt-vis';
+
+const markdownContent = `
+本月共产生决策数量2,783个,环比增长15.2%。高优先级决策占比56.2%,呈现稳定上升趋势,预计下月将突破3,000大关。
+
+\`\`\`my-ui
+my data
+\`\`\`
+`;
+
+const customRenderers = { 'my-ui': ({ children }) => {children}
};
+const components = {
+ 'vis-text': VisText,
+ code: withDefaultChartCode({ languageRenderers: customRenderers }),
+};
+
+export default () => {
+ return {markdownContent};
+};
+```
+
## 💻 本地开发
```bash
diff --git a/docs/guide/antd-design-x.md b/docs/guide/antd-design-x.md
index bdc3477..e5b1a0b 100644
--- a/docs/guide/antd-design-x.md
+++ b/docs/guide/antd-design-x.md
@@ -5,7 +5,7 @@ toc: content
order: 1
---
-## 1⃣️ 使用 Markdown 协议
+## 使用 Markdown 协议
1.定义图表 Markdown 代码块
@@ -101,7 +101,7 @@ export default () => {
};
```
-## 2⃣️ 使用结构化的数据
+## 使用结构化的数据
1. 定义你的图表数据
diff --git a/docs/guide/custome-markdown.md b/docs/guide/custome-markdown.md
new file mode 100644
index 0000000..df82b56
--- /dev/null
+++ b/docs/guide/custome-markdown.md
@@ -0,0 +1,34 @@
+---
+title: 扩展 MD 渲染器使用
+nav: { title: '指南', order: 0 }
+toc: content
+order: 2
+---
+
+## 扩展 react-markdown 使用
+
+```tsx | pure
+import React from 'react';
+import Markdown from 'react-markdown';
+import { withChartCode, withDefaultChartCode, ChartType, Line } from '@antv/gpt-vis';
+
+const markdownContent = `
+# GPT-VIS \n\nComponents for GPTs, generative AI, and LLM projects. Not only UI Components.
+
+Here’s a visualization of Haidilao's food delivery revenue from 2013 to 2022. You can see a steady increase over the years, with notable *growth* particularly in recent years.
+
+\`\`\`vis-chart
+{ "type": "line","data": [{"time":2013,"value":59.3},{"time":2014,"value":64.4},{"time":2015,"value":68.9},{"time":2016,"value":74.4},{"time":2017,"value":82.7},{"time":2018,"value":91.9},{"time":2019,"value":99.1},{"time":2020,"value":101.6},{"time":2021,"value":114.4},{"time":2022,"value":121}] }
+\`\`\`
+`;
+
+const CodeBlock = withChartCode({
+ components: { [ChartType.Line]: Line },
+});
+// 或
+// const CodeBlock = withDefaultChartCode();
+
+export default () => {
+ return {markdownContent};
+};
+```
diff --git a/docs/guide/customize-style.md b/docs/guide/customize-style.md
index 51bd412..754f27a 100644
--- a/docs/guide/customize-style.md
+++ b/docs/guide/customize-style.md
@@ -2,7 +2,7 @@
title: 定制样式
nav: { title: '指南', order: 0 }
toc: content
-order: 2
+order: 3
---
通过在 [ConfigProvider](/components/config-provider) 中传入样式属性,来配置图表组件的全局样式。
diff --git a/docs/guide/quick-start.md b/docs/guide/quick-start.md
index e375d39..97b2b26 100644
--- a/docs/guide/quick-start.md
+++ b/docs/guide/quick-start.md
@@ -11,31 +11,7 @@ order: 0
$ npm install @antv/gpt-vis --save
```
-## 🌰 示例
-
-### 📦 组件中使用
-
-```tsx | pure
-import React from 'react';
-import { Pie } from '@antv/gpt-vis';
-
-const data = [
- { category: '分类一', value: 27 },
- { category: '分类二', value: 25 },
- { category: '分类三', value: 18 },
- { category: '分类四', value: 15 },
- { category: '分类五', value: 10 },
- { category: '其他', value: 5 },
-];
-
-export default () => {
- return ;
-};
-```
-
-### 📝 Markdown 中使用
-
-#### 方式一:使用 GPTVis 组件
+## 🌰 使用
```tsx | pure
import React from 'react';
@@ -44,18 +20,10 @@ import { GPTVis } from '@antv/gpt-vis';
const markdownContent = `
# GPT-VIS \n\nComponents for GPTs, generative AI, and LLM projects. Not only UI Components.
+Here’s a visualization of Haidilao's food delivery revenue from 2013 to 2022. You can see a steady increase over the years, with notable *growth* particularly in recent years.
+
\`\`\`vis-chart
-{
- "type": "pie",
- "data": [
- { "category": "分类一", "value": 27 },
- { "category": "分类二", "value": 25 },
- { "category": "分类三", "value": 18 },
- { "category": "分类四", "value": 15 },
- { "category": "分类五", "value": 10 },
- { "category": "其他", "value": 5 }
- ]
-}
+{ "type": "line","data": [{"time":2013,"value":59.3},{"time":2014,"value":64.4},{"time":2015,"value":68.9},{"time":2016,"value":74.4},{"time":2017,"value":82.7},{"time":2018,"value":91.9},{"time":2019,"value":99.1},{"time":2020,"value":101.6},{"time":2021,"value":114.4},{"time":2022,"value":121}] }
\`\`\`
`;
@@ -64,34 +32,30 @@ export default () => {
};
```
-#### 方式二:扩展 react-markdown 使用
+## 🛠 定制渲染器
+
+业务定制 UI 场景,提供方便的扩展机制,支持标签和代码块扩展。
```tsx | pure
-import React from 'react';
-import Markdown from 'react-markdown';
-import { withDefaultChartCode } from '@antv/gpt-vis';
+import { GPTVis, withDefaultChartCode, VisText } from '@antv/gpt-vis';
const markdownContent = `
-# GPT-VIS \n\nComponents for GPTs, generative AI, and LLM projects. Not only UI Components.
-
-\`\`\`vis-chart
-{
- "type": "pie",
- "data": [
- { "name": "分类一", "value": 27 },
- { "name": "分类二", "value": 25 },
- { "name": "分类三", "value": 18 },
- { "name": "分类四", "value": 15 },
- { "name": "分类五", "value": 10 },
- { "name": "其他", "value": 5 }
- ]
-}
+\`\`\`my-ui
+my data
\`\`\`
+
+本月共产生决策数量2,783个,环比增长15.2%。高优先级决策占比56.2%,呈现稳定上升趋势,预计下月将突破3,000大关。
`;
-const CodeBlock = withDefaultChartCode();
+const customRenderers = {
+ 'my-ui': ({ children }) => {children}
,
+};
+const components = {
+ 'vis-text': VisText,
+ code: withDefaultChartCode({ languageRenderers: customRenderers }),
+};
export default () => {
- return {markdownContent};
+ return {markdownContent};
};
```
diff --git a/src/ChartCodeRender/demos/extra.tsx b/src/ChartCodeRender/demos/extra.tsx
index 6c7b22d..38a1ca1 100644
--- a/src/ChartCodeRender/demos/extra.tsx
+++ b/src/ChartCodeRender/demos/extra.tsx
@@ -1,31 +1,17 @@
+import type { CodeBlockComponent } from '@antv/gpt-vis';
import { GPTVis, withDefaultChartCode } from '@antv/gpt-vis';
import React from 'react';
/**
- * 自定义的 Kotlin 代码块渲染器
+ * 自定义代码块渲染器
*/
-const KotlinRenderer: React.FC<{
- className?: string;
- children: React.ReactNode;
-}> = ({ children }) => {
- return (
-
- {children}
-
- );
+const MyUIRenderer: CodeBlockComponent = ({ children }) => {
+ return {children}
;
};
const markdownContent = `
-\`\`\`kotlin
-// A Kotlin code block
-fun main() {
- println("Hello, world!")
-}
-\`\`\`
-
-\`\`\`javascript
-// Normal code block
-console.log('Hello World');
+\`\`\`my-ui
+my data ...
\`\`\`
\`\`\`vis-chart
@@ -46,7 +32,7 @@ console.log('Hello World');
// 自定义代码块渲染组件,NOTE: withDefaultChartCode 不要直接放入函数内部,避免重复渲染抖动问题!!!
const CodeComponent = withDefaultChartCode({
languageRenderers: {
- kotlin: KotlinRenderer,
+ 'my-ui': MyUIRenderer,
},
});
diff --git a/src/GPTVis/demos/code.tsx b/src/GPTVis/demos/code.tsx
index 07a0be1..e3de201 100644
--- a/src/GPTVis/demos/code.tsx
+++ b/src/GPTVis/demos/code.tsx
@@ -1,35 +1,24 @@
+import type { CodeBlockComponent } from '@antv/gpt-vis';
import { ChartType, GPTVis, PinMap, withChartCode } from '@antv/gpt-vis';
import React from 'react';
/**
- * 自定义的 Kotlin 代码块渲染器
+ * 自定义代码块渲染器
*/
-const KotlinRenderer = ({ children }) => {
- return (
-
- {children}
-
- );
+const MyUIRenderer: CodeBlockComponent = ({ children }) => {
+ return {children}
;
};
const components = {
code: withChartCode({
- languageRenderers: { kotlin: KotlinRenderer },
+ languageRenderers: { kotlin: MyUIRenderer },
components: { [ChartType.PinMap]: PinMap },
}),
};
const content = `
-\`\`\`kotlin
-// A Kotlin code block
-fun main() {
- println("Hello, world!")
-}
-\`\`\`
-
-\`\`\`javascript
-// Normal code block
-console.log('Hello World');
+\`\`\`my-ui
+my data ...
\`\`\`
\`\`\`vis-chart
diff --git a/src/index.ts b/src/index.ts
index 5bfee62..9ca8e80 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -2,6 +2,7 @@ export * from './export';
export { default as version } from './version';
export { withChartCode, withDefaultChartCode } from './ChartCodeRender';
+export type { CodeBlockComponent, WithChartCodeOptions } from './ChartCodeRender/type';
export { default as GPTVis, type GPTVisProps } from './GPTVis';
export * from './types';