我可以在 XMarkdown 里把 llm 引用的外部链接表示的文件用 FileCard 显示吗 #1738
-
|
我可以在 XMarkdown 里把 llm 引用的外部链接表示的文件用 FileCard 显示吗,比如对 image,audio 和 video 的标签替换为 FileCard |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Hi @zhcn000000! I'm Dosu and I’m helping the x team. 可以实现。XMarkdown 支持通过 简单实现示例: import { XMarkdown } from '@ant-design/x-markdown';
import { FileCard } from '@ant-design/x';
const FileCardWrapper = ({ domNode, streamStatus, ...rest }) => {
// 解析标签类型
let type = 'file';
if (domNode.name === 'img') type = 'image';
if (domNode.name === 'audio') type = 'audio';
if (domNode.name === 'video') type = 'video';
// src、alt、title 等都在 rest 里
return (
<FileCard
type={type}
src={rest.src}
name={rest.alt || rest.title || rest.src}
loading={streamStatus === 'loading'}
// 你可以根据 type 传递 imageProps、audioProps、videoProps
{...rest}
/>
);
};
<XMarkdown
content={markdown}
components={{
img: FileCardWrapper,
audio: FileCardWrapper,
video: FileCardWrapper,
}}
/>这样,Markdown 里的图片、音频、视频标签就会自动用 FileCard 展示外链文件。 官方文档有详细说明 To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
|
@zhcn000000 可以的,x-markdown 支持自定义组件的映射 |
Beta Was this translation helpful? Give feedback.
Hi @zhcn000000! I'm Dosu and I’m helping the x team.
可以实现。XMarkdown 支持通过
components属性自定义渲染 HTML 标签,你可以把img、audio、video标签映射为自定义的 React 组件,然后用 FileCard 渲染这些外链文件。FileCard 支持type(如'image' | 'audio' | 'video')、src、name等属性,能很好地展示图片、音频、视频等外部资源,并且支持流式渲染状态(streamStatus)和自定义 loading 处理。简单实现示例: