Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/pr_preview-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ jobs:
* [VIM 编辑模式](${{steps.deploy.outputs.url}}/vim.html)
* [使用自带或自定义的 Mermaid.js](${{steps.deploy.outputs.url}}/mermaid.html)
* [自定义代码块外层容器](${{steps.deploy.outputs.url}}/custom_codeblock_wrapper.html)
* [流式输出包](${{steps.deploy.outputs.url}}/ai_chat_stream.html)
<!-- [工作流地址](${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}) -->
<!-- AUTO_PREVIEW_HOOK -->
number: ${{ steps.pr.outputs.id }}
Expand Down
49 changes: 49 additions & 0 deletions README.CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Cherry Markdown Writer 是一款 Javascript Markdown 编辑器,具有开箱即
- [表格编辑](https://tencent.github.io/cherry-markdown/examples/table.html)
- [自动编号标题](https://tencent.github.io/cherry-markdown/examples/head_num.html)
- [流式输入模式(AI chat 场景)](https://tencent.github.io/cherry-markdown/examples/ai_chat.html)
- [流式输入模式 - 可选插件懒加载](https://tencent.github.io/cherry-markdown/examples/ai_chat_stream.html)
- [VIM 编辑模式](https://tencent.github.io/cherry-markdown/examples/vim.html)
- [使用自带或自定义的 Mermaid.js](https://tencent.github.io/cherry-markdown/examples/mermaid.html)
- [自定义代码块外层容器](https://tencent.github.io/cherry-markdown/examples/custom_codeblock_wrapper.html)
Expand Down Expand Up @@ -246,6 +247,54 @@ const cherryInstance = new Cherry({
});
````

### 流式输出包(Stream Build)

Cherry 提供了专为流式输出场景优化的构建包,该包不包含 mermaid、CodeMirror 等大型依赖,可实现按需懒加载,非常适合 AI Chat 等场景。

```javascript
import 'cherry-markdown/dist/cherry-markdown.css';
import Cherry from 'cherry-markdown/dist/cherry-markdown.stream';

// 流式输出包默认不包含以下依赖,可按需加载:
// - mermaid(流程图)
// - CodeMirror(代码编辑器)

const cherryInstance = new Cherry({
id: 'markdown-container',
});

cherryInstance.setMarkdown('# welcome to cherry editor!');
```

#### 为流式输出包加载 Mermaid 插件

```javascript
import 'cherry-markdown/dist/cherry-markdown.css';
import Cherry from 'cherry-markdown/dist/cherry-markdown.stream';
import CherryMermaidPlugin from 'cherry-markdown/dist/addons/cherry-code-block-mermaid-plugin';
import mermaid from 'mermaid';

// 插件注册必须在 Cherry 实例化之前完成
Cherry.usePlugin(CherryMermaidPlugin, {
mermaid,
mermaidAPI: mermaid,
});

const cherryInstance = new Cherry({
id: 'markdown-container',
});
```

#### 流式输出包与核心包的区别

| 构建包 | 文件 | 包含 Mermaid | 包含 CodeMirror | 适用场景 |
| ---------- | --------------------------- | ------------ | --------------- | ---------------- |
| 完整包 | `cherry-markdown.js` | ✅ | ✅ | 通用场景 |
| 核心包 | `cherry-markdown.core.js` | ❌ | ✅ | 不需要 Mermaid |
| 流式输出包 | `cherry-markdown.stream.js` | ❌ | ❌ | AI Chat 流式输出 |

> 注意:MathJax/KaTeX 为外部依赖,通过 CDN 动态加载,不包含在任何构建包中。

### 异步加载

强烈推荐使用动态引入(Dynamic import),下面给出 webpack 动态引入的示例。
Expand Down
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Cherry Markdown Writer is a Javascript Markdown editor. It has the advantages su
- [Table WYSIWYG](https://tencent.github.io/cherry-markdown/examples/table.html)
- [Headers with Auto Num](https://tencent.github.io/cherry-markdown/examples/head_num.html)
- [Streaming rendering Mode (AI chat scenario)](https://tencent.github.io/cherry-markdown/examples/ai_chat.html)
- [Streaming Mode - Lazy Loading Plugins](https://tencent.github.io/cherry-markdown/examples/ai_chat_stream.html)
- [VIM Editing Mode](https://tencent.github.io/cherry-markdown/examples/vim.html)
- [Utilize Your Own Mermaid.js](https://tencent.github.io/cherry-markdown/examples/mermaid.html)
- [Custom Code Block Wrapper](https://tencent.github.io/cherry-markdown/examples/custom_codeblock_wrapper.html)
Expand Down Expand Up @@ -245,6 +246,55 @@ const cherryInstance = new Cherry({
});
````

### Stream Build

Cherry provides a build package optimized for streaming output scenarios. This package does not include large dependencies like mermaid or CodeMirror, enabling on-demand lazy loading. It is ideal for AI Chat and similar scenarios.

```javascript
import 'cherry-markdown/dist/cherry-markdown.css';
import Cherry from 'cherry-markdown/dist/cherry-markdown.stream';

// The stream build does not include the following dependencies by default,
// which can be loaded on demand:
// - mermaid (flowcharts)
// - CodeMirror (code editor)

const cherryInstance = new Cherry({
id: 'markdown-container',
});

cherryInstance.setMarkdown('# welcome to cherry editor!');
```

#### Loading Mermaid Plugin for Stream Build

```javascript
import 'cherry-markdown/dist/cherry-markdown.css';
import Cherry from 'cherry-markdown/dist/cherry-markdown.stream';
import CherryMermaidPlugin from 'cherry-markdown/dist/addons/cherry-code-block-mermaid-plugin';
import mermaid from 'mermaid';

// Plugin registration must be done before Cherry is instantiated
Cherry.usePlugin(CherryMermaidPlugin, {
mermaid,
mermaidAPI: mermaid,
});

const cherryInstance = new Cherry({
id: 'markdown-container',
});
```

#### Differences Between Stream Build and Core Build

| Build | File | Mermaid | CodeMirror | Use Case |
| ------ | --------------------------- | ------- | ---------- | ----------------- |
| Full | `cherry-markdown.js` | ✅ | ✅ | General purpose |
| Core | `cherry-markdown.core.js` | ❌ | ✅ | Without Mermaid |
| Stream | `cherry-markdown.stream.js` | ❌ | ❌ | AI Chat streaming |

> Note: MathJax/KaTeX are external dependencies loaded dynamically via CDN and are not included in any build package.

### Dynamic import

**recommend** Using Dynamic import, the following is an example of webpack Dynamic import.
Expand Down
Loading
Loading