I want to generate HTML format from editorState in Lexical Rich Editor, I'm able to get selection with editorState and what will be best to save into database, HTML or some sort of JSON format?
and I want to show this HTML outside of editor. here is some example of code
const onChange = (editorState) => {
const editorStateTextString = editorState.read(() => {
const selection = $getSelection();
console.log(selection);
return $getRoot().getTextContent();
});
// TODO: saving text only at the moment
if (changeHandler) {
changeHandler(editorStateTextString);
}
};
<LexicalComposer initialConfig={editorConfig}>
<div className="editor-container">
<ToolbarPlugin aditionalTools={aditionalTools} />
<div className="editor-inner">
<RichTextPlugin
contentEditable={<ContentEditable className="editor-input" />}
placeholder={<Placeholder placeholder={placeholder} />}
/>
<OnChangePlugin ignoreInitialChange onChange={onChange} />
</div>
</div>
</LexicalComposer>