我正在研究 React-draft.js 编辑器,我能够以纯字符串的形式获取编辑器状态。如何从编辑器状态获取格式化文本以便以 pdf 和 doc 的形式存储
class Textedit extends React.Component{
constructor(props){
super(props)
this.state={
editorState: EditorState.createEmpty(),
}
}
onEditorStateChange=(editorState)=>{
this.setState({editorState})
}
onhandleSubmit=()=>{
const blocks = convertToRaw(this.state.editorState.getCurrentContent()).blocks;
const value = blocks.map(block => (!block.text.trim() && '\n') || block.text).join('\n');
}
<Editor
editorState={editorState}
toolbarClassName="toolbarClassName"
wrapperClassName="wrapperClassName"
editorClassName="editorClassName"
onEditorStateChange={this.onEditorStateChange}
/>
<button onClick={this.onhandleSubmit}>Submit</button>
任何帮助或建议将不胜感激,如果有任何其他方法可以达到同样的效果,也请提出建议。