draft-js-export-markdown icon indicating copy to clipboard operation
draft-js-export-markdown copied to clipboard

Insert breaks every time

Open romanlex opened this issue 8 years ago • 1 comments

Hello, when I trying get markdown from onChange event by Editor I has double breaks in text. I want save markdown to another key in my state and save its to database. What I doing wrong?

<div className={`editor ${this.state.hasFocus ? 'hasFocus' : ''}`}
     onClick={() => { this.editor.focus() }} >
	<Editor
		onFocus={() => this.setState({hasFocus: true})}
		onBlur={e => this.validationDescriptionCheck(e)}
		editorState={this.state.editorState}
		onChange={this.onChange}
		plugins={plugins}
		ref={(element) => { this.editor = element; }}
	/>
	<EmojiSuggestions/>
	<InlineToolbar/>
	{this.state._description === false ?
		<div className="invalid-feedback">{this.state._descriptionMsg}</div> : null}
</div>
	onChange = (editorState) => {
		const markdown = stateToMarkdown(editorState.getCurrentContent());
		this.setState({
			editorState,
			formData: {
				...this.state.formData,
				description: markdown
			}
		});
	};

And my submitHandler:

submitHandler(e) {
	e.preventDefault();
	const { actions } = this.props;
	
	if(this.validate()) {
		let data = this.state.formData;

		let service = new Service(data);

		//TODO удалить
		if(!service.createdAt || service.createdAt === null)
			service.createdAt = moment().format('YYYY-MM-DD HH:mm');
		
		if(this.state.edit === true)
			actions.updateServiceAction(service);
		else
			actions.addServiceAction(service);
	} else {
		actions.error("Данные заполнены не корректно или неполностью");
	}
}

When I call submitHandler I has multiple line-breaks in my string and next save form added another breaks example first save image next save image

If I save in my formData plaintext(not markdown) all works properly

romanlex avatar Aug 25 '17 15:08 romanlex

I fix it with draft-js-import-markdown package and fix my componentWillReceiveProps method. close pls

romanlex avatar Aug 25 '17 16:08 romanlex