Skip to content

Commit 8d45177

Browse files
committed
chore: add markdown demo stream
1 parent fb6ad2b commit 8d45177

File tree

3 files changed

+509
-129
lines changed

3 files changed

+509
-129
lines changed

src/Markdown/demos/content.ts

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
export const fullContent = `# Complete Markdown Integration Example
2+
3+
This demonstrates a comprehensive real-world example of how different markdown features work together in a cohesive document.
4+
5+
## AI Assistant Capabilities
6+
7+
Hello! I'm an AI assistant powered by advanced language models. I can help you with various tasks:
8+
9+
1. **Question Answering** - Provide detailed responses to complex queries
10+
2. **Information Research** - Gather and synthesize information from multiple sources
11+
3. **Code Development** - Write, review, and debug code in multiple languages
12+
4. **Concept Explanation** - Break down complex topics into understandable parts
13+
14+
## Long Paragraph Example
15+
16+
This is the first paragraph demonstrating the text-box-trim and text-edge properties. In modern web design, typography plays a crucial role in creating readable and visually appealing content. When browsers support the text-box-trim property, we can achieve more precise control over vertical spacing, eliminating unnecessary whitespace that can affect the overall layout.
17+
18+
This is the second paragraph showing how margin-inline-start and margin-inline-end create horizontal spacing for paragraphs. By setting appropriate inline margins, we can create visual separation between paragraphs while maintaining a clean, structured appearance. This approach is particularly effective for long-form content like articles, documentation, and blog posts.
19+
20+
This is the third paragraph illustrating the line-height property set to 2. A generous line height significantly improves readability by providing more breathing room between lines of text. This spacing reduces visual fatigue and makes it easier for readers to follow along, especially when reading extended passages of text.
21+
22+
This is the fourth paragraph explaining the text-box-trim: trim-both property. When supported by the browser, this CSS feature automatically trims the leading and trailing whitespace of text boxes, allowing for more precise control over paragraph spacing. Combined with text-edge: cap alphabetic, we can achieve professional typographic alignment.
23+
24+
This is the fifth paragraph discussing practical applications of these typography techniques. These styling approaches are particularly well-suited for displaying long articles, blog content, technical documentation, and any scenario where excellent readability is essential. Proper spacing and line height can transform dense text into an enjoyable reading experience.
25+
26+
This is the sixth paragraph covering the separation of concerns in typography. Paragraph spacing is controlled through margin-block-start and margin-block-end, while horizontal spacing uses margin-inline-start and margin-inline-end. This separation provides flexibility in controlling layout effects independently, allowing designers to fine-tune the visual presentation.
27+
28+
This is the seventh paragraph exploring modern CSS capabilities. New CSS features like text-box-trim and text-edge give us unprecedented control over text rendering. These properties enable more precise typographic control, helping us achieve professional-grade layouts that were previously difficult to implement with traditional CSS approaches.
29+
30+
This is the eighth paragraph demonstrating the visual effect of multiple paragraphs. Each paragraph benefits from appropriate horizontal margins and a line-height of 2, creating a comfortable reading rhythm. This design approach proves highly effective in long-form reading scenarios, where user comfort and comprehension are paramount.
31+
32+
This is the ninth paragraph emphasizing the importance of typography in user experience. Text formatting is not merely a technical concern but a fundamental component of user experience design. Well-crafted typography helps users understand content more easily, reduces reading burden, and enhances overall usability. This is why attention to these details matters.
33+
34+
This is the tenth and final paragraph concluding our exploration of paragraph styling. Through thoughtful spacing and line-height settings, we can create text layouts that are both aesthetically pleasing and highly functional. This design approach deserves consideration and application in real-world projects where readability and user experience are priorities.
35+
36+
Thank you for exploring these markdown capabilities!
37+
38+
## React Component Implementation
39+
40+
Here's a complete React component that demonstrates markdown integration:
41+
42+
\`\`\`tsx
43+
import { memo, useMemo } from 'react';
44+
import ReactMarkdown from 'react-markdown';
45+
46+
import { PreviewGroup } from '@/Image';
47+
import { useMarkdown } from '@/hooks/useMarkdown';
48+
49+
import { SyntaxMarkdownProps } from '../type';
50+
\`\`\`
51+
52+
## Mathematical Formula Support
53+
54+
Advanced mathematical expressions are fully supported through LaTeX integration:
55+
56+
### Fourier Transform
57+
The Fourier transform converts signals between time and frequency domains:
58+
59+
$$
60+
f(x) = \\int_{-\\infty}^{\\infty} \\hat{f}(\\xi) e^{2\\pi i \\xi x} d\\xi
61+
$$
62+
63+
### Complex Analysis
64+
For complex functions, we can express relationships like:
65+
66+
$$
67+
\\frac{d}{dz}f(z) = \\lim_{h \\to 0} \\frac{f(z+h) - f(z)}{h}
68+
$$
69+
70+
## Data Flow Visualization
71+
72+
\`\`\`mermaid
73+
graph TD
74+
A[User Input] --> B[Markdown Parser]
75+
B --> C[Plugin Processing]
76+
C --> D[Component Rendering]
77+
D --> E[Final Output]
78+
79+
B --> F[LaTeX Processing]
80+
F --> D
81+
82+
B --> G[Mermaid Processing]
83+
G --> D
84+
85+
B --> H[Code Highlighting]
86+
H --> D
87+
\`\`\`
88+
89+
## Feature Integration Summary
90+
91+
| Feature | Status | Implementation |
92+
|---------|--------|----------------|
93+
| Headers | ✅ | Native markdown |
94+
| Text Formatting | ✅ | Bold, italic, strikethrough |
95+
| Code Blocks | ✅ | Syntax highlighting + annotations |
96+
| Math Formulas | ✅ | LaTeX via KaTeX |
97+
| Diagrams | ✅ | Mermaid integration |
98+
| Tables | ✅ | GitHub-flavored markdown |
99+
| Task Lists | ✅ | Interactive checkboxes |
100+
| Footnotes | ✅ | Reference system |
101+
`;
102+
103+
export const fullContentCN = `# 完整 Markdown 集成示例
104+
105+
这是一个全面的真实示例,展示了不同的 Markdown 功能如何在文档中协同工作。
106+
107+
## AI 助手能力
108+
109+
你好!我是由先进语言模型驱动的 AI 助手。我可以帮你完成各种任务:
110+
111+
1. **问题解答** - 对复杂查询提供详细回复
112+
2. **信息研究** - 收集并综合多源信息
113+
3. **代码开发** - 编写、审查和调试多种语言的代码
114+
4. **概念解释** - 将复杂主题分解为易懂的部分
115+
116+
## 长段落示例
117+
118+
这是第一段,演示 text-box-trim 和 text-edge 属性。在现代网页设计中,排版在创建可读且视觉吸引的内容方面起着至关重要的作用。当浏览器支持 text-box-trim 属性时,我们可以实现对垂直间距的更精确控制,消除可能影响整体布局的不必要空白。
119+
120+
这是第二段,展示 margin-inline-start 和 margin-inline-end 如何为段落创建水平间距。通过设置适当的内联边距,我们可以在保持整洁结构外观的同时,在段落之间创建视觉分隔。这种方法对于长篇文章、文档和博客帖子等内容特别有效。
121+
122+
这是 third 段,说明行高属性设置为 2。宽裕的行高通过在文本行之间提供更多呼吸空间,显著提高了可读性。这种间距减少了视觉疲劳,使读者更容易跟随,尤其是在阅读长段落文本时。
123+
124+
这是第四段,解释 text-box-trim: trim-both 属性。当浏览器支持时,此 CSS 功能会自动修剪文本框的前导和尾随空白,允许更精确地控制段落间距。结合 text-edge: cap alphabetic,我们可以实现专业的排版对齐。
125+
126+
这是第五段,讨论这些排版技术的实际应用。这些样式方法特别适合显示长篇文章、博客内容、技术文档以及任何极其重视可读性的场景。适当的间距和行高可以将密集的文本转变为愉快的阅读体验。
127+
128+
这是第六段,涵盖排版中的关注点分离。段落间距通过 margin-block-start 和 margin-block-end 控制,而水平间距使用 margin-inline-start 和 margin-inline-end。这种分离提供了独立控制布局效果的灵活性,允许设计师微调视觉呈现。
129+
130+
这是第七段,探索现代 CSS 能力。像 text-box-trim 和 text-edge 这样的新 CSS 功能让我们对文本渲染有了前所未有的控制。这些属性实现了更精确的排版控制,帮助我们实现以前使用传统 CSS 方法难以实现的专业级布局。
131+
132+
这是第八段,演示多个段落的视觉效果。每个段落都受益于适当的水平边距和 2 的行高,创造了舒适的阅读节奏。这种设计方法在长篇阅读场景中被证明非常有效,因为用户的舒适度和理解力至关重要。
133+
134+
这是第九段,强调排版在用户体验中的重要性。文本格式不仅仅是一个技术问题,而是用户体验设计的一个基本组成部分。精心制作的排版有助于用户更容易理解内容,减少阅读负担,并增强整体可用性。这就是为什么关注这些细节很重要的原因。
135+
136+
这是第十段也是最后一段,总结我们对段落样式的探索。通过周到的间距和行高设置,我们可以创建既美观又高度实用的文本布局。这种设计方法值得在可读性和用户体验优先的实际项目中考虑和应用。
137+
138+
感谢探索这些 markdown 功能!
139+
140+
## React 组件实现
141+
142+
这是一个演示 markdown 集成的完整 React 组件:
143+
144+
\`\`\`tsx
145+
import { memo, useMemo } from 'react';
146+
import ReactMarkdown from 'react-markdown';
147+
148+
import { PreviewGroup } from '@/Image';
149+
import { useMarkdown } from '@/hooks/useMarkdown';
150+
151+
import { SyntaxMarkdownProps } from '../type';
152+
\`\`\`
153+
154+
## 数学公式支持
155+
156+
通过 LaTeX 集成完全支持高级数学表达式:
157+
158+
### 傅里叶变换
159+
傅里叶变换在时域和频域之间转换信号:
160+
161+
$$
162+
f(x) = \\int_{-\\infty}^{\\infty} \\hat{f}(\\xi) e^{2\\pi i \\xi x} d\\xi
163+
$$
164+
165+
### 复分析
166+
对于复函数,我们可以表达如下关系:
167+
168+
$$
169+
\\frac{d}{dz}f(z) = \\lim_{h \\to 0} \\frac{f(z+h) - f(z)}{h}
170+
$$
171+
172+
## 数据流可视化
173+
174+
\`\`\`mermaid
175+
graph TD
176+
A[用户输入] --> B[Markdown 解析器]
177+
B --> C[插件处理]
178+
C --> D[组件渲染]
179+
D --> E[最终输出]
180+
181+
B --> F[LaTeX 处理]
182+
F --> D
183+
184+
B --> G[Mermaid 处理]
185+
G --> D
186+
187+
B --> H[代码高亮]
188+
H --> D
189+
\`\`\`
190+
191+
## 功能集成摘要
192+
193+
| 功能 | 状态 | 实现 |
194+
|---------|--------|----------------|
195+
| 标题 | ✅ | 原生 markdown |
196+
| 文本格式 | ✅ | 粗体、斜体、删除线 |
197+
| 代码块 | ✅ | 语法高亮 + 注释 |
198+
| 数学公式 | ✅ | 通过 KaTeX 实现 LaTeX |
199+
| 图表 | ✅ | Mermaid 集成 |
200+
| 表格 | ✅ | GitHub 风格 markdown |
201+
| 任务列表 | ✅ | 交互式复选框 |
202+
| 脚注 | ✅ | 引用系统 |
203+
`;
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
export interface ChunkInfo {
2+
content: string;
3+
delay: number;
4+
index: number;
5+
}
6+
7+
interface LocalStreamControl {
8+
shouldPause?: () => boolean;
9+
signal?: AbortSignal;
10+
}
11+
12+
export const createLocalStream = (
13+
content: string,
14+
chunkSizeMin: number,
15+
chunkSizeMax: number,
16+
chunkDelayMin: number,
17+
chunkDelayMax: number,
18+
onChunk: (chunk: ChunkInfo) => void,
19+
control: LocalStreamControl = {},
20+
) => {
21+
const encoder = new TextEncoder();
22+
let currentPosition = 0;
23+
let chunkIndex = 0;
24+
const { shouldPause, signal } = control;
25+
26+
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
27+
const waitIfPaused = async () => {
28+
while (shouldPause?.()) {
29+
if (signal?.aborted) return;
30+
await sleep(50);
31+
}
32+
};
33+
34+
return new ReadableStream({
35+
async start(controller) {
36+
while (currentPosition < content.length) {
37+
if (signal?.aborted) break;
38+
await waitIfPaused();
39+
if (signal?.aborted) break;
40+
41+
// Calculate random chunk size and delay
42+
const chunkSize =
43+
Math.floor(Math.random() * (chunkSizeMax - chunkSizeMin + 1)) + chunkSizeMin;
44+
const delay =
45+
Math.floor(Math.random() * (chunkDelayMax - chunkDelayMin + 1)) + chunkDelayMin;
46+
47+
// Get chunk content
48+
const chunkContent = content.slice(currentPosition, currentPosition + chunkSize);
49+
50+
// Wait for delay
51+
await sleep(delay);
52+
if (signal?.aborted) break;
53+
await waitIfPaused();
54+
if (signal?.aborted) break;
55+
56+
// Enqueue chunk
57+
const encodedChunk = encoder.encode(chunkContent);
58+
controller.enqueue(encodedChunk);
59+
60+
// Notify chunk info
61+
onChunk({
62+
index: chunkIndex++,
63+
content: chunkContent,
64+
delay,
65+
});
66+
67+
currentPosition += chunkSize;
68+
}
69+
controller.close();
70+
},
71+
cancel() {
72+
// Optional: Handle cancellation if needed
73+
},
74+
});
75+
};

0 commit comments

Comments
 (0)