Rosey/markdown-draft-js

Blank line between paragraphs is not preserved when preserveNewlines: true enabled

Opened this issue · 4 comments

This results in multiple paragraphs in draft being combined into a single paragraph with a BR inside.

Opened a PR that shows this failing test #143

Currently dealing with the same issue. Did you find any solution?

@supasus our workaround was to remove preserveNewlines: true - perhaps that will work in your case?

@alibosworth Thanks, that did the trick. If anyone ever stumbles onto this: I was trying to differentiate between a soft newline break and a paragraph break. Doing this

     if(e.shiftKey) {
                    const newEditorState = RichUtils.insertSoftNewline(this.state.editorState);
                    if (newEditorState !== this.state.editorState) {
                        this.onChange(newEditorState);
                    }
                } else {
                    const editorState = this.state.editorState;
                    const currentContent = editorState.getCurrentContent();
                    const selection = editorState.getSelection();
                    const textWithEntity = Modifier.splitBlock(currentContent, selection);

                    this.setState({
                        editorState: EditorState.push(editorState, textWithEntity, "split-block")
                    });
                }

And setting the data-blocks margin was the solution.

@supasus interesting, is this general enough that it would be a good improvement to the library? If so I'm sure @Rosey would appreciate a pull-request!