sstur / draft-js-export-markdown

DraftJS: Export ContentState to Markdown
http://npm.im/draft-js-export-markdown
55 stars 23 forks source link

Extra spacing on line break #4

Closed jxodwyer closed 8 years ago

jxodwyer commented 8 years ago

When hitting enter for a new line it seems like an extra line is appended to the output from the stateToMarkdown module. Below is a screenshot consoling out stateToMarkdown(editorState.getCurrentContent()). As you can see in the console there is an added space between each of the breaks which is not seen in the draft.js editor itself. @sstur feel free to hit me back on slack. Like I mentioned I'd be happy to work through this with you and help out as much as possible.

screen shot 2016-04-19 at 10 44 23 am
sstur commented 8 years ago

Hi @jxodwyer. I don't think this is a bug. Whenever you press enter in Draft you create a new block (even though the blocks in your case have no margin so it looks like a single block with multiple lines). The closest equivalent to a plain-text block in Markdown is a paragraph. Paragraphs in Markdown should have two linebreaks between them. A single linebreak would cause a markdown parser will swallow the linebreak completely.

This behavior is by design, it's not a bug.

So, if I understand your problem correctly, you want to condense consecutive unstyled blocks into a single block with soft-breaks. I'd suggest doing this as a pre-process step before converting to Markdown.