Skip to content

Commit 2112a44

Browse files
authored
Merge branch 'main' into welcome
2 parents 625a4ae + 2efa4f5 commit 2112a44

File tree

248 files changed

+27361
-4575
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

248 files changed

+27361
-4575
lines changed

.dumi/theme/builtins/FormulaFunctions.tsx

Lines changed: 4319 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
// src/components/MarkdownEditor.tsx
2+
import React, { useEffect, useState } from "react";
3+
import Vditor from "vditor";
4+
import "vditor/dist/index.css";
5+
import { useSiteData } from 'dumi';
6+
7+
interface TutorialStep {
8+
en: string;
9+
zh: string;
10+
ja: string;
11+
}
12+
13+
// 定义教程内容数组,每个元素包含中、日、英三种语言的文本
14+
const tutorialSteps: TutorialStep[] = [
15+
{
16+
en: `
17+
# Welcome to the Markdown Editor
18+
19+
This is a tutorial on how to use the Markdown Editor.
20+
`,
21+
zh: `
22+
# 欢迎使用 Markdown 编辑器
23+
24+
这是一个关于如何使用 Markdown 编辑器的教程。
25+
`,
26+
ja: `
27+
# Markdownエディタへようこそ
28+
29+
これはMarkdownエディタの使い方に関するチュートリアルです。
30+
`,
31+
},
32+
{
33+
en: `
34+
## Markdown Syntax Basics
35+
36+
### Headers
37+
Use # for headers. For example:
38+
- # Header 1
39+
- ## Header 2
40+
- ### Header 3
41+
42+
### Emphasis
43+
- **Bold** will render as Bold.
44+
- *Italic* will render as Italic.
45+
- ~~Strikethrough~~ will render as Strikethrough.
46+
47+
### Links
48+
[NocoBase](https://www.nocobase.com/) creates a hyperlink.
49+
50+
### Images
51+
![Alt text](https://static-docs.nocobase.com/logo-nocobase.png)
52+
53+
### Blockquotes
54+
> This is a blockquote. Use the ">" symbol at the beginning of a line to create one.
55+
56+
### Code Blocks
57+
Use triple backticks (\`\`\`) for code blocks. Here's an example with JavaScript:
58+
59+
\`\`\`js
60+
function greet() {
61+
console.log('Hello, Markdown!');
62+
}
63+
greet();
64+
\`\`\`
65+
66+
### Math Blocks
67+
For math equations, you would typically use double dollar signs for block equations and single dollar signs for inline equations. Here are examples:
68+
$$ E = mc^2 $$
69+
Inline equation: $E = mc^2$
70+
71+
### Tables
72+
Tables are created with pipes (|) and dashes (-):
73+
| Column 1 | Column 2 | Column 3 |
74+
| --- | --- | --- |
75+
| Row 1 Data 1 | Row 1 Data 2 | Row 1 Data 3 |
76+
| Row 2 Data 1 | Row 2 Data 2 | Row 2 Data 3 |
77+
78+
### Emoji
79+
You can add emojis like :smile: which renders as 😄.
80+
81+
### Lists
82+
- Unordered lists use - or *.
83+
- Example: - Item 1
84+
85+
### Task Lists
86+
- [x] Completed task
87+
- [ ] Incomplete task
88+
`,
89+
zh: `
90+
## Markdown 基本语法
91+
92+
### 标题
93+
使用 # 表示标题。例如:
94+
- # 一级标题
95+
- ## 二级标题
96+
- ### 三级标题
97+
98+
### 强调
99+
- **加粗** 会显示为 加粗。
100+
- *斜体* 会显示为 斜体。
101+
- ~~删除线~~ 会显示为 删除线。
102+
103+
### 链接
104+
[NocoBase](https://www.nocobase.com/) 创建超链接。
105+
106+
### 图片
107+
![替代文字](https://static-docs.nocobase.com/logo-nocobase.png)
108+
109+
### 引用
110+
> 这是一个引用。在行首使用 “>” 符号来创建。
111+
112+
### 代码块
113+
使用三个反引号(\`\`\`)表示代码块。这里是一个 JavaScript 代码的例子:
114+
115+
\`\`\`js
116+
function greet() {
117+
console.log('你好,Markdown!');
118+
}
119+
greet();
120+
\`\`\`
121+
122+
### 公式块
123+
对于数学公式,通常使用双美元符号表示行间公式,单美元符号表示行内公式。这里有一些例子:
124+
$$ E = mc^2 $$
125+
行内公式: $E = mc^2$
126+
127+
### 表格
128+
表格通过竖线(|)和短横线(-)创建:
129+
| 列1 | 列2 | 列3 |
130+
| --- | --- | --- |
131+
| 第1行数据1 | 第1行数据2 | 第1行数据3 |
132+
| 第2行数据1 | 第2行数据2 | 第2行数据3 |
133+
134+
### 表情符号 Emoji
135+
你可以添加类似 :smile: 的表情符号,它会显示为 😄。
136+
137+
### 列表
138+
- 无序列表使用 - 或 *。
139+
- 示例:- 项目 1
140+
141+
### 任务列表
142+
- [x] 已完成的任务
143+
- [ ] 未完成的任务
144+
`,
145+
ja: `
146+
## Markdown 基本文法
147+
148+
### 見出し
149+
# を使って見出しを作成します。例えば:
150+
- # 見出し1
151+
- ## 見出し2
152+
- ### 見出し3
153+
154+
### 強調
155+
- **太字** は 太字 になります。
156+
- *斜体* は 斜体 になります。
157+
- ~~取り消し線~~ は 取り消し線 になります。
158+
159+
### リンク
160+
[NocoBase](https://www.nocobase.com/) はハイパーリンクを作成します。
161+
162+
### 画像
163+
![代替テキスト](https://static-docs.nocobase.com/logo-nocobase.png)
164+
165+
### 引用
166+
> これは引用です。行の最初に ">", シンボルを使用して作成します。
167+
168+
### コードブロック
169+
コードブロックは3つのバッククォート(\`\`\`)を使用します。以下がJavaScriptの例です:
170+
171+
\`\`\`js
172+
function greet() {
173+
console.log('こんにちは、Markdown!');
174+
}
175+
greet();
176+
\`\`\`
177+
178+
### 数式ブロック
179+
数式は通常、ダブルドル記号を使って行間数式を作成し、シングルドル記号を使って行内数式を作ります。以下がその例です:
180+
$$ E = mc^2 $$
181+
行内数式: $E = mc^2$
182+
183+
### テーブル
184+
テーブルはパイプ(|)とダッシュ(-)を使用して作成します:
185+
| 列1 | 列2 | 列3 |
186+
| --- | --- | --- |
187+
| 行1データ1 | 行1データ2 | 行1データ3 |
188+
| 行2データ1 | 行2データ2 | 行2データ3 |
189+
190+
### 絵文字 Emoji
191+
:smile: のような絵文字を追加できます。それは 😄 として表示されます。
192+
193+
### リスト
194+
- 箇条書きは - または * を使用します。
195+
- 例: - アイテム1
196+
197+
### タスクリスト
198+
- [x] 完了したタスク
199+
- [ ] 未完了のタスク
200+
`,
201+
},
202+
];
203+
204+
const MarkdownEditor: React.FC = () => {
205+
const [vditorInstance, setVditorInstance] = useState<Vditor | null>(null);
206+
const { themeConfig } = useSiteData();
207+
// 提取语言代码,如 'en', 'zh', 'ja'
208+
const language = themeConfig.lang.slice(0, 2);
209+
210+
// 根据当前语言拼接教程内容
211+
const assembleContent = (lang: string): string => {
212+
return tutorialSteps.map((step) => step[lang] || step['en']).join("\n");
213+
};
214+
215+
// 初始化 Vditor
216+
useEffect(() => {
217+
const initialContent = assembleContent(language);
218+
219+
const vditor = new Vditor("vditor", {
220+
value: initialContent,
221+
after: () => {
222+
setVditorInstance(vditor);
223+
},
224+
});
225+
226+
// 清理函数
227+
return () => {
228+
vditor.destroy();
229+
setVditorInstance(null);
230+
};
231+
// eslint-disable-next-line react-hooks/exhaustive-deps
232+
}, [language]);
233+
234+
// 当语言变化时,更新 Vditor 的内容
235+
useEffect(() => {
236+
if (vditorInstance) {
237+
const newContent = assembleContent(language);
238+
vditorInstance.setValue(newContent);
239+
}
240+
// eslint-disable-next-line react-hooks/exhaustive-deps
241+
}, [language]);
242+
243+
return <div id="vditor" className="vditor"></div>;
244+
};
245+
246+
export default MarkdownEditor;

0 commit comments

Comments
 (0)