0

I was almost done working with Lexical when I realized I can't store some lexical content as pure HTML tags without the default lexical classes. For example: Editor content is stored as:

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

instead of

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

Is there any way to store the data as pure HTML so that I can directly load any HTML as rich text?

Code that I am currently using to generate HTML from Lexical:

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);
  });
};
Ahmed Sbai
  • 10,695
  • 9
  • 19
  • 38
  • isn't that what themes are for? https://lexical.dev/docs/getting-started/theming – kabukiman Mar 23 '23 at 11:11
  • I'm not sure I understand your question. There's an "Export HTML" button on the playground and it shows the relevant HTML so it should be quite easy: https://playground.lexical.dev/ – Slbox Apr 20 '23 at 21:20
  • I have the same question, have you found a solution by now? – nerdess Aug 15 '23 at 11:35

0 Answers0