有没有办法将词法编辑器内容转换为原始 HTML?

问题描述 投票:0回答:0

当我意识到我无法将一些词汇内容存储为没有默认词汇类的纯 HTML 标签时,我几乎完成了 Lexical 的工作。 例如: Editor content 存储为:

<strong class="editor-text-bold editor-text-italic" data-lexical-text="true">Hi there</strong>

代替

<strong><i>Hi there</i></strong>

有没有办法将数据存储为纯 HTML,以便我可以直接加载任何 HTML 作为富文本?

我目前用来从 Lexical 生成 HTML 的代码:

const [editor] = useLexicalComposerContext();
const handleClick = (editor) => {
  editor.update(() => {
    const htmlString = $generateHtmlFromNodes(editor, null);
    const html = DOMPurify.sanitize(htmlString, {
      FORBID_ATTR: ["class", "dir"],
    });
    console.log(html);
    setPreview(html);
  });
};
html reactjs rich-text-editor lexicaljs
© www.soinside.com 2019 - 2024. All rights reserved.