I am using a lexical editor and want to convert lexical data to HTML on click of a button.
After referring from this question, I am using $generateHtmlFromNodes and wrapping it inside editor.update function.
My code:
import { $generateHtmlFromNodes } from '@lexical/html';
document.getElementById("export-html").addEventListener("click", () => {
editor.update(() => {
const htmlString = $generateHtmlFromNodes(editor, null);
console.log('htmlString', htmlString);
});
})
The output I am receiving: enter image description here
Expecting a proper HTML output in string format. I checked Serialization as well.