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);
});
};