Skip to content
Discussion options

You must be logged in to vote

Hi @zhcn000000! I'm Dosu and I’m helping the x team.

可以实现。XMarkdown 支持通过 components 属性自定义渲染 HTML 标签,你可以把 imgaudiovideo 标签映射为自定义的 React 组件,然后用 FileCard 渲染这些外链文件。FileCard 支持 type(如 'image' | 'audio' | 'video')、srcname 等属性,能很好地展示图片、音频、视频等外部资源,并且支持流式渲染状态(streamStatus)和自定义 loading 处理。

简单实现示例:

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={t…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by zhcn000000
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants