ds-markdown 1.0.2 β 1.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 +48 -666
- package/README.zh.md +40 -839
- package/es/Markdown/index.js +2 -2
- package/es/Markdown/index.js.map +1 -1
- package/es/MarkdownCMD/index.js +5 -5
- package/es/MarkdownCMD/index.js.map +1 -1
- package/es/components/CodeComponent/BlockWrap/index.css +0 -13
- package/es/components/CodeComponent/BlockWrap/index.js +1 -1
- package/es/components/CodeComponent/BlockWrap/index.js.map +1 -1
- package/es/components/CodeComponent/CodeBlockWrap/index.css +24 -0
- package/es/components/CodeComponent/CodeBlockWrap/index.d.ts +1 -0
- package/es/components/CodeComponent/CodeBlockWrap/index.d.ts.map +1 -1
- package/es/components/CodeComponent/CodeBlockWrap/index.js +1 -0
- package/es/components/CodeComponent/CodeBlockWrap/index.js.map +1 -1
- package/es/components/CodeComponent/index.css +0 -24
- package/es/components/CopyButton/index.js +1 -1
- package/es/components/CopyButton/index.js.map +1 -1
- package/es/components/DownloadButton/index.js +2 -2
- package/es/components/DownloadButton/index.js.map +1 -1
- package/es/components/Icon/index.js +3 -3
- package/es/components/Icon/index.js.map +1 -1
- package/es/components/ui/SuccessButton/index.js +1 -1
- package/es/components/ui/SuccessButton/index.js.map +1 -1
- package/es/constant.d.ts +2 -2
- package/es/constant.d.ts.map +1 -1
- package/es/constant.js +2 -2
- package/es/constant.js.map +1 -1
- package/es/context/ConfigProvider/index.js +2 -2
- package/es/context/ConfigProvider/index.js.map +1 -1
- package/es/context/MarkdownThemeProvider.js +1 -1
- package/es/context/MarkdownThemeProvider.js.map +1 -1
- package/es/defined/index.d.ts +17 -17
- package/es/defined/index.d.ts.map +1 -1
- package/es/i18n/en/index.js +1 -1
- package/es/i18n/en/index.js.map +1 -1
- package/es/i18n/index.js +3 -3
- package/es/i18n/index.js.map +1 -1
- package/es/i18n/zh/index.js +1 -1
- package/es/i18n/zh/index.js.map +1 -1
- package/es/index.js +1 -1
- package/es/index.js.map +1 -1
- package/es/style.css +0 -1004
- package/es/utils/remarkMathBracket.d.ts +10 -10
- package/es/utils/remarkMathBracket.js +14 -14
- package/es/utils/remarkMathBracket.js.map +1 -1
- package/package.json +2 -2
- package/es/utils/Tokenizer.d.ts +0 -48
- package/es/utils/Tokenizer.d.ts.map +0 -1
- package/es/utils/Tokenizer.js +0 -191
- package/es/utils/Tokenizer.js.map +0 -1
- package/es/utils/compiler.d.ts +0 -5
- package/es/utils/compiler.d.ts.map +0 -1
- package/es/utils/compiler.js +0 -62
- package/es/utils/compiler.js.map +0 -1
- package/es/utils/rule.d.ts +0 -26
- package/es/utils/rule.d.ts.map +0 -1
- package/es/utils/rule.js +0 -69
- package/es/utils/rule.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# ds-markdown
|
|
2
2
|
|
|
3
|
+
> π React Markdown typing animation component for modern chat interface effects
|
|
4
|
+
|
|
3
5
|
<p align="center">
|
|
4
6
|
<img src="./assets/images/favicon.png" alt="ds-markdown logo" width="120" />
|
|
5
7
|
</p>
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
**πΊπΈ English | [π¨π³ δΈζ](./README.md)**
|
|
9
|
+
**πΊπΈ English | [π¨π³ δΈζ](./README.zh.md)**
|
|
10
10
|
|
|
11
11
|
A React component designed specifically for modern AI applications, providing smooth real-time typing animations and complete Markdown rendering capabilities.
|
|
12
12
|
|
|
@@ -16,21 +16,9 @@ A React component designed specifically for modern AI applications, providing sm
|
|
|
16
16
|
[](https://react.dev)
|
|
17
17
|
[](https://www.typescriptlang.org/)
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
- Usage Examples
|
|
21
|
-
- [Basic Usage](https://stackblitz.com/~/github.com/onshinpei/ds-markdown-base-en?file=src/App.tsx)
|
|
22
|
-
- [Streaming Data Usage](https://stackblitz.com/edit/vitejs-vite-2ri8kex3?file=src%2FApp.tsx)
|
|
23
|
-
- [Mermaid Charts](https://stackblitz.com/edit/vitejs-vite-iqbyta3j?file=index.html)
|
|
24
|
-
- [Math Formulas Demo 1](https://stackblitz.com/edit/vitejs-vite-iqbyta3j?file=index.html)
|
|
25
|
-
- [Math Formulas Demo 2](https://stackblitz.com/edit/vitejs-vite-xk9lxagc?file=src%2FApp.tsx)
|
|
26
|
-
|
|
27
|
-
If you want a clean `react markdown` typing component, you can use [react-markdown-typer](https://github.com/onshinpei/react-markdown-typer)
|
|
28
|
-
|
|
29
|
-
---
|
|
30
|
-
|
|
31
|
-
## β Why use ds-markdown?
|
|
19
|
+
## Why use ds-markdown?
|
|
32
20
|
|
|
33
|
-
###
|
|
21
|
+
### **Core Problems Solved**
|
|
34
22
|
|
|
35
23
|
- **Streaming Data Typing Stuttering Issues**
|
|
36
24
|
Traditional typewriter components experience stuttering and character jumping when processing AI backend streaming data, as each chunk contains multiple characters. ds-markdown intelligently splits each chunk to ensure smooth typing for every character.
|
|
@@ -38,7 +26,7 @@ If you want a clean `react markdown` typing component, you can use [react-markdo
|
|
|
38
26
|
- **Markdown Rendering and Typing Animation Disconnection**
|
|
39
27
|
Most typewriter components only support plain text and cannot render Markdown syntax, mathematical formulas, charts, and other rich media content in real-time during typing.
|
|
40
28
|
|
|
41
|
-
###
|
|
29
|
+
### **Value Delivered**
|
|
42
30
|
|
|
43
31
|
- **Enhanced User Immersion**
|
|
44
32
|
Provides professional-level AI chat experience, allowing users to feel authentic AI interaction processes, greatly improving product professionalism and user satisfaction.
|
|
@@ -46,105 +34,39 @@ If you want a clean `react markdown` typing component, you can use [react-markdo
|
|
|
46
34
|
- **Out-of-the-box, Reduces Development Complexity**
|
|
47
35
|
Complete solution that requires no additional configuration to support streaming data, Markdown rendering, mathematical formulas, charts, and other complex features.
|
|
48
36
|
|
|
49
|
-
|
|
50
|
-
From AI chatbots to educational content display, from technical documentation to product demos, one component meets multiple needs.
|
|
37
|
+
> _If you don't need any styles and want full control over rendering, we recommend using [react-markdown-typer](https://github.com/onshinpei/react-markdown-typer)_
|
|
51
38
|
|
|
52
|
-
|
|
39
|
+
## Documentation
|
|
40
|
+
|
|
41
|
+
**π [Full Documentation](https://onshinpei.github.io/ds-markdown/)**
|
|
42
|
+
|
|
43
|
+
- [Get Started](https://onshinpei.github.io/ds-markdown/#get-started)
|
|
44
|
+
- [API Documentation](https://onshinpei.github.io/ds-markdown/#docs)
|
|
45
|
+
- [Live Examples](https://onshinpei.github.io/ds-markdown/#examples)
|
|
46
|
+
- [Try it Now](https://onshinpei.github.io/ds-markdown/#try)
|
|
47
|
+
|
|
48
|
+
## Stackblitz Examples
|
|
53
49
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
- [
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
- [π 5-Minute Quick Start](#-5-minute-quick-start)
|
|
71
|
-
- [Basic Usage](#basic-usage)
|
|
72
|
-
- [Disable Typing Animation](#disable-typing-animation)
|
|
73
|
-
- [Mathematical Formula Support](#mathematical-formula-support)
|
|
74
|
-
- [AI Chat Scenarios](#ai-chat-scenarios)
|
|
75
|
-
- [Code Block Features π](#code-block-features-)
|
|
76
|
-
- [Mermaid Chart Support](#mermaid-chart-support)
|
|
77
|
-
- [π Complete API Documentation](#-complete-api-documentation)
|
|
78
|
-
- [Default export DsMarkdown and MarkdownCMD props](#default-export-dsmarkdown-and-markdowncmd-props)
|
|
79
|
-
- [IBeforeTypedChar](#ibeforetypedchar)
|
|
80
|
-
- [ITypedChar](#itypedchar)
|
|
81
|
-
- [IMarkdownMath](#imarkdownmath)
|
|
82
|
-
- [IMarkdownCode π](#imarkdowncode-)
|
|
83
|
-
- [IMarkdownPlugin](#imarkdownplugin)
|
|
84
|
-
- [Component Exposed Methods](#component-exposed-methods)
|
|
85
|
-
- [Default export DsMarkdown](#default-export-dsmarkdown)
|
|
86
|
-
- [MarkdownCMD Exposed Methods](#markdowncmd-exposed-methods)
|
|
87
|
-
- [π Plugin System](#-plugin-system)
|
|
88
|
-
- [Built-in Plugins](#built-in-plugins)
|
|
89
|
-
- [KaTeX Mathematical Formula Plugin](#katex-mathematical-formula-plugin)
|
|
90
|
-
- [Mermaid Chart Plugin π](#mermaid-chart-plugin-)
|
|
91
|
-
- [Custom Plugins](#custom-plugins)
|
|
92
|
-
- [π¨ UI Component System π](#-ui-component-system--1)
|
|
93
|
-
- [Core Components](#core-components)
|
|
94
|
-
- [Style Customization](#style-customization)
|
|
95
|
-
- [Multi-language Configuration](#multi-language-configuration)
|
|
96
|
-
- [π‘ Practical Examples](#-practical-examples)
|
|
97
|
-
- [π AI Streaming Chat](#-ai-streaming-chat)
|
|
98
|
-
- [π§ Best Practices](#-best-practices)
|
|
99
|
-
- [1. Performance Optimization](#1-performance-optimization)
|
|
100
|
-
- [2. Streaming Data Processing](#2-streaming-data-processing)
|
|
101
|
-
- [3. Mathematical Formula Optimization](#3-mathematical-formula-optimization)
|
|
102
|
-
- [4. Mermaid Chart Best Practices π](#4-mermaid-chart-best-practices-)
|
|
103
|
-
|
|
104
|
-
## β¨ Core Features
|
|
105
|
-
|
|
106
|
-
### π€ **AI Chat Scenarios**
|
|
107
|
-
|
|
108
|
-
- Professional-level AI chat response effects, comparable to mainstream AI platform experiences
|
|
109
|
-
- Supports thinking process (`thinking`) and answer content `answer`) dual modes
|
|
110
|
-
- Perfect streaming data adaptation with zero-delay response to user input
|
|
111
|
-
|
|
112
|
-
### π **Content Display Scenarios**
|
|
113
|
-
|
|
114
|
-
- Complete Markdown syntax support, including code highlighting, tables, lists, etc.
|
|
115
|
-
- Mathematical formula rendering (KaTeX), supporting `$...$` and `\[...\]` syntax
|
|
116
|
-
- Mermaid chart support, including flowcharts, sequence diagrams, Gantt charts, class diagrams, etc. π
|
|
117
|
-
- Supports light/dark themes, adapting to different product styles
|
|
118
|
-
- Plugin architecture supporting remark/rehype plugin extensions
|
|
119
|
-
|
|
120
|
-
### π¨ **UI Component System π**
|
|
121
|
-
|
|
122
|
-
- Code block and chart enhancement features: copy, download, language, etc.
|
|
123
|
-
- Built-in rich UI components: Button, IconButton, ToolTip, Segmented, etc.
|
|
124
|
-
- Complete interactive experience and accessibility support
|
|
125
|
-
|
|
126
|
-
### π§ **Development Experience**
|
|
127
|
-
|
|
128
|
-
- Rich imperative API: `start`, `stop`, `resume`, `restart`, etc.
|
|
129
|
-
- Supports typing interruption and continuation, flexible control of animation states
|
|
130
|
-
- Supports typing on/off, meeting different scenario requirements
|
|
131
|
-
- Complete TypeScript type support
|
|
132
|
-
|
|
133
|
-
### π¬ **Smooth Animation**
|
|
134
|
-
|
|
135
|
-
- Dual-mode timer optimization, supporting `requestAnimationFrame` and `setTimeout` modes
|
|
136
|
-
- High-frequency typing support (typing interval can be as low as close to `0ms` in `requestAnimationFrame` mode)
|
|
137
|
-
- Frame-synchronized rendering, perfectly coordinated with browser refresh
|
|
138
|
-
- Intelligent character batch processing for more natural visual effects
|
|
139
|
-
|
|
140
|
-
### β‘ **Performance Optimization**
|
|
141
|
-
|
|
142
|
-
- Lightweight design, small size and excellent performance
|
|
143
|
-
- Core dependency [react-markdown](https://github.com/remarkjs/react-markdown), no heavyweight dependencies
|
|
50
|
+
- [Basic Usage](https://stackblitz.com/edit/vitejs-vite-61cs2kga?file=src%2FApp.tsx)
|
|
51
|
+
- [Streaming Data Usage](https://stackblitz.com/edit/vitejs-vite-lwyevhp6?file=src%2FApp.tsx)
|
|
52
|
+
- [Mermaid Charts](https://stackblitz.com/edit/vitejs-vite-6gxhttps?file=src%2FApp.tsx)
|
|
53
|
+
- [Math Formulas Demo 1](https://stackblitz.com/edit/vitejs-vite-zncjktys?file=src%2FApp.tsx)
|
|
54
|
+
- [Math Formulas Demo 2](https://stackblitz.com/edit/vitejs-vite-xk9lxagc?file=src%2FApp.tsx)
|
|
55
|
+
|
|
56
|
+
## Key Features
|
|
57
|
+
|
|
58
|
+
- π€ **AI Chat Ready** - Professional typing animation for AI streaming responses
|
|
59
|
+
- π **Full Markdown Support** - Code highlighting, tables, lists, and more
|
|
60
|
+
- π’ **Math Formulas** - KaTeX support with `$...$` and `$$...$$` syntax
|
|
61
|
+
- π **Mermaid Charts** - Flowcharts, sequence diagrams, Gantt charts, etc.
|
|
62
|
+
- π¨ **Customizable** - Light/dark themes, configurable typing speed
|
|
63
|
+
- β‘ **High Performance** - Lightweight, smooth animations
|
|
64
|
+
- π **Extensible** - Plugin system for custom functionality
|
|
65
|
+
- π¦ **TypeScript** - Full type support
|
|
144
66
|
|
|
145
67
|
---
|
|
146
68
|
|
|
147
|
-
##
|
|
69
|
+
## Installation
|
|
148
70
|
|
|
149
71
|
```bash
|
|
150
72
|
# npm
|
|
@@ -157,32 +79,7 @@ yarn add ds-markdown
|
|
|
157
79
|
pnpm add ds-markdown
|
|
158
80
|
```
|
|
159
81
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
No installation required, use directly in the browser:
|
|
163
|
-
|
|
164
|
-
[DEMO](https://stackblitz.com/edit/stackblitz-starters-7vcclcw7?file=index.html)
|
|
165
|
-
|
|
166
|
-
```html
|
|
167
|
-
<!-- Import styles, required -->
|
|
168
|
-
<link rel="stylesheet" href="https://esm.sh/ds-markdown/dist/style.css" />
|
|
169
|
-
|
|
170
|
-
<!-- Import KaTeX math formula styles, only import if needed -->
|
|
171
|
-
<link rel="stylesheet" href="https://esm.sh/ds-markdown/dist/katex.css" />
|
|
172
|
-
|
|
173
|
-
<!-- Import component -->
|
|
174
|
-
<script type="module">
|
|
175
|
-
import Markdown from 'https://esm.sh/ds-markdown';
|
|
176
|
-
</script>
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
## π 5-Minute Quick Start
|
|
180
|
-
|
|
181
|
-
> β
Starting from v1.0+, you no longer need to manually import `ds-markdown/style.css`; the component automatically injects the required base styles.
|
|
182
|
-
|
|
183
|
-
### Basic Usage
|
|
184
|
-
|
|
185
|
-
[DEMO](https://stackblitz.com/edit/vitejs-vite-z94syu8j?file=src%2FApp.tsx)
|
|
82
|
+
## Quick Start
|
|
186
83
|
|
|
187
84
|
```tsx
|
|
188
85
|
import DsMarkdown from 'ds-markdown';
|
|
@@ -196,172 +93,9 @@ function App() {
|
|
|
196
93
|
}
|
|
197
94
|
```
|
|
198
95
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
```tsx
|
|
202
|
-
import DsMarkdown from 'ds-markdown';
|
|
203
|
-
|
|
204
|
-
function StaticDemo() {
|
|
205
|
-
const [disableTyping, setDisableTyping] = useState(false);
|
|
206
|
-
|
|
207
|
-
return (
|
|
208
|
-
<div>
|
|
209
|
-
<button onClick={() => setDisableTyping(!disableTyping)}>{disableTyping ? 'Enable' : 'Disable'} Typewriter Effect</button>
|
|
210
|
-
|
|
211
|
-
<DsMarkdown interval={20} answerType="answer" disableTyping={disableTyping}>
|
|
212
|
-
# Static Display Mode When `disableTyping` is `true`, content will be displayed immediately without typing animation effects. This is very useful in certain scenarios: - π Static document
|
|
213
|
-
display - π Switching display modes - β‘ Quick content preview
|
|
214
|
-
</DsMarkdown>
|
|
215
|
-
</div>
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
### Mathematical Formula Support
|
|
221
|
-
|
|
222
|
-
```tsx
|
|
223
|
-
import DsMarkdown from 'ds-markdown';
|
|
224
|
-
// If you need to display formulas, you need to import the formula conversion plugin
|
|
225
|
-
import { katexPlugin } from 'ds-markdown/plugins';
|
|
226
|
-
import 'ds-markdown/style.css';
|
|
227
|
-
// If you need to display formulas, you need to import math formula styles
|
|
228
|
-
import 'ds-markdown/katex.css';
|
|
229
|
-
|
|
230
|
-
function MathDemo() {
|
|
231
|
-
return (
|
|
232
|
-
<DsMarkdown interval={20} answerType="answer" plugins={[katexPlugin]} math={{ splitSymbol: 'dollar' }}>
|
|
233
|
-
# Pythagorean Theorem In a right triangle, the square of the hypotenuse equals the sum of the squares of the two legs: $a^2 + b^2 = c^2$ Where: - $a$ and $b$ are the legs - $c$ is the hypotenuse
|
|
234
|
-
For the classic "3-4-5 triangle": $c = \sqrt{3 ^ (2 + 4) ^ 2} = \sqrt{25} = 5$
|
|
235
|
-
</DsMarkdown>
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
### AI Chat Scenarios
|
|
241
|
-
|
|
242
|
-
```tsx
|
|
243
|
-
function ChatDemo() {
|
|
244
|
-
const [thinking, setThinking] = useState('');
|
|
245
|
-
const [answer, setAnswer] = useState('');
|
|
246
|
-
|
|
247
|
-
const handleAsk = () => {
|
|
248
|
-
setThinking('π€ Thinking about your question...');
|
|
249
|
-
|
|
250
|
-
setTimeout(() => {
|
|
251
|
-
setAnswer(`# About React 19
|
|
252
|
-
|
|
253
|
-
React 19 brings many exciting new features:
|
|
254
|
-
|
|
255
|
-
## π Major Updates
|
|
256
|
-
1. **React Compiler** - Automatic performance optimization
|
|
257
|
-
2. **Actions** - Simplified form handling
|
|
258
|
-
3. **Document Metadata** - Built-in SEO support
|
|
259
|
-
|
|
260
|
-
Let's explore these new features together!`);
|
|
261
|
-
}, 2000);
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
return (
|
|
265
|
-
<div>
|
|
266
|
-
<button onClick={handleAsk}>Ask AI</button>
|
|
267
|
-
|
|
268
|
-
{thinking && (
|
|
269
|
-
<DsMarkdown answerType="thinking" interval={30}>
|
|
270
|
-
{thinking}
|
|
271
|
-
</DsMarkdown>
|
|
272
|
-
)}
|
|
273
|
-
|
|
274
|
-
{answer && (
|
|
275
|
-
<DsMarkdown answerType="answer" interval={15}>
|
|
276
|
-
{answer}
|
|
277
|
-
</DsMarkdown>
|
|
278
|
-
)}
|
|
279
|
-
</div>
|
|
280
|
-
);
|
|
281
|
-
}
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
### Code Block Features π
|
|
285
|
-
|
|
286
|
-
```tsx
|
|
287
|
-
import DsMarkdown from 'ds-markdown';
|
|
288
|
-
|
|
289
|
-
function CodeBlockDemo() {
|
|
290
|
-
const codeContent = `# Hello World
|
|
291
|
-
|
|
292
|
-
\`\`\`javascript
|
|
293
|
-
function greet(name) {
|
|
294
|
-
console.log(\`Hello, \${name}!\`);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
greet('ds-markdown');
|
|
298
|
-
\`\`\`
|
|
299
|
-
|
|
300
|
-
Supports code highlighting, copying, and downloading!`;
|
|
301
|
-
|
|
302
|
-
return (
|
|
303
|
-
<DsMarkdown
|
|
304
|
-
interval={20}
|
|
305
|
-
answerType="answer"
|
|
306
|
-
codeBlock={{
|
|
307
|
-
headerActions: true, // Enable code block header action buttons
|
|
308
|
-
}}
|
|
309
|
-
>
|
|
310
|
-
{codeContent}
|
|
311
|
-
</DsMarkdown>
|
|
312
|
-
);
|
|
313
|
-
}
|
|
314
|
-
```
|
|
315
|
-
|
|
316
|
-
### Mermaid Chart Support
|
|
317
|
-
|
|
318
|
-
[DEMO](https://stackblitz.com/edit/vitejs-vite-iqbyta3j?file=README.md)
|
|
319
|
-
|
|
320
|
-
```tsx
|
|
321
|
-
import DsMarkdown from 'ds-markdown';
|
|
322
|
-
import { ConfigProvider } from 'ds-markdown';
|
|
323
|
-
import mermaidPlugin from 'ds-markdown-mermaid-plugin';
|
|
324
|
-
import 'ds-markdown/style.css';
|
|
325
|
-
|
|
326
|
-
function MermaidDemo() {
|
|
327
|
-
const chartContent = `Here's a simplified learning to drive flowchart, keeping only the **most core steps**, suitable for quickly mastering key nodes:
|
|
328
|
-
|
|
329
|
-
\`\`\`mermaid
|
|
330
|
-
graph TD
|
|
331
|
-
A[Start] --> B[Subject 1: Theory Exam]
|
|
332
|
-
B --> C[Subject 2: Field Five Items]
|
|
333
|
-
C --> D[Subject 3: Road Test]
|
|
334
|
-
D --> E[Subject 4: Safety Written Test]
|
|
335
|
-
E --> F[Get Driver's License]
|
|
336
|
-
F --> G[Actual Driving Practice]
|
|
337
|
-
\`\`\`
|
|
338
|
-
|
|
339
|
-
### Minimalist Explanation:
|
|
340
|
-
1. **Theory First**: Pass traffic rules written test (Subject 1).
|
|
341
|
-
2. **Field Basics**: Practice reversing, hill starts, etc. (Subject 2).
|
|
342
|
-
3. **Road Combat**: Actual road driving test (Subject 3).
|
|
343
|
-
4. **Safety Finish**: Pass Subject 4 to get license.
|
|
344
|
-
5. **Continuous Proficiency**: Continue practicing after getting license to adapt to real road conditions.
|
|
345
|
-
|
|
346
|
-
### Visualization Suggestions:
|
|
347
|
-
- When sketching with phone memo or white paper, write steps in **arrow order**.
|
|
348
|
-
- Want more intuitive? Use circular sticky notes for each subject, connect them into a flow.`;
|
|
349
|
-
|
|
350
|
-
return (
|
|
351
|
-
<ConfigProvider>
|
|
352
|
-
<DsMarkdown interval={20} answerType="answer" plugins={[mermaidPlugin]}>
|
|
353
|
-
{chartContent}
|
|
354
|
-
</DsMarkdown>
|
|
355
|
-
</ConfigProvider>
|
|
356
|
-
);
|
|
357
|
-
}
|
|
358
|
-
```
|
|
96
|
+
## Core API Documentation
|
|
359
97
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
---
|
|
363
|
-
|
|
364
|
-
## π Complete API Documentation
|
|
98
|
+
For detailed documentation, please visit: [Full Documentation](https://onshinpei.github.io/ds-markdown/#get-started)
|
|
365
99
|
|
|
366
100
|
### Default export DsMarkdown and MarkdownCMD props
|
|
367
101
|
|
|
@@ -371,12 +105,12 @@ import DsMarkdown, { MarkdownCMD } from 'ds-markdown';
|
|
|
371
105
|
|
|
372
106
|
| Property | Type | Description | Default Value |
|
|
373
107
|
| ------------------- | ------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
|
|
374
|
-
| `interval` | `number`
|
|
108
|
+
| `interval` | `number` \| `IntervalConfig` | Typing interval configuration, supports fixed interval or dynamic speed control | `30` |
|
|
375
109
|
| `timerType` | `'setTimeout'` \| `'requestAnimationFrame'` | Timer type, does not support dynamic modification | Current default is `setTimeout`, will change to `requestAnimationFrame` later |
|
|
376
110
|
| `answerType` | `'thinking'` \| `'answer'` | Content type (affects style theme), does not support dynamic modification | `'answer'` |
|
|
377
111
|
| `theme` | `'light'` \| `'dark'` | Theme type | `'light'` |
|
|
378
112
|
| `plugins` | `IMarkdownPlugin[]` | Plugin configuration | `[]` |
|
|
379
|
-
| `math` |
|
|
113
|
+
| `math` | `IMarkdownMath` | Mathematical formula configuration | `{ splitSymbol: 'dollar' }` |
|
|
380
114
|
| `onEnd` | `(data: EndData) => void` | Typing completion callback | - |
|
|
381
115
|
| `onStart` | `(data: StartData) => void` | Typing start callback | - |
|
|
382
116
|
| `onBeforeTypedChar` | `(data: IBeforeTypedChar) => Promise<void>` | Callback before character typing, supports async operations, blocks subsequent typing | - |
|
|
@@ -385,373 +119,21 @@ import DsMarkdown, { MarkdownCMD } from 'ds-markdown';
|
|
|
385
119
|
| `autoStartTyping` | `boolean` | Whether to automatically start typing animation, set to false for manual trigger, does not support dynamic modification | `true` |
|
|
386
120
|
| `codeBlock` | `IMarkdownCode` | Code block configuration | `{headerActions: true}` |
|
|
387
121
|
|
|
388
|
-
> Note: If `disableTyping` changes from `true` to `false` during typing
|
|
389
|
-
|
|
390
|
-
### IBeforeTypedChar
|
|
391
|
-
|
|
392
|
-
| Property | Type | Description | Default Value |
|
|
393
|
-
| -------------- | ------------ | -------------------------------------------- | ------------- |
|
|
394
|
-
| `currentIndex` | `number` | Current character index in the entire string | `0` |
|
|
395
|
-
| `currentChar` | `string` | Current character about to be typed | - |
|
|
396
|
-
| `answerType` | `AnswerType` | Content type (thinking/answer) | - |
|
|
397
|
-
| `prevStr` | `string` | Prefix string of current type content | - |
|
|
398
|
-
| `percent` | `number` | Typing progress percentage (0-100) | `0` |
|
|
399
|
-
|
|
400
|
-
### ITypedChar
|
|
401
|
-
|
|
402
|
-
| Property | Type | Description | Default Value |
|
|
403
|
-
| -------------- | ------------ | -------------------------------------------- | ------------- |
|
|
404
|
-
| `currentIndex` | `number` | Current character index in the entire string | `0` |
|
|
405
|
-
| `currentChar` | `string` | Current typed character | - |
|
|
406
|
-
| `answerType` | `AnswerType` | Content type (thinking/answer) | - |
|
|
407
|
-
| `prevStr` | `string` | Prefix string of current type content | - |
|
|
408
|
-
| `currentStr` | `string` | Complete string of current type content | - |
|
|
409
|
-
| `percent` | `number` | Typing progress percentage (0-100) | `0` |
|
|
410
|
-
|
|
411
|
-
#### IMarkdownMath
|
|
412
|
-
|
|
413
|
-
| Property | Type | Description | Default Value |
|
|
414
|
-
| ------------- | ------------------------- | --------------------------- | ------------- |
|
|
415
|
-
| `splitSymbol` | `'dollar'` \| `'bracket'` | Math formula delimiter type | `'dollar'` |
|
|
416
|
-
|
|
417
|
-
**Delimiter Description:**
|
|
418
|
-
|
|
419
|
-
- `'dollar'`: Uses `$...$` and `$$...$$` syntax
|
|
420
|
-
- `'bracket'`: Uses `\(...\)` and `\[...\]` syntax
|
|
122
|
+
> Note: If `disableTyping` changes from `true` to `false` during typing, it will only continue from the current position and will not replay the skipped animation; to replay from the beginning, please call the instance method `restart()`.
|
|
421
123
|
|
|
422
|
-
|
|
124
|
+
For detailed documentation, please visit: [Full Documentation](https://onshinpei.github.io/ds-markdown/#get-started)
|
|
423
125
|
|
|
424
|
-
|
|
425
|
-
| --------------- | --------- | ------------------------------------- | ------------- |
|
|
426
|
-
| `headerActions` | `boolean` | Whether to show header action buttons | `true` |
|
|
126
|
+
## Related Projects
|
|
427
127
|
|
|
428
|
-
|
|
128
|
+
- **[react-markdown-typer](https://github.com/onshinpei/react-markdown-typer)** - If you need a lightweight markdown typing component
|
|
129
|
+
- **[ds-markdown-mermaid-plugin](https://github.com/onshinpei/ds-markdown-mermaid-plugin)** - Mermaid chart support plugin
|
|
429
130
|
|
|
430
|
-
|
|
431
|
-
| -------------- | ---------------------------------------------- | --------------------------- | ------------- |
|
|
432
|
-
| `remarkPlugin` | `Pluggable` | remark plugin | - |
|
|
433
|
-
| `rehypePlugin` | `Pluggable` | rehype plugin | - |
|
|
434
|
-
| `type` | `'buildIn'` \| `'custom'` | Plugin type | - |
|
|
435
|
-
| `id` | `any` | Plugin unique identifier | - |
|
|
436
|
-
| `components` | `Record<string, React.ComponentType<unknown>>` | Custom component mapping π | - |
|
|
131
|
+
## License
|
|
437
132
|
|
|
438
|
-
|
|
133
|
+
MIT Β© [onshinpei](https://github.com/onshinpei)
|
|
439
134
|
|
|
440
|
-
|
|
135
|
+
## Contributing
|
|
441
136
|
|
|
442
|
-
|
|
443
|
-
| --------- | ---------- | ------------------------------------------------------------- |
|
|
444
|
-
| `start` | - | Start typing animation |
|
|
445
|
-
| `stop` | - | Pause typing animation |
|
|
446
|
-
| `resume` | - | Resume typing animation |
|
|
447
|
-
| `restart` | - | Restart typing animation, play current content from beginning |
|
|
448
|
-
|
|
449
|
-
#### MarkdownCMD Exposed Methods
|
|
450
|
-
|
|
451
|
-
| Method | Parameters | Description |
|
|
452
|
-
| ----------------- | ------------------------------------------- | ------------------------------------------------------------- |
|
|
453
|
-
| `push` | `(content: string, answerType: AnswerType)` | Add content and start typing |
|
|
454
|
-
| `clear` | - | Clear all content and state |
|
|
455
|
-
| `triggerWholeEnd` | - | Manually trigger completion callback |
|
|
456
|
-
| `start` | - | Start typing animation |
|
|
457
|
-
| `stop` | - | Pause typing animation |
|
|
458
|
-
| `resume` | - | Resume typing animation |
|
|
459
|
-
| `restart` | - | Restart typing animation, play current content from beginning |
|
|
460
|
-
|
|
461
|
-
**Usage Examples:**
|
|
462
|
-
|
|
463
|
-
```tsx
|
|
464
|
-
markdownRef.current?.start(); // Start animation
|
|
465
|
-
markdownRef.current?.stop(); // Pause animation
|
|
466
|
-
markdownRef.current?.resume(); // Resume animation
|
|
467
|
-
markdownRef.current?.restart(); // Restart animation
|
|
468
|
-
```
|
|
469
|
-
|
|
470
|
-
---
|
|
471
|
-
|
|
472
|
-
## π Plugin System
|
|
473
|
-
|
|
474
|
-
### Built-in Plugins
|
|
475
|
-
|
|
476
|
-
#### KaTeX Mathematical Formula Plugin
|
|
477
|
-
|
|
478
|
-
[DEMO](https://stackblitz.com/edit/vitejs-vite-iqbyta3j?file=index.html)
|
|
479
|
-
|
|
480
|
-
```tsx
|
|
481
|
-
import { katexPlugin } from 'ds-markdown/plugins';
|
|
482
|
-
|
|
483
|
-
// Enable mathematical formula support
|
|
484
|
-
<DsMarkdown plugins={[katexPlugin]}>Math formula: $E = mc^2$</DsMarkdown>;
|
|
485
|
-
```
|
|
486
|
-
|
|
487
|
-
#### Mermaid Chart Plugin π
|
|
488
|
-
|
|
489
|
-
**Install Mermaid Plugin:**
|
|
490
|
-
|
|
491
|
-
```bash
|
|
492
|
-
npm install ds-markdown-mermaid-plugin
|
|
493
|
-
```
|
|
494
|
-
|
|
495
|
-
**Basic Usage:**
|
|
496
|
-
|
|
497
|
-
```tsx
|
|
498
|
-
import { ConfigProvider, Markdown } from 'ds-markdown';
|
|
499
|
-
import mermaidPlugin from 'ds-markdown-mermaid-plugin';
|
|
500
|
-
|
|
501
|
-
function App() {
|
|
502
|
-
const content = `
|
|
503
|
-
# Flowchart Example
|
|
504
|
-
|
|
505
|
-
\`\`\`mermaid
|
|
506
|
-
flowchart TD
|
|
507
|
-
A[Start] --> B{Decision}
|
|
508
|
-
B -->|Yes| C[Process A]
|
|
509
|
-
B -->|No| D[Process B]
|
|
510
|
-
C --> E[End]
|
|
511
|
-
D --> E
|
|
512
|
-
\`\`\`
|
|
513
|
-
`;
|
|
514
|
-
|
|
515
|
-
return (
|
|
516
|
-
<ConfigProvider>
|
|
517
|
-
<Markdown plugins={[mermaidPlugin]}>{content}</Markdown>
|
|
518
|
-
</ConfigProvider>
|
|
519
|
-
);
|
|
520
|
-
}
|
|
521
|
-
```
|
|
522
|
-
|
|
523
|
-
**Supported Chart Types:**
|
|
524
|
-
|
|
525
|
-
- π **Flowchart** - Display processes and decision paths
|
|
526
|
-
- π **Sequence Diagram** - Display interaction timing between objects
|
|
527
|
-
- π
**Gantt Chart** - Project planning and timelines
|
|
528
|
-
- ποΈ **Class Diagram** - Object-oriented design
|
|
529
|
-
- π₯§ **Pie Chart** - Data proportion display
|
|
530
|
-
- π **State Diagram** - State transition processes
|
|
531
|
-
- π **Git Graph** - Code branch history
|
|
532
|
-
- πΊοΈ **User Journey** - User experience flow
|
|
533
|
-
|
|
534
|
-
**Configure Mermaid:**
|
|
535
|
-
|
|
536
|
-
```tsx
|
|
537
|
-
import { ConfigProvider } from 'ds-markdown';
|
|
538
|
-
|
|
539
|
-
const mermaidConfig = {
|
|
540
|
-
theme: 'default', // Theme: default, neutral, dark, forest
|
|
541
|
-
flowchart: {
|
|
542
|
-
useMaxWidth: true,
|
|
543
|
-
htmlLabels: true,
|
|
544
|
-
},
|
|
545
|
-
sequence: {
|
|
546
|
-
diagramMarginX: 50,
|
|
547
|
-
diagramMarginY: 10,
|
|
548
|
-
},
|
|
549
|
-
};
|
|
550
|
-
|
|
551
|
-
return (
|
|
552
|
-
<ConfigProvider mermaidConfig={mermaidConfig}>
|
|
553
|
-
<Markdown plugins={[mermaidPlugin]}>{chartContent}</Markdown>
|
|
554
|
-
</ConfigProvider>
|
|
555
|
-
);
|
|
556
|
-
```
|
|
557
|
-
|
|
558
|
-
**Related Links:**
|
|
559
|
-
|
|
560
|
-
- [ds-markdown-mermaid-plugin GitHub](https://github.com/onshinpei/ds-markdown-mermaid-plugin)
|
|
561
|
-
- [Mermaid Official Documentation](https://mermaid.js.org/)
|
|
562
|
-
|
|
563
|
-
### Custom Plugins
|
|
564
|
-
|
|
565
|
-
```tsx
|
|
566
|
-
import { createBuildInPlugin } from 'ds-markdown/plugins';
|
|
567
|
-
|
|
568
|
-
// Create custom plugin
|
|
569
|
-
const customPlugin = createBuildInPlugin({
|
|
570
|
-
remarkPlugin: yourRemarkPlugin,
|
|
571
|
-
rehypePlugin: yourRehypePlugin,
|
|
572
|
-
id: Symbol('custom-plugin'),
|
|
573
|
-
components: {
|
|
574
|
-
// Custom component mapping π
|
|
575
|
-
CustomComponent: MyCustomComponent,
|
|
576
|
-
},
|
|
577
|
-
});
|
|
578
|
-
|
|
579
|
-
// Use custom plugin
|
|
580
|
-
<DsMarkdown plugins={[katexPlugin, customPlugin]}>Content</DsMarkdown>;
|
|
581
|
-
```
|
|
582
|
-
|
|
583
|
-
---
|
|
584
|
-
|
|
585
|
-
## π¨ UI Component System π
|
|
586
|
-
|
|
587
|
-
ds-markdown provides rich UI components that can be used individually or in combination with markdown components.
|
|
588
|
-
|
|
589
|
-
### Core Components
|
|
590
|
-
|
|
591
|
-
```tsx
|
|
592
|
-
import {
|
|
593
|
-
Button,
|
|
594
|
-
IconButton,
|
|
595
|
-
ToolTip,
|
|
596
|
-
Segmented,
|
|
597
|
-
CopyButton,
|
|
598
|
-
DownloadButton
|
|
599
|
-
} from 'ds-markdown';
|
|
600
|
-
|
|
601
|
-
// Button component
|
|
602
|
-
<Button icon={<span>π</span>} onClick={() => {}}>
|
|
603
|
-
Click Button
|
|
604
|
-
</Button>
|
|
605
|
-
|
|
606
|
-
// Tooltip
|
|
607
|
-
<ToolTip title="Tooltip information">
|
|
608
|
-
<IconButton icon={<span>π</span>} onClick={() => {}} />
|
|
609
|
-
</ToolTip>
|
|
610
|
-
|
|
611
|
-
// Segmented controller
|
|
612
|
-
<Segmented
|
|
613
|
-
options={[
|
|
614
|
-
{ label: 'Chart', value: 'diagram' },
|
|
615
|
-
{ label: 'Code', value: 'code' }
|
|
616
|
-
]}
|
|
617
|
-
value={value}
|
|
618
|
-
onChange={setValue}
|
|
619
|
-
/>
|
|
620
|
-
|
|
621
|
-
// Code block operations
|
|
622
|
-
<CopyButton codeContent="console.log('Hello')" />
|
|
623
|
-
<DownloadButton codeContent="console.log('Hello')" language="javascript" />
|
|
624
|
-
```
|
|
625
|
-
|
|
626
|
-
### Style Customization
|
|
627
|
-
|
|
628
|
-
```css
|
|
629
|
-
:root {
|
|
630
|
-
--ds-button-bg-color: #f5f5f5;
|
|
631
|
-
--ds-button-hover-color: #e0e0e0;
|
|
632
|
-
--ds-tooltip-bg-color: rgba(0, 0, 0, 0.8);
|
|
633
|
-
}
|
|
634
|
-
```
|
|
635
|
-
|
|
636
|
-
---
|
|
637
|
-
|
|
638
|
-
## Multi-language Configuration
|
|
639
|
-
|
|
640
|
-
```tsx
|
|
641
|
-
import { ConfigProvider } from 'ds-markdown';
|
|
642
|
-
import zhCN from 'ds-markdown/i18n/zh';
|
|
643
|
-
import enUS from 'ds-markdown/i18n/en';
|
|
644
|
-
|
|
645
|
-
// Chinese
|
|
646
|
-
<ConfigProvider locale={zhCN}>
|
|
647
|
-
<DsMarkdown {...props} />
|
|
648
|
-
</ConfigProvider>
|
|
649
|
-
|
|
650
|
-
// English
|
|
651
|
-
<ConfigProvider locale={enUS}>
|
|
652
|
-
<DsMarkdown {...props} />
|
|
653
|
-
</ConfigProvider>
|
|
654
|
-
```
|
|
655
|
-
|
|
656
|
-
---
|
|
657
|
-
|
|
658
|
-
## π‘ Practical Examples
|
|
659
|
-
|
|
660
|
-
### π AI Streaming Chat
|
|
661
|
-
|
|
662
|
-
[DEMO: π§ StackBlitz Experience](https://stackblitz.com/edit/vitejs-vite-2ri8kex3?file=src%2FApp.tsx)
|
|
663
|
-
|
|
664
|
-
```tsx
|
|
665
|
-
import { useRef } from 'react';
|
|
666
|
-
import { MarkdownCMD, MarkdownCMDRef } from 'ds-markdown';
|
|
667
|
-
|
|
668
|
-
function StreamingChat() {
|
|
669
|
-
const markdownRef = useRef<MarkdownCMDRef>(null);
|
|
670
|
-
|
|
671
|
-
// Simulate AI streaming response
|
|
672
|
-
const simulateAIResponse = async () => {
|
|
673
|
-
markdownRef.current?.clear();
|
|
674
|
-
|
|
675
|
-
// Thinking phase
|
|
676
|
-
markdownRef.current?.push('π€ Analyzing your question...', 'thinking');
|
|
677
|
-
await delay(1000);
|
|
678
|
-
markdownRef.current?.push('\n\nβ
Analysis complete, starting to answer', 'thinking');
|
|
679
|
-
|
|
680
|
-
// Streaming answer
|
|
681
|
-
const chunks = [
|
|
682
|
-
'# React 19 New Features Analysis\n\n',
|
|
683
|
-
'## π React Compiler\n',
|
|
684
|
-
'The biggest highlight of React 19 is the introduction of **React Compiler**:\n\n',
|
|
685
|
-
'- π― **Automatic Optimization**: No need for manual memo and useMemo\n',
|
|
686
|
-
'- β‘ **Performance Boost**: Compile-time optimization, zero runtime overhead\n',
|
|
687
|
-
'- π§ **Backward Compatible**: Existing code requires no modification\n\n',
|
|
688
|
-
'Hope this answer helps you! π',
|
|
689
|
-
];
|
|
690
|
-
|
|
691
|
-
for (const chunk of chunks) {
|
|
692
|
-
await delay(100);
|
|
693
|
-
markdownRef.current?.push(chunk, 'answer');
|
|
694
|
-
}
|
|
695
|
-
};
|
|
696
|
-
|
|
697
|
-
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
698
|
-
|
|
699
|
-
return (
|
|
700
|
-
<div className="chat-container">
|
|
701
|
-
<button onClick={simulateAIResponse}>π€ Ask about React 19 New Features</button>
|
|
702
|
-
<MarkdownCMD ref={markdownRef} interval={10} timerType="requestAnimationFrame" />
|
|
703
|
-
</div>
|
|
704
|
-
);
|
|
705
|
-
}
|
|
706
|
-
```
|
|
707
|
-
|
|
708
|
-
## π§ Best Practices
|
|
709
|
-
|
|
710
|
-
### 1. Performance Optimization
|
|
711
|
-
|
|
712
|
-
```tsx
|
|
713
|
-
// β
Recommended configuration
|
|
714
|
-
<DsMarkdown
|
|
715
|
-
timerType="requestAnimationFrame"
|
|
716
|
-
interval={15} // 15-30ms for best experience
|
|
717
|
-
/>
|
|
718
|
-
```
|
|
719
|
-
|
|
720
|
-
### 2. Streaming Data Processing
|
|
721
|
-
|
|
722
|
-
```tsx
|
|
723
|
-
// β
Recommended: Imperative API
|
|
724
|
-
const ref = useRef<MarkdownCMDRef>(null);
|
|
725
|
-
useEffect(() => {
|
|
726
|
-
ref.current?.push(newChunk, 'answer');
|
|
727
|
-
}, [newChunk]);
|
|
728
|
-
```
|
|
729
|
-
|
|
730
|
-
### 3. Mathematical Formula Optimization
|
|
731
|
-
|
|
732
|
-
```tsx
|
|
733
|
-
// β
Recommended: Load on demand
|
|
734
|
-
import { katexPlugin } from 'ds-markdown/plugins';
|
|
735
|
-
import 'ds-markdown/katex.css'; // Only import when needed
|
|
736
|
-
|
|
737
|
-
<DsMarkdown plugins={[katexPlugin]}>Mathematical formula content</DsMarkdown>;
|
|
738
|
-
```
|
|
739
|
-
|
|
740
|
-
### 4. Mermaid Chart Best Practices π
|
|
741
|
-
|
|
742
|
-
```tsx
|
|
743
|
-
// β
Recommended: Install plugin separately
|
|
744
|
-
npm install ds-markdown-mermaid-plugin
|
|
745
|
-
|
|
746
|
-
// β
Recommended: Configure suitable themes
|
|
747
|
-
const mermaidConfig = {
|
|
748
|
-
theme: 'default', // Choose based on application theme
|
|
749
|
-
flowchart: { useMaxWidth: true },
|
|
750
|
-
};
|
|
751
|
-
|
|
752
|
-
<ConfigProvider mermaidConfig={mermaidConfig}>
|
|
753
|
-
<DsMarkdown plugins={[mermaidPlugin]} />
|
|
754
|
-
</ConfigProvider>
|
|
755
|
-
```
|
|
137
|
+
Contributions, issues and feature requests are welcome!
|
|
756
138
|
|
|
757
139
|
[](https://visitorbadge.io/status?path=https%3A%2F%2Fgithub.com%2Fonshinpei%2Fds-markdown)
|