question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature: serialize EditorState to HTML in read-only mode

See original GitHub issue

I’m storing EditorState as the value for a RichTextInput (controlled input), and I want on form submission to:

  • ✅ generate JSON from EditorState – JSON.stringify does it
  • ❌ generate HTML from EditorState and EditorConfig (styles) – I need an editor instance

Currently, to generate HTML from Lexical, I need to use Editor. update with $generateHtmlfromNodes, which has some issues:

  • Not possible in read-only mode,
  • Generating HTML from the editor requires the caller of the method to have an Editor instance, where as an EditorState and EditorConfig should be sufficient

Pleasure to contribute code

I’m open to contributing to this project if this feature is a valid use case.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:9
  • Comments:19 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
trueadmcommented, Sep 14, 2022

That’s a neat trick too!

1reaction
norregaarden-scalgocommented, Jul 26, 2022

@norregaarden-scalgo I’m waiting for a confirmation from @trueadm to start on my proposition.

For your case, using LexicalOnChangePlugin with a debounced onChange callback will be sufficient.

@med8bra thanks you for your suggestion, but the same error pertains using OnChangePlugin from @lexical/react/LexicalOnChangePlugin, i.e. $generateHtmlFromNodes can only be called from editor.read or editor.update, and if I wrap it in that, it says " Cannot use method in read-only mode." even when I’m, not in read-only mode, if the editor has been in read-only mode at some point.

Read more comments on GitHub >

github_iconTop Results From Across the Web

With Lexical, how do I set default initial text? - Stack Overflow
You can set default text by setting editorState to either a stringified JSON state, or a function that imperatively ...
Read more >
Reference manual - ProseMirror
ProseMirror keeps all editor state (the things, basically, that would be required ... If you want to serialize the state of plugins, pass...
Read more >
Reference Manual - CodeMirror
In its most basic form, an editor's state is made up of a current document and a selection. ... A function used to...
Read more >
Top 5 rich-text React components | Sanity.io guide
Requires a parser to convert EditorState to HTML or any other markup. ... React-Quill also features an uncontrolled mode that uses ...
Read more >
blob - Google Git
computeN(deps: readonly Slot<any>[], get: (state: EditorState) => readonly Input[]): ... A function used to serialize this field's content to JSON. Only.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found