Skip to content

Commit 47a9f26

Browse files
authored
feat: add x-markdown skills (#1813)
* feat: x-markdown skills * revert: revert x-sdks change * revert: x-sdks change * feat: add marketplace * fix: fix cr * fix: fix cr
1 parent b3f3923 commit 47a9f26

14 files changed

Lines changed: 737 additions & 4 deletions

File tree

packages/x-skill/.claude-plugin/marketplace.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "x-agent-skills",
33
"metadata": {
44
"description": "Ant Design X intelligent agent skills collection",
5+
"descriptionZh": "Ant Design X 智能技能库,提供完整的 AI 对话应用开发技能",
56
"version": "2.3.0-beta.1",
67
"author": "Ant Design X Team",
78
"homepage": "https://github.com/ant-design/x",
@@ -13,6 +14,8 @@
1314
"ant-design-x",
1415
"x-chat",
1516
"x-request",
17+
"x-markdown",
18+
"markdown",
1619
"chat-provider",
1720
"ai",
1821
"react",
@@ -23,9 +26,18 @@
2326
{
2427
"name": "x-sdk-skills",
2528
"description": "Ant Design X SDK core skill package, including complete features such as useXChat, XRequest, and custom Provider",
29+
"descriptionZh": "Ant Design X SDK 核心技能包,包含 useXChat、XRequest 和自定义 Provider 等完整功能",
2630
"source": "./",
2731
"strict": false,
2832
"skills": ["./skills/use-x-chat", "./skills/x-chat-provider", "./skills/x-request"]
33+
},
34+
{
35+
"name": "x-markdown",
36+
"description": "Ant Design X Markdown rendering skill package, providing rich text rendering and chat enhancement features",
37+
"descriptionZh": "Ant Design X Markdown 渲染技能包,提供富文本渲染和对话增强功能",
38+
"source": "./",
39+
"strict": false,
40+
"skills": ["./skills/x-markdown"]
2941
}
3042
]
3143
}

packages/x-skill/README-zh_CN.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
- 🤖 **智能化开发体验**:基于最佳实践的代码生成和优化建议,让 AI 辅助您的开发
1818
-**效率大幅提升**:减少重复性工作,加速 Ant Design X 项目开发
1919
- 🛡 **质量保证**:严格遵循 Ant Design X 设计规范,确保代码质量和一致性
20-
- 🎯 **场景全覆盖**:覆盖对话组件、数据请求、状态管理等常见 AI 应用场景
20+
- 🎯 **场景全覆盖**:覆盖对话组件、数据请求、状态管理、Markdown 渲染等常见 AI 应用场景
2121
- 🔧 **多 IDE 支持**:支持 Claude Code、CodeFuse、Cursor 等主流 AI IDE
2222

2323
## 📦 安装
@@ -81,10 +81,14 @@ npx x-skill
8181

8282
网络请求最佳实践,优化 API 调用和数据处理。
8383

84+
### x-markdown
85+
86+
Markdown 渲染指南,覆盖流式输出、自定义组件映射、插件与主题。
87+
8488
## 🎯 适用场景
8589

8690
- **🚀 新项目启动**:快速搭建 Ant Design X 项目框架,包含完整的配置和最佳实践
87-
- **⚙️ 功能开发**获取组件使用最佳实践和代码示例,加速功能实现
91+
- **⚙️ 功能开发**获取组件使用、渲染与集成的最佳实践和代码示例,加速功能实现
8892
- **🔍 问题排查**:智能诊断和解决常见开发问题,提供专业的解决方案
8993
- **📈 性能优化**:获取性能调优的专业建议,提升应用性能
9094

packages/x-skill/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Intelligent skill library specially designed for Ant Design X
1717
- 🤖 **Intelligent Development Experience**: Code generation and optimization suggestions based on best practices, with AI assisting your development
1818
-**Significant Efficiency Boost**: Reduce repetitive work and accelerate Ant Design X project development
1919
- 🛡 **Quality Assurance**: Strictly follow Ant Design X design specifications to ensure code quality and consistency
20-
- 🎯 **Full Scenario Coverage**: Cover common AI application scenarios like conversation components, data requests, and state management
20+
- 🎯 **Full Scenario Coverage**: Cover common AI application scenarios like conversation components, data requests, state management, and Markdown rendering
2121
- 🔧 **Multi-IDE Support**: Support mainstream AI IDEs like Claude Code, CodeFuse, and Cursor
2222

