ds-markdown 0.0.4-beta.3 → 0.0.4
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 +63 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,12 +17,12 @@ npm install ds-markdown
|
|
|
17
17
|
<a href="https://www.npmjs.com/package/ds-markdown"><img src="https://img.shields.io/npm/v/ds-markdown" alt="npm version"/></a>
|
|
18
18
|
<img src="https://img.shields.io/npm/dm/ds-markdown.svg" alt="npm downloads"/> <img src="https://img.shields.io/bundlephobia/minzip/ds-markdown" alt="Min gzipped size"/>
|
|
19
19
|
|
|
20
|
-
##
|
|
20
|
+
## 使用示例
|
|
21
21
|
|
|
22
22
|
[在线查看](https://stackblitz.com/edit/vitejs-vite-ddfw8avb?file=src%2FApp.tsx)
|
|
23
23
|
|
|
24
24
|
```tsx
|
|
25
|
-
import {
|
|
25
|
+
import { useState } from 'react';
|
|
26
26
|
import DsMarkdown from 'ds-markdown';
|
|
27
27
|
import 'ds-markdown/style.css';
|
|
28
28
|
|
|
@@ -37,6 +37,66 @@ const markdown = `# ds-markdown
|
|
|
37
37
|
- 🔤 对大文档进行了性能优化,进行分批处理,生成打字效果的时候不会对页面造成卡顿现象
|
|
38
38
|
`;
|
|
39
39
|
|
|
40
|
+
function App() {
|
|
41
|
+
const [thinkingContent, setThkingContent] = useState('');
|
|
42
|
+
const [answerContent, setAnswerContent] = useState('');
|
|
43
|
+
|
|
44
|
+
const onClick = () => {
|
|
45
|
+
// 如果重复点击,则会清空之前的效果
|
|
46
|
+
setThkingContent('这是我思考的内容,我已经思考完成,下面是我的答案');
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
console.log(answerContent);
|
|
50
|
+
return (
|
|
51
|
+
<div>
|
|
52
|
+
<button onClick={onClick}>点击显示文字效果</button>
|
|
53
|
+
<DsMarkdown
|
|
54
|
+
answerType="thinking"
|
|
55
|
+
interval={5}
|
|
56
|
+
onEnd={() => {
|
|
57
|
+
console.log('思考完成');
|
|
58
|
+
setAnswerContent(markdown);
|
|
59
|
+
}}
|
|
60
|
+
>
|
|
61
|
+
{thinkingContent}
|
|
62
|
+
</DsMarkdown>
|
|
63
|
+
|
|
64
|
+
{!!answerContent && (
|
|
65
|
+
<DsMarkdown answerType="answer" interval={5}>
|
|
66
|
+
{answerContent}
|
|
67
|
+
</DsMarkdown>
|
|
68
|
+
)}
|
|
69
|
+
</div>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export default App;
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## 命令式示例
|
|
77
|
+
|
|
78
|
+
上面的示例中使用声明式方式来进行`markdown`的打字效果,当我们用流式拉取到数据时,文字是一个不断变化的过程,我们可以进行命令式的方式来加入文字,这样可以减少`markdown`的`rerender`
|
|
79
|
+
使用方式:
|
|
80
|
+
`import { MarkdownCMD } from 'ds-markdown';`
|
|
81
|
+
|
|
82
|
+
[在线查看](https://stackblitz.com/edit/vitejs-vite-2ri8kex3?file=src%2FApp.tsx)
|
|
83
|
+
|
|
84
|
+
```tsx
|
|
85
|
+
import { useRef, useState } from 'react';
|
|
86
|
+
import { MarkdownCMD } from 'ds-markdown';
|
|
87
|
+
import 'ds-markdown/style.css';
|
|
88
|
+
|
|
89
|
+
const markdown = `# ds-markdown
|
|
90
|
+
|
|
91
|
+
\`ds-markdown\`是一个[React](https://react.dev)组件, 类似[deepseek官网](https://chat.deepseek.com/)风格的 \`Markdown\`
|
|
92
|
+
|
|
93
|
+
## 特性
|
|
94
|
+
|
|
95
|
+
- 🛠 自带打字效果
|
|
96
|
+
- 🦮 内部封装了常用的\`markdown\`格式的文本显示
|
|
97
|
+
- 🔤 对大文档进行了性能优化,进行分批处理,生成打字效果的时候不会对页面造成卡顿现象
|
|
98
|
+
`;
|
|
99
|
+
|
|
40
100
|
function App() {
|
|
41
101
|
const ref = useRef();
|
|
42
102
|
|
|
@@ -52,7 +112,7 @@ function App() {
|
|
|
52
112
|
return (
|
|
53
113
|
<div>
|
|
54
114
|
<button onClick={onClick}>点击显示文字效果</button>
|
|
55
|
-
<
|
|
115
|
+
<MarkdownCMD ref={ref} />
|
|
56
116
|
</div>
|
|
57
117
|
);
|
|
58
118
|
}
|