ds-markdown 0.1.9-beta.6 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -43,6 +43,9 @@
43
43
  - **多主题与插件化架构**
44
44
  支持亮/暗主题切换,兼容 remark/rehype 插件,满足个性化和高级扩展需求。
45
45
 
46
+ - **丰富的UI组件系统** 🆕
47
+ 内置按钮、工具提示、分段控制器等UI组件,支持代码块复制、下载等交互功能。
48
+
46
49
  - **适用场景广泛**
47
50
  - AI 聊天机器人/助手
48
51
  - 实时问答/知识库
@@ -61,9 +64,12 @@
61
64
  - [禁用打字动画](#禁用打字动画)
62
65
  - [数学公式支持](#数学公式支持)
63
66
  - [AI 对话场景](#ai-对话场景)
67
+ - [代码块功能](#代码块功能) 🆕
68
+ - [Mermaid图表支持](#mermaid图表支持) 🆕
64
69
  - [📚 完整 API 文档](#-完整-api-文档)
65
70
  - [🧮 数学公式使用指南](#-数学公式使用指南)
66
71
  - [🔌 插件系统](#-插件系统)
72
+ - [🎨 UI组件系统](#-ui组件系统) 🆕
67
73
  - [🎛️ 定时器模式详解](#️-定时器模式详解)
68
74
  - [💡 实战示例](#-实战示例)
69
75
  - [🎯 高级回调控制](#-高级回调控制)
@@ -71,6 +77,7 @@
71
77
  - [▶️ 手动开始动画演示](#️-手动开始动画演示)
72
78
  - [📝 AI 流式对话](#-ai-流式对话)
73
79
  - [🧮 数学公式流式渲染](#-数学公式流式渲染)
80
+ - [📊 Mermaid图表流式渲染](#-mermaid图表流式渲染) 🆕
74
81
  - [多语言配置](#多语言配置)
75
82
  - [🔧 最佳实践](#-最佳实践)
76
83
 
@@ -88,13 +95,21 @@
88
95
 
89
96
  - 完整 Markdown 语法支持,包括代码高亮、表格、列表等
90
97
  - 数学公式渲染 (KaTeX),支持 `$...$` 和 `\[...\]` 语法
98
+ - Mermaid 图表支持,包括流程图、序列图、甘特图、类图等 🆕
91
99
  - 支持亮色/暗色主题,适配不同产品风格
92
100
  - 插件化架构,支持 remark/rehype 插件扩展
93
101
 
102
+ ### 🎨 **UI组件系统** 🆕
103
+
104
+ - 内置丰富的UI组件:Button、IconButton、ToolTip、Segmented等
105
+ - 代码块增强功能:复制、下载、语言标识
106
+ - 完整的交互体验和无障碍支持
107
+
94
108
  ### 🔧 **开发体验**
95
109
 
96
110
  - 支持打字中断 `stop` 和继续 `resume`
97
111
  - 支持打字关闭与开启
112
+ - 完整的TypeScript类型支持
98
113
 
99
114
  ### 🎬 **流畅动画**
100
115
 
@@ -240,6 +255,85 @@ React 19 带来了许多激动人心的新特性:
240
255
  }
241
256
  ```
242
257
 
258
+ ### 代码块功能 🆕
259
+
260
+ ```tsx
261
+ import DsMarkdown from 'ds-markdown';
262
+ import 'ds-markdown/style.css';
263
+
264
+ function CodeBlockDemo() {
265
+ const codeContent = `# Hello World
266
+
267
+ \`\`\`javascript
268
+ function greet(name) {
269
+ console.log(\`Hello, \${name}!\`);
270
+ }
271
+
272
+ greet('ds-markdown');
273
+ \`\`\`
274
+
275
+ 支持代码高亮、复制和下载功能!`;
276
+
277
+ return (
278
+ <DsMarkdown
279
+ interval={20}
280
+ answerType="answer"
281
+ codeBlock={{
282
+ headerActions: true, // 启用代码块头部操作按钮
283
+ }}
284
+ >
285
+ {codeContent}
286
+ </DsMarkdown>
287
+ );
288
+ }
289
+ ```
290
+
291
+ ### Mermaid图表支持 🆕
292
+
293
+ ```tsx
294
+ import DsMarkdown from 'ds-markdown';
295
+ import { ConfigProvider } from 'ds-markdown';
296
+ import mermaidPlugin from 'ds-markdown-mermaid-plugin';
297
+ import 'ds-markdown/style.css';
298
+
299
+ function MermaidDemo() {
300
+ const chartContent = `# 流程图示例
301
+
302
+ \`\`\`mermaid
303
+ flowchart TD
304
+ A[开始] --> B{判断条件}
305
+ B -->|是| C[处理A]
306
+ B -->|否| D[处理B]
307
+ C --> E[结束]
308
+ D --> E
309
+ \`\`\`
310
+
311
+ ## 序列图示例
312
+
313
+ \`\`\`mermaid
314
+ sequenceDiagram
315
+ participant 用户
316
+ participant 系统
317
+ participant 数据库
318
+
319
+ 用户->>系统: 登录请求
320
+ 系统->>数据库: 验证用户
321
+ 数据库-->>系统: 返回结果
322
+ 系统-->>用户: 登录响应
323
+ \`\`\`
324
+
325
+ 支持流程图、序列图、甘特图、类图等多种图表类型!`;
326
+
327
+ return (
328
+ <ConfigProvider>
329
+ <DsMarkdown interval={20} answerType="answer" plugins={[mermaidPlugin]}>
330
+ {chartContent}
331
+ </DsMarkdown>
332
+ </ConfigProvider>
333
+ );
334
+ }
335
+ ```
336
+
243
337
  ---
244
338
 
245
339
  ## 📚 完整 API 文档
@@ -300,14 +394,21 @@ import DsMarkdown, { MarkdownCMD } from 'ds-markdown';
300
394
  - `'dollar'`:使用 `$...$` 和 `$$...$$` 语法
301
395
  - `'bracket'`:使用 `\(...\)` 和 `\[...\]` 语法
302
396
 
397
+ #### IMarkdownCode 🆕
398
+
399
+ | 属性 | 类型 | 说明 | 默认值 |
400
+ | --------------- | --------- | -------------------- | ------ |
401
+ | `headerActions` | `boolean` | 是否显示头部操作按钮 | `true` |
402
+
303
403
  #### IMarkdownPlugin
304
404
 
305
- | 属性 | 类型 | 说明 | 默认值 |
306
- | -------------- | ------------------------- | ------------ | ------ |
307
- | `remarkPlugin` | `unknown` | remark 插件 | - |
308
- | `rehypePlugin` | `unknown` | rehype 插件 | - |
309
- | `type` | `'buildIn'` \| `'custom'` | 插件类型 | - |
310
- | `id` | `any` | 插件唯一标识 | - |
405
+ | 属性 | 类型 | 说明 | 默认值 |
406
+ | -------------- | ---------------------------------------------- | ----------------- | ------ |
407
+ | `remarkPlugin` | `Pluggable` | remark 插件 | - |
408
+ | `rehypePlugin` | `Pluggable` | rehype 插件 | - |
409
+ | `type` | `'buildIn'` \| `'custom'` | 插件类型 | - |
410
+ | `id` | `any` | 插件唯一标识 | - |
411
+ | `components` | `Record<string, React.ComponentType<unknown>>` | 自定义组件映射 🆕 | - |
311
412
 
312
413
  ### 组件暴露的方法
313
414
 
@@ -443,6 +544,82 @@ import { katexPlugin } from 'ds-markdown/plugins';
443
544
  <DsMarkdown plugins={[katexPlugin]}>数学公式:$E = mc^2$</DsMarkdown>;
444
545
  ```
445
546
 
547
+ #### Mermaid 图表插件 🆕
548
+
549
+ **安装 Mermaid 插件:**
550
+
551
+ ```bash
552
+ npm install ds-markdown-mermaid-plugin
553
+ ```
554
+
555
+ **基础用法:**
556
+
557
+ ```tsx
558
+ import { ConfigProvider, Markdown } from 'ds-markdown';
559
+ import mermaidPlugin from 'ds-markdown-mermaid-plugin';
560
+
561
+ function App() {
562
+ const content = `
563
+ # 流程图示例
564
+
565
+ \`\`\`mermaid
566
+ flowchart TD
567
+ A[开始] --> B{判断条件}
568
+ B -->|是| C[处理A]
569
+ B -->|否| D[处理B]
570
+ C --> E[结束]
571
+ D --> E
572
+ \`\`\`
573
+ `;
574
+
575
+ return (
576
+ <ConfigProvider>
577
+ <Markdown plugins={[mermaidPlugin]}>{content}</Markdown>
578
+ </ConfigProvider>
579
+ );
580
+ }
581
+ ```
582
+
583
+ **支持的图表类型:**
584
+
585
+ - 🔄 **流程图** (Flowchart) - 展示流程和决策路径
586
+ - 📋 **序列图** (Sequence Diagram) - 展示对象间的交互时序
587
+ - 📅 **甘特图** (Gantt Chart) - 项目计划和时间线
588
+ - 🏗️ **类图** (Class Diagram) - 面向对象设计
589
+ - 🥧 **饼图** (Pie Chart) - 数据比例展示
590
+ - 🔀 **状态图** (State Diagram) - 状态转换流程
591
+ - 📊 **Git图** (Git Graph) - 代码分支历史
592
+ - 🗺️ **用户旅程图** (User Journey) - 用户体验流程
593
+
594
+ **配置 Mermaid:**
595
+
596
+ ```tsx
597
+ import { ConfigProvider } from 'ds-markdown';
598
+
599
+ const mermaidConfig = {
600
+ theme: 'default', // 主题:default, neutral, dark, forest
601
+ flowchart: {
602
+ useMaxWidth: true,
603
+ htmlLabels: true,
604
+ },
605
+ sequence: {
606
+ diagramMarginX: 50,
607
+ diagramMarginY: 10,
608
+ },
609
+ };
610
+
611
+ return (
612
+ <ConfigProvider mermaidConfig={mermaidConfig}>
613
+ <Markdown plugins={[mermaidPlugin]}>{chartContent}</Markdown>
614
+ </ConfigProvider>
615
+ );
616
+ ```
617
+
618
+ **相关链接:**
619
+
620
+ - [ds-markdown-mermaid-plugin GitHub](https://github.com/onshinpei/ds-markdown-mermaid-plugin)
621
+ - [Mermaid 官方文档](https://mermaid.js.org/)
622
+
446
623
  ### 自定义插件
447
624
 
448
625
  ```tsx
@@ -453,6 +630,10 @@ const customPlugin = createBuildInPlugin({
453
630
  remarkPlugin: yourRemarkPlugin,
454
631
  rehypePlugin: yourRehypePlugin,
455
632
  id: Symbol('custom-plugin'),
633
+ components: {
634
+ // 自定义组件映射 🆕
635
+ CustomComponent: MyCustomComponent,
636
+ },
456
637
  });
457
638
 
458
639
  // 使用自定义插件
@@ -461,6 +642,197 @@ const customPlugin = createBuildInPlugin({
461
642
 
462
643
  ---
463
644
 
645
+ ## 🎨 UI组件系统 🆕
646
+
647
+ ds-markdown 提供了一套完整的UI组件系统,可以单独使用或与markdown组件配合。
648
+
649
+ ### Button 组件
650
+
651
+ 通用按钮组件,支持图标和自定义样式。
652
+
653
+ ```tsx
654
+ import { Button } from 'ds-markdown';
655
+
656
+ function ButtonDemo() {
657
+ return (
658
+ <Button icon={<span>📄</span>} onClick={() => console.log('clicked')} className="my-button">
659
+ 点击按钮
660
+ </Button>
661
+ );
662
+ }
663
+ ```
664
+
665
+ ### IconButton 组件
666
+
667
+ 图标按钮组件,适用于工具栏和操作区域。
668
+
669
+ ```tsx
670
+ import { IconButton } from 'ds-markdown';
671
+
672
+ function IconButtonDemo() {
673
+ return <IconButton icon={<span>📋</span>} onClick={() => console.log('copy')} className="my-icon-button" />;
674
+ }
675
+ ```
676
+
677
+ ### ToolTip 组件
678
+
679
+ 工具提示组件,提供悬停提示功能。
680
+
681
+ ```tsx
682
+ import { ToolTip } from 'ds-markdown';
683
+
684
+ function ToolTipDemo() {
685
+ return (
686
+ <ToolTip title="这是一个提示信息">
687
+ <button>悬停查看提示</button>
688
+ </ToolTip>
689
+ );
690
+ }
691
+ ```
692
+
693
+ ### Segmented 分段控制器
694
+
695
+ 分段控制器组件,适用于选项切换场景。
696
+
697
+ ```tsx
698
+ import { Segmented } from 'ds-markdown';
699
+ import { useState } from 'react';
700
+
701
+ function SegmentedDemo() {
702
+ const [value, setValue] = useState('diagram');
703
+
704
+ const options = [
705
+ { label: '图表', value: 'diagram' },
706
+ { label: '代码', value: 'code' },
707
+ ];
708
+
709
+ return <Segmented Segmented={options} value={value} onChange={setValue} />;
710
+ }
711
+ ```
712
+
713
+ ### 代码块组件
714
+
715
+ 代码块相关的交互组件,提供复制、下载等功能。
716
+
717
+ ```tsx
718
+ import { CodeBlockActions, CopyButton, DownloadButton, CodeBlockWrap, HighlightCode } from 'ds-markdown';
719
+
720
+ function MyCodeBlock() {
721
+ const codeContent = 'console.log("Hello World");';
722
+
723
+ return (
724
+ <div className="code-block">
725
+ {/* 完整的代码块操作组件 */}
726
+ <CodeBlockActions codeContent={codeContent} language="javascript" />
727
+
728
+ {/* 或者单独使用各个组件 */}
729
+ <CopyButton codeContent={codeContent} />
730
+ <DownloadButton codeContent={codeContent} language="javascript" />
731
+
732
+ {/* 代码块包装器 */}
733
+ <CodeBlockWrap language="javascript">
734
+ <HighlightCode code={codeContent} language="javascript" />
735
+ </CodeBlockWrap>
736
+ </div>
737
+ );
738
+ }
739
+ ```
740
+
741
+ ### UI组件完整API
742
+
743
+ #### Button Props
744
+
745
+ | 属性 | 类型 | 说明 | 默认值 |
746
+ | ----------- | --------------------- | ---------- | ------ |
747
+ | `className` | `string` | 自定义类名 | - |
748
+ | `children` | `React.ReactNode` | 按钮内容 | - |
749
+ | `icon` | `React.ReactNode` | 按钮图标 | - |
750
+ | `onClick` | `() => void` | 点击回调 | - |
751
+ | `style` | `React.CSSProperties` | 自定义样式 | - |
752
+
753
+ #### IconButton Props
754
+
755
+ | 属性 | 类型 | 说明 | 默认值 |
756
+ | ----------- | --------------------- | ---------- | ------ |
757
+ | `className` | `string` | 自定义类名 | - |
758
+ | `icon` | `React.ReactNode` | 图标内容 | - |
759
+ | `onClick` | `() => void` | 点击回调 | - |
760
+ | `style` | `React.CSSProperties` | 自定义样式 | - |
761
+
762
+ #### ToolTip Props
763
+
764
+ | 属性 | 类型 | 说明 | 默认值 |
765
+ | ---------- | ----------------- | -------- | ------ |
766
+ | `title` | `string` | 提示文本 | - |
767
+ | `children` | `React.ReactNode` | 子元素 | - |
768
+
769
+ #### Segmented Props
770
+
771
+ | 属性 | 类型 | 说明 | 默认值 |
772
+ | ----------- | ------------------------- | ---------- | ------ |
773
+ | `Segmented` | `SegmentedItem[]` | 选项列表 | - |
774
+ | `value` | `string` | 当前选中值 | - |
775
+ | `onChange` | `(value: string) => void` | 值变化回调 | - |
776
+
777
+ #### SegmentedItem
778
+
779
+ | 属性 | 类型 | 说明 | 默认值 |
780
+ | ------- | -------- | -------- | ------ |
781
+ | `label` | `string` | 显示文本 | - |
782
+ | `value` | `string` | 选项值 | - |
783
+
784
+ #### CodeBlockActions Props
785
+
786
+ | 属性 | 类型 | 说明 | 默认值 |
787
+ | ------------- | -------- | -------- | ------ |
788
+ | `codeContent` | `string` | 代码内容 | - |
789
+ | `language` | `string` | 代码语言 | - |
790
+
791
+ #### CopyButton Props
792
+
793
+ | 属性 | 类型 | 说明 | 默认值 |
794
+ | ------------- | --------------------- | ---------- | ------ |
795
+ | `codeContent` | `string` | 代码内容 | - |
796
+ | `style` | `React.CSSProperties` | 自定义样式 | - |
797
+
798
+ #### DownloadButton Props
799
+
800
+ | 属性 | 类型 | 说明 | 默认值 |
801
+ | ------------- | --------------------- | ---------- | ------ |
802
+ | `codeContent` | `string` | 代码内容 | - |
803
+ | `language` | `string` | 代码语言 | - |
804
+ | `style` | `React.CSSProperties` | 自定义样式 | - |
805
+
806
+ ### 样式定制
807
+
808
+ 所有UI组件都支持CSS变量定制:
809
+
810
+ ```css
811
+ :root {
812
+ /* 按钮样式 */
813
+ --ds-button-bg-color: #f5f5f5;
814
+ --ds-button-hover-color: #e0e0e0;
815
+ --ds-button-text-color: #333;
816
+
817
+ /* 工具提示样式 */
818
+ --ds-tooltip-bg-color: rgba(0, 0, 0, 0.8);
819
+ --ds-tooltip-text-color: white;
820
+
821
+ /* 分段控制器样式 */
822
+ --ds-segmented-bg-color: #f0f0f0;
823
+ --ds-segmented-active-color: #1890ff;
824
+ }
825
+
826
+ /* 暗色主题适配 */
827
+ [data-theme='dark'] {
828
+ --ds-button-bg-color: #333;
829
+ --ds-button-hover-color: #444;
830
+ --ds-button-text-color: #fff;
831
+ }
832
+ ```
833
+
834
+ ---
835
+
464
836
  ## 🎛️ 定时器模式详解
465
837
 
466
838
  ### `requestAnimationFrame` 模式 🌟 (推荐)
@@ -534,12 +906,50 @@ const App: React.FC = () => {
534
906
  import zhCN from 'ds-markdown/i18n/zh';
535
907
  ```
536
908
 
909
+ 包含字段:
910
+
911
+ ```typescript
912
+ {
913
+ codeBlock: {
914
+ copy: '复制',
915
+ copied: '已复制',
916
+ download: '下载',
917
+ },
918
+ mermaid: {
919
+ diagram: '图表',
920
+ code: '代码',
921
+ zoomOut: '缩小',
922
+ zoomIn: '放大',
923
+ download: '下载',
924
+ }
925
+ }
926
+ ```
927
+
537
928
  #### 英文 (enUS)
538
929
 
539
930
  ```tsx
540
931
  import enUS from 'ds-markdown/i18n/en';
541
932
  ```
542
933
 
934
+ 包含字段:
935
+
936
+ ```typescript
937
+ {
938
+ codeBlock: {
939
+ copy: 'Copy',
940
+ copied: 'Copied',
941
+ download: 'Download',
942
+ },
943
+ mermaid: {
944
+ diagram: 'Diagram',
945
+ code: 'Code',
946
+ zoomOut: 'Zoom Out',
947
+ zoomIn: 'Zoom In',
948
+ download: 'Download',
949
+ }
950
+ }
951
+ ```
952
+
543
953
  ### 在组件中使用语言包
544
954
 
545
955
  使用 `locale` 属性来切换自己想要的语言包,例如切换到英文
@@ -570,7 +980,14 @@ interface Locale {
570
980
  copied: string;
571
981
  download: string;
572
982
  };
573
- [key: string]: string;
983
+ mermaid: {
984
+ diagram: string;
985
+ code: string;
986
+ zoomOut: string;
987
+ zoomIn: string;
988
+ download: string;
989
+ };
990
+ [key: string]: any;
574
991
  }
575
992
  ```
576
993
 
@@ -907,6 +1324,82 @@ function MathStreamingDemo() {
907
1324
  }
908
1325
  ```
909
1326
 
1327
+ ### 📊 Mermaid图表流式渲染 🆕
1328
+
1329
+ ````tsx
1330
+ import { useRef } from 'react';
1331
+ import { MarkdownCMD, MarkdownCMDRef, ConfigProvider } from 'ds-markdown';
1332
+ import mermaidPlugin from 'ds-markdown-mermaid-plugin';
1333
+
1334
+ function MermaidStreamingDemo() {
1335
+ const markdownRef = useRef<MarkdownCMDRef>(null);
1336
+
1337
+ const simulateMermaidResponse = async () => {
1338
+ markdownRef.current?.clear();
1339
+
1340
+ const mermaidChunks = [
1341
+ '# 系统架构图\n\n',
1342
+ '```mermaid\n',
1343
+ 'flowchart TD\n',
1344
+ ' A[用户请求] --> B[负载均衡器]\n',
1345
+ ' B --> C[Web服务器]\n',
1346
+ ' B --> D[Web服务器]\n',
1347
+ ' C --> E[应用服务器]\n',
1348
+ ' D --> F[应用服务器]\n',
1349
+ ' E --> G[数据库]\n',
1350
+ ' F --> G\n',
1351
+ '```\n\n',
1352
+ '## 用户流程图\n\n',
1353
+ '```mermaid\n',
1354
+ 'sequenceDiagram\n',
1355
+ ' participant U as 用户\n',
1356
+ ' participant W as Web服务\n',
1357
+ ' participant A as API服务\n',
1358
+ ' participant D as 数据库\n',
1359
+ '\n',
1360
+ ' U->>W: 访问页面\n',
1361
+ ' W->>A: 请求数据\n',
1362
+ ' A->>D: 查询数据\n',
1363
+ ' D-->>A: 返回结果\n',
1364
+ ' A-->>W: 响应数据\n',
1365
+ ' W-->>U: 渲染页面\n',
1366
+ '```\n\n',
1367
+ '## 项目计划\n\n',
1368
+ '```mermaid\n',
1369
+ 'gantt\n',
1370
+ ' title 项目开发计划\n',
1371
+ ' dateFormat YYYY-MM-DD\n',
1372
+ ' section 设计阶段\n',
1373
+ ' 需求分析 :done, des1, 2024-01-01, 2024-01-10\n',
1374
+ ' 系统设计 :active, des2, 2024-01-11, 2024-01-25\n',
1375
+ ' section 开发阶段\n',
1376
+ ' 前端开发 :des3, 2024-01-26, 2024-02-15\n',
1377
+ ' 后端开发 :des4, 2024-01-26, 2024-02-20\n',
1378
+ ' 测试调试 :des5, 2024-02-21, 2024-02-28\n',
1379
+ '```\n\n',
1380
+ '支持多种图表类型的流式渲染,让技术文档更加生动!',
1381
+ ];
1382
+
1383
+ for (const chunk of mermaidChunks) {
1384
+ await delay(100);
1385
+ markdownRef.current?.push(chunk, 'answer');
1386
+ }
1387
+ };
1388
+
1389
+ const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
1390
+
1391
+ return (
1392
+ <div>
1393
+ <button onClick={simulateMermaidResponse}>🎨 展示 Mermaid 图表</button>
1394
+
1395
+ <ConfigProvider>
1396
+ <MarkdownCMD ref={markdownRef} interval={15} timerType="requestAnimationFrame" plugins={[mermaidPlugin]} />
1397
+ </ConfigProvider>
1398
+ </div>
1399
+ );
1400
+ }
1401
+ ````
1402
+
910
1403
  ## 🔧 最佳实践
911
1404
 
912
1405
  ### 1. 性能优化
@@ -952,11 +1445,104 @@ import { katexPlugin } from 'ds-markdown/plugins';
952
1445
  <DsMarkdown plugins={[katexPlugin]}>数学公式内容</DsMarkdown>;
953
1446
  ```
954
1447
 
955
- ### 4. 类型安全
1448
+ ### 4. UI组件使用 🆕
956
1449
 
957
1450
  ```tsx
958
- import { MarkdownCMDRef } from 'ds-markdown';
1451
+ // 推荐:按需导入UI组件
1452
+ import { Button, ToolTip, CopyButton } from 'ds-markdown';
1453
+
1454
+ // ✅ 推荐:组合使用UI组件
1455
+ <ToolTip title="复制代码">
1456
+ <CopyButton codeContent={code} />
1457
+ </ToolTip>
1458
+
1459
+ // ✅ 推荐:利用CSS变量定制主题
1460
+ :root {
1461
+ --ds-button-bg-color: your-brand-color;
1462
+ }
1463
+ ```
1464
+
1465
+ ### 5. 代码块最佳实践 🆕
1466
+
1467
+ ```tsx
1468
+ // ✅ 推荐:启用代码块操作
1469
+ <DsMarkdown
1470
+ codeBlock={{ headerActions: true }}
1471
+ // 其他配置...
1472
+ >
1473
+ {markdownContent}
1474
+ </DsMarkdown>;
1475
+
1476
+ // ✅ 推荐:自定义代码块组件
1477
+ import { CodeBlockWrap, HighlightCode } from 'ds-markdown';
1478
+
1479
+ const CustomCodeBlock = ({ code, language }) => (
1480
+ <CodeBlockWrap language={language}>
1481
+ <HighlightCode code={code} language={language} />
1482
+ {/* 添加自定义操作 */}
1483
+ </CodeBlockWrap>
1484
+ );
1485
+ ```
1486
+
1487
+ ### 6. 类型安全
1488
+
1489
+ ```tsx
1490
+ import { MarkdownCMDRef, useThemeState } from 'ds-markdown';
959
1491
 
960
1492
  const ref = useRef<MarkdownCMDRef>(null);
1493
+ const themeState = useThemeState(); // 🆕 获取主题状态
961
1494
  // 完整的 TypeScript 类型提示
962
1495
  ```
1496
+
1497
+ ### 7. 国际化最佳实践 🆕
1498
+
1499
+ ```tsx
1500
+ // ✅ 推荐:根据用户语言动态切换
1501
+ import { ConfigProvider } from 'ds-markdown';
1502
+ import zhCN from 'ds-markdown/i18n/zh';
1503
+ import enUS from 'ds-markdown/i18n/en';
1504
+
1505
+ const App = () => {
1506
+ const locale = userLanguage === 'zh' ? zhCN : enUS;
1507
+
1508
+ return (
1509
+ <ConfigProvider locale={locale}>
1510
+ <DsMarkdown {...props} />
1511
+ </ConfigProvider>
1512
+ );
1513
+ };
1514
+ ```
1515
+
1516
+ ### 8. Mermaid图表最佳实践 🆕
1517
+
1518
+ ````tsx
1519
+ // ✅ 推荐:独立安装Mermaid插件
1520
+ npm install ds-markdown-mermaid-plugin
1521
+
1522
+ // ✅ 推荐:配置适合的主题
1523
+ const mermaidConfig = {
1524
+ theme: 'default', // 根据应用主题选择
1525
+ startOnLoad: false, // 提升性能
1526
+ flowchart: {
1527
+ useMaxWidth: true, // 响应式设计
1528
+ },
1529
+ };
1530
+
1531
+ // ✅ 推荐:在ConfigProvider中统一配置
1532
+ <ConfigProvider mermaidConfig={mermaidConfig} locale={locale}>
1533
+ <DsMarkdown plugins={[mermaidPlugin]} />
1534
+ </ConfigProvider>
1535
+
1536
+ // ✅ 推荐:复杂图表分块渲染
1537
+ const complexChart = [
1538
+ '```mermaid\n',
1539
+ 'flowchart TD\n',
1540
+ ' A[开始] --> B[处理]\n',
1541
+ ' B --> C[结束]\n',
1542
+ '```\n',
1543
+ ];
1544
+
1545
+ // ✅ 推荐:使用语义化的节点命名
1546
+ // 好的例子:A[用户登录] --> B[验证凭据]
1547
+ // 避免:n1 --> n2
1548
+ ````
@@ -17,3 +17,4 @@ declare function createBuildInPlugin(partialPlugin: Partial<IMarkdownPlugin>): I
17
17
  declare const katexPlugin: IMarkdownPlugin;
18
18
 
19
19
  export { createBuildInPlugin, katexId, katexPlugin, mermaidId };
20
+ export type { IMarkdownPlugin };
@@ -17,3 +17,4 @@ declare function createBuildInPlugin(partialPlugin: Partial<IMarkdownPlugin>): I
17
17
  declare const katexPlugin: IMarkdownPlugin;
18
18
 
19
19
  export { createBuildInPlugin, katexId, katexPlugin, mermaidId };
20
+ export type { IMarkdownPlugin };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ds-markdown",
3
3
  "private": false,
4
- "version": "0.1.9-beta.6",
4
+ "version": "0.1.9",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "types": "./dist/cjs/index.d.ts",
7
7
  "module": "./dist/esm/index.js",
@@ -155,6 +155,6 @@
155
155
  "react-markdown"
156
156
  ],
157
157
  "publishConfig": {
158
- "tag": "beta"
158
+ "tag": "latest"
159
159
  }
160
160
  }