从 DraftJS 中的粘贴文本中删除所有样式?

Strip all styling from pasted text in DraftJS?

当将文本从 word 或其他来源粘贴到 draftjs 时,格式随之而来,我尝试像这样剥离样式数据:

onChange={(newEditorState) => {
                        const raw = convertToRaw(newEditorState.getCurrentContent())
                        for (let i = 0; i < raw.blocks.length; i++){
                            raw.blocks[i].type = "unstyled"
                        }
                        let newContent = convertFromRaw(raw)
                        newEditorState
                        const newState = EditorState.push(state, newContent, "change-block-type")

                        setState(newState)
                    }} />

除了打字最终在输入时被颠倒之外,这很有效,这非常令人困惑。

您要找的似乎是 stripPastedStyles option:

Set whether to remove all information except plaintext from pasted content.

This should be used if your editor does not support rich styles.

Default is false.