2323
## 📦 Installation
@@ -81,10 +81,14 @@ Chat data flow management, providing efficient data stream processing solutions.
8181

8282
Network request best practices, optimizing API calls and data processing.
8383

84+
### x-markdown
85+
86+
Markdown rendering guide for streaming output, component mapping, plugins, and themes.
87+
8488
## 🎯 Applicable Scenarios
8589

8690
- **🚀 New Project Startup**: Quickly set up Ant Design X project framework with complete configuration and best practices
87-
- **⚙️ Feature Development**: Get best practices and code examples for component usage to accelerate feature implementation
91+
- **⚙️ Feature Development**: Get best practices and code examples for component usage, rendering, and integration to accelerate feature implementation
8892
- **🔍 Problem Troubleshooting**: Intelligent diagnosis and resolution of common development issues with professional solutions
8993
- **📈 Performance Optimization**: Get professional advice for performance tuning to improve application performance
9094

packages/x-skill/scripts/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ const skillConfig: Config = {
4141
zh: {
4242
'use-x-chat': 'packages/x/docs/x-sdk/use-x-chat.zh-CN.md',
4343
'x-request': 'packages/x/docs/x-sdk/x-request.zh-CN.md',
44+
'x-markdown': 'packages/x/docs/x-markdown/examples.zh-CN.md',
4445
},
4546
en: {
4647
'use-x-chat': 'packages/x/docs/x-sdk/use-x-chat.en-US.md',
4748
'x-request': 'packages/x/docs/x-sdk/x-request.en-US.md',
49+
'x-markdown': 'packages/x/docs/x-markdown/examples.en-US.md',
4850
},
4951
paths: {
5052
// 中文技能目录
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
name: x-markdown
3+
version: 2.3.0-beta.1
4+
description: 当任务涉及 @ant-design/x-markdown 的 Markdown 渲染、流式输出、自定义组件映射、插件、主题或聊天富内容展示时使用。
5+
---
6+
7+
# 🎯 技能定位
8+
9+
**本技能专注解决一个问题**:如何用 `@ant-design/x-markdown` 正确、稳定地渲染 Markdown 内容。
10+
11+
覆盖范围包括:
12+
13+
- 基础渲染与包职责边界
14+
- LLM 流式输出与不完整语法处理
15+
- 自定义组件映射与聊天富内容渲染
16+
- 插件、主题与安全默认配置
17+
18+
## 目录导航
19+
20+
- [📦 包职责边界](#-包职责边界)
21+
- [🚀 快速决策指南](#-快速决策指南)
22+
- [🛠 推荐工作流](#-推荐工作流)
23+
- [🚨 开发规则](#-开发规则)
24+
- [🤝 技能协作](#-技能协作)
25+
- [🔗 参考资源](#-参考资源)
26+
27+
# 📦 包职责边界
28+
29+
| 层级 | 包名 | 职责 |
30+
| ---------- | ------------------------ | ----------------------------------------------- |
31+
| **UI层** | `@ant-design/x` | 聊天 UI、Bubble、Sender、交互组件 |
32+
| **数据层** | `@ant-design/x-sdk` | Provider、请求、流式数据流、状态管理 |
33+
| **渲染层** | `@ant-design/x-markdown` | Markdown 解析、流式渲染、插件、主题、自定义渲染 |
34+
35+
> ⚠️ `x-markdown` 不是聊天状态管理工具。它负责把已有消息内容渲染出来,不负责请求和消息流本身。
36+
37+
# 🚀 快速决策指南
38+
39+
| 当你需要... | 优先阅读 | 典型结果 |
40+
| --- | --- | --- |
41+
| 用最小配置渲染 Markdown | [CORE.md](reference/CORE.md) |`XMarkdown` 渲染基础内容 |
42+
| 渲染 LLM 流式输出 | [STREAMING.md](reference/STREAMING.md) | 正确处理 `hasNextChunk`、占位符、尾部指示器 |
43+
| 把标签映射到业务组件 | [EXTENSIONS.md](reference/EXTENSIONS.md) | 为自定义标签、代码块、富内容组件建立稳定映射 |
44+
| 增加插件或主题定制 | [EXTENSIONS.md](reference/EXTENSIONS.md) | 完成插件导入、主题类名接入、最小 CSS 覆盖 |
45+
| 查看属性细节和默认值 | [API.md](reference/API.md) | 获取 `XMarkdown` 与 streaming 的完整属性表 |
46+
47+
# 🛠 推荐工作流
48+
49+
1. 先看 [CORE.md](reference/CORE.md),先让基础渲染跑通。
50+
2. 只有在内容是分块到达时,才继续看 [STREAMING.md](reference/STREAMING.md)
51+
3. 只有在需要自定义标签、插件、主题时,才继续看 [EXTENSIONS.md](reference/EXTENSIONS.md)
52+
4. 属性名与默认值以 [API.md](reference/API.md) 为准,不要凭记忆猜。
53+
54+
## 最小使用示例
55+
56+
```tsx
57+
import { XMarkdown } from '@ant-design/x-markdown';
58+
59+
export default () => <XMarkdown content="# Hello" />;
60+
```
61+
62+
# 🚨 开发规则
63+
64+
- `components` 映射尽量保持稳定,不要在每次渲染时创建新的内联组件对象。
65+
- 最后一块内容必须设置 `streaming.hasNextChunk = false`,否则不完整占位内容不会被刷新成最终结果。
66+
- 谨慎处理原始 HTML。如果只想保留文本展示,优先使用 `escapeRawHtml`
67+
- 如果必须渲染 HTML,请显式审查 `dompurifyConfig`,不要依赖模糊默认行为。
68+
- 主题覆盖尽量最小化。先继承 `x-markdown-light``x-markdown-dark`,只改必要变量。
69+
- 如果自定义组件依赖完整语法,再在 `streamStatus === 'done'` 时执行昂贵逻辑。
70+
71+
# 🤝 技能协作
72+
73+
| 场景 | 推荐技能组合 | 原因 |
74+
| --- | --- | --- |
75+
| 聊天中的富文本回答 | `x-chat-provider``x-request``use-x-chat``x-markdown` | 前三者负责数据流,`x-markdown` 负责最终内容渲染 |
76+
| 内置 Provider + Markdown 回复 | `x-request``use-x-chat``x-markdown` | 请求配置与渲染职责分离 |
77+
| 独立的 Markdown 页面或文档视图 | `x-markdown` | 不需要聊天状态管理 |
78+
79+
## 边界规则
80+
81+
- 适配接口格式,用 **`x-chat-provider`**
82+
- 配置传输、认证、重试、流分隔,用 **`x-request`**
83+
- 管理 React 聊天状态,用 **`use-x-chat`**
84+
- 处理 Markdown 解析、流式恢复和富组件渲染,用 **`x-markdown`**
85+
86+
# 🔗 参考资源
87+
88+
- [CORE.md](reference/CORE.md) - 包职责、安装与起步、安全默认值、常见渲染模式
89+
- [STREAMING.md](reference/STREAMING.md) - 分块渲染、不完整语法恢复、loading/done 行为
90+
- [EXTENSIONS.md](reference/EXTENSIONS.md) - 组件映射、插件、主题、自定义标签建议
91+
- [API.md](reference/API.md) - 从官方 `x-markdown` 文档生成的 API 参考
92+
93+
## 官方文档
94+
95+
- [XMarkdown 介绍](https://github.com/ant-design/x/blob/main/packages/x/docs/x-markdown/introduce.zh-CN.md)
96+
- [XMarkdown 示例](https://github.com/ant-design/x/blob/main/packages/x/docs/x-markdown/examples.zh-CN.md)
97+
- [XMarkdown 流式渲染](https://github.com/ant-design/x/blob/main/packages/x/docs/x-markdown/streaming.zh-CN.md)
98+
- [XMarkdown Components](https://github.com/ant-design/x/blob/main/packages/x/docs/x-markdown/components.zh-CN.md)
99+
- [XMarkdown 插件](https://github.com/ant-design/x/blob/main/packages/x/docs/x-markdown/plugins.zh-CN.md)
100+
- [XMarkdown 主题](https://github.com/ant-design/x/blob/main/packages/x/docs/x-markdown/themes.zh-CN.md)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
| 属性 | 说明 | 类型 | 默认值 |
2+
| --- | --- | --- | --- |
3+
| content | 需要渲染的 Markdown 内容 | `string` | - |
4+
| children | Markdown 内容(与 `content` 二选一) | `string` | - |
5+
| components | 将 HTML 节点映射为自定义 React 组件 | `Record<string, React.ComponentType<ComponentProps> \| keyof JSX.IntrinsicElements>` | - |
6+
| streaming | 流式渲染行为配置 | `StreamingOption` | - |
7+
| config | Marked 解析配置,后应用且可能覆盖内置 renderer | [`MarkedExtension`](https://marked.js.org/using_advanced#options) | `{ gfm: true }` |
8+
| rootClassName | 根元素的额外 CSS 类名 | `string` | - |
9+
| className | 根容器的额外 CSS 类名 | `string` | - |
10+
| paragraphTag | 段落使用的 HTML 标签(避免自定义组件含块级元素时的校验问题) | `keyof JSX.IntrinsicElements` | `'p'` |
11+
| style | 根容器的内联样式 | `CSSProperties` | - |
12+
| prefixCls | 组件节点 CSS 类名前缀 | `string` | - |
13+
| openLinksInNewTab | 是否为所有链接添加 `target="_blank"` 并在新标签页打开 | `boolean` | `false` |
14+
| dompurifyConfig | HTML 净化与 XSS 防护的 DOMPurify 配置 | [`DOMPurify.Config`](https://github.com/cure53/DOMPurify#can-i-configure-dompurify) | - |
15+
| protectCustomTagNewlines | 是否保留自定义标签内部的换行 | `boolean` | `false` |
16+
| escapeRawHtml | 是否将 Markdown 中的原始 HTML 转义为纯文本展示(不解析为真实 HTML),用于防 XSS 同时保留内容 | `boolean` | `false` |
17+
| debug | 是否开启调试模式(显示性能监控浮层) | `boolean` | `false` |
18+
19+
### StreamingOption
20+
21+
| 字段 | 说明 | 类型 | 默认值 |
22+
| --- | --- | --- | --- |
23+
| hasNextChunk | 是否还有后续内容块。为 `false` 时会刷新缓存并完成渲染 | `boolean` | `false` |
24+
| enableAnimation | 是否为块级元素启用文字淡入动画 | `boolean` | `false` |
25+
| animationConfig | 动画配置(如淡入时长、缓动函数) | `AnimationConfig` | - |
26+
| tail | 是否启用尾部指示器 | `boolean \| TailConfig` | `false` |
27+
| incompleteMarkdownComponentMap | 将未闭合 Markdown 片段映射到自定义 loading 组件 | `Partial<Record<'link' \| 'image' \| 'html' \| 'emphasis' \| 'list' \| 'table' \| 'inline-code', string>>` | `{ link: 'incomplete-link', image: 'incomplete-image' }` |
28+
29+
### TailConfig
30+
31+
| 属性 | 说明 | 类型 | 默认值 |
32+
| --- | --- | --- | --- |
33+
| content | 尾部显示的内容 | `string` | `'▋'` |
34+
| component | 自定义尾部组件,优先级高于 content | `React.ComponentType<{ content?: string }>` | - |
35+
36+
### AnimationConfig
37+
38+
| 属性 | 说明 | 类型 | 默认值 |
39+
| ------------ | ---------------- | -------- | --------------- |
40+
| fadeDuration | 动画时长(毫秒) | `number` | `200` |
41+
| easing | 缓动函数 | `string` | `'ease-in-out'` |
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# 核心指南
2+
3+
## 包职责边界
4+
5+
| 需求 | 对应包 |
6+
| ----------------------------- | ------------------------ |
7+
| 把消息内容渲染成 Markdown | `@ant-design/x-markdown` |
8+
| 构建聊天 UI 容器 | `@ant-design/x` |
9+
| 管理 Provider、请求与消息状态 | `@ant-design/x-sdk` |
10+
11+
## 安装与最小渲染
12+
13+
```bash
14+
npm install @ant-design/x-markdown
15+
```
16+
17+
```tsx
18+
import { XMarkdown } from '@ant-design/x-markdown';
19+
20+
const content = `
21+
# Hello
22+
23+
- item 1
24+
- item 2
25+
`;
26+
27+
export default () => <XMarkdown content={content} />;
28+
```
29+
30+
## 安全默认值
31+
32+
- `content``children` 二选一即可,不要同时传。
33+
- 先让纯 Markdown 渲染正确,再加插件或自定义组件。
34+
- 当模型输出可能包含外链时,优先开启 `openLinksInNewTab`
35+
- 如果原始 HTML 只需要保留文本展示,优先使用 `escapeRawHtml`
36+
- 如果必须渲染真实 HTML,请显式检查 `dompurifyConfig`
37+
38+
## 常见集成模式
39+
40+
### 基础内容块
41+
42+
```tsx
43+
<XMarkdown content={message} className="x-markdown-light" />
44+
```
45+
46+
### 聊天消息渲染
47+
48+
`useXChat` 产出消息列表之后,再用 `XMarkdown` 负责内容展示。
49+
50+
```tsx
51+
<XMarkdown content={message.message.content} openLinksInNewTab escapeRawHtml />
52+
```
53+
54+
### 最小检查清单
55+
56+
- 先确认内容本身真的是 Markdown,而不是结构化组件协议。
57+
- 不要把渲染逻辑塞进 Provider。
58+
- 不要把请求逻辑塞进 `XMarkdown`
59+
- 主题和自定义组件放在基础渲染稳定之后再加。
60+
61+
## 何时继续阅读其他参考
62+
63+
- 内容是流式分块到达时,阅读 [STREAMING.md](STREAMING.md)
64+
- 需要自定义标签、代码块、插件、主题时,阅读 [EXTENSIONS.md](EXTENSIONS.md)
65+
- 需要完整属性表时,阅读 `API.md`
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# 扩展指南
2+
3+
## Components
4+
5+
`components` 是主要扩展入口,可把 Markdown 或自定义 HTML 标签映射到 React 组件。
6+
7+
```tsx
8+
import { Mermaid, Sources, Think } from '@ant-design/x';
9+
import { XMarkdown } from '@ant-design/x-markdown';
10+
11+
<XMarkdown
12+
content={content}
13+
components={{
14+
mermaid: Mermaid,
15+
think: Think,
16+
sources: Sources,
17+
}}
18+
/>;
19+
```
20+
21+
### 组件映射规则
22+
23+
- 映射对象尽量保持稳定,避免每次渲染创建新对象。
24+
-`streamStatus` 区分临时 loading UI 和最终渲染结果。
25+
- 如果自定义组件内部包含块级元素,必要时用 `paragraphTag` 避免非法嵌套。
26+
- 自定义标签应语义明确,避免混乱的 Markdown/HTML 混写。
27+
28+
## 插件
29+
30+
内置插件从 `@ant-design/x-markdown/plugins/...` 导入,并通过 `config` 接入。
31+
32+
```tsx
33+
import Latex from '@ant-design/x-markdown/plugins/Latex';
34+
35+
<XMarkdown
36+
content={content}
37+
config={{
38+
extensions: Latex(),
39+
}}
40+
/>;
41+
```
42+
43+
当需求属于“新增解析语法”时用插件;仅仅是替换已渲染节点的视觉表现时,用 `components` 更合适。
44+
45+
## 主题
46+
47+
先从内置主题样式开始。
48+
49+
```tsx
50+
import '@ant-design/x-markdown/themes/light.css';
51+
52+
<XMarkdown className="x-markdown-light" content={content} />;
53+
```
54+
55+
如果要定制:
56+
57+
1. 保留内置主题类名
58+
2. 额外加一个自定义类名
59+
3. 只覆盖真正需要的 CSS 变量
60+
61+
## 自定义标签建议
62+
63+
- 保持自定义标签结构完整
64+
- 除非语法有意为之,否则避免在自定义 HTML 块内部插入多余空行
65+
- 如果自定义标签内换行需要保留,检查 `protectCustomTagNewlines`
66+
67+
## 如何选工具
68+
69+
-`components` 替换渲染后的节点
70+
- 用插件扩展 Markdown 解析能力
71+
- 用主题控制排版、间距和颜色
72+
-`dompurifyConfig``escapeRawHtml` 处理安全,不要拿它们做视觉定制

0 commit comments

Comments
 (0)