如何使用 antd 设置带省略号的属性 "dangerouslySetInnerHTML"?

How to set attribute "dangerouslySetInnerHTML" with ellipsis using antd?

我需要用省略号显示评论。我为此使用了 antd 的 Paragraph Typography。 我的问题是评论也可以包含 html 属性(link 标记用户)所以我还需要在组件中设置 dangerouslySetInnerHTML。如何在 Typography 组件中设置?

<Paragraph ellipsis={{ rows: 2, expandable: true, symbol: "more" }}>
      {comment}
</Paragraph>

预览:

我尝试在 Paragraph 中使用 span 来使用 dangerouslySetInnerHTML,但随后省略号开始只对所有长评论显示“...更多”,而没有显示任何内容注释中的初始字符以填充宽度。在 <Paragraph></Paragragh> 中使用除字符串

之外的任何 HTML 元素时也会收到警告
<Paragraph ellipsis={{ rows: 2, expandable: true, symbol: "more" }}>
      <span dangerouslySetInnerHTML={{ __html: comment.comment }} />
</Paragraph>

预览:

警告:

实现此目的的任何解决方法?

首先,我也喜欢 antd Typography 的这个功能,但目前情况并非如此,所以在此期间,这里有一些解决方法。

import React, { useState } from "react";
import Button from "antd/es/button";

import ChopLines from "chop-lines";
import insane from "insane";

const Sanitized = ({ html }) => (
    <div
        className={styles.sanitizedBody}
        dangerouslySetInnerHTML={{
            __html: insane(html, {
                allowedTags: [
                    "p",
                    "strong",
                    "em",
                    "a",
                    "b",
                    "i",
                    "span",
                    "div",
                    "br",
                    "u",
                    "img",
                ],
            }),
        }}
    />
);

const Ellipsis = ({ expand }) => (
    <Button
        size="small"
        shape="round"
        type="primary"
        onClick={expand}
    >
        ...see more
    </Button>
);

const Post = ({content}) => {
    const [expanded, setExpanded] = useState(false);

    render (
        <div>
            {expanded ? (
                <Sanitized html={content} />
            ) : (
                <ChopLines
                    maxHeight={90}
                    ellipsis={
                        <Ellipsis expand={expand}>
                            <span>Read More</span>
                        </Ellipsis>
                    }
                >
                    <Sanitized html={content} />
                </ChopLines>
            )}
        </div>
    );
};