Skip to content

How to convert the output of editorState to plain text? #1934

Answered by thegreatercurve
charklewis asked this question in Q&A
Discussion options

You must be logged in to vote

I think getTextContent on the root node should produce what you need i.e.:

import {
  $getRoot,
} from 'lexical';

// ... 

const stringifiedEditorState = JSON.stringify(
  editor.getEditorState().toJSON(),
);
const parsedEditorState = editor.parseEditorState(stringifiedEditorState);

const editorStateTextString = parsedEditorState.read(() => $getRoot().getTextContent())

Replies: 5 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@charklewis
Comment options

Answer selected by charklewis
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@laulautrup
Comment options

Comment options

You must be logged in to vote
2 replies
@jackple
Comment options

@jackple
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
7 participants