question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

convertFromHTML doesn't preserve <br>s inside <div>s

See original GitHub issue

Let’s say I have some text in the editor:

hello

we're separated by a line


and us by two

In the editor, when creating this text, I end up with 6 blocks, with the 2nd, 4th, and 5th having empty text.

The HTML I generate from this text looks like this (which is very similar to the HTML outputted during editing):

<div>hello</div>
<div><br></div>
<div>we're separated by a line</div>
<div><br></div>
<div><br></div>
<div>and us by two</div>

If I use convertFromHTML() on this HTML, I would expect to get 6 content blocks back. Instead, I only get 3, and all of the empty lines get collapsed. So after I load the 3 blocks, the text in the editor ends up like this:

hello
we're separated by a line
and us by two

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:7
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
benbriggscommented, Aug 3, 2016

This was discussed a bit in https://github.com/facebook/draft-js/issues/231:

This was on purpose to keep pastes of long text from having a lot of extra spaces between paragraphs. The content coming in can be pretty messy sometimes and this is one of the things we try to do to clean it up.

3reactions
Smaxor5commented, May 19, 2020

This is awful default behavior.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Empty elements removed when using convertFromHTML()
The problem is that any HTML block elements that don't have text in them don't get converted to ContentBlocks. So all of the...
Read more >
Re: convert from Div.innerhtml to image in vb.net - ASP.NET ...
Save (Server.MapPath("generated_image.jpg"), ImageFormat.Jpeg) //Response.Write("View the generated image <a target=""_blank"" ...
Read more >
Data Conversion | Draft.js
This is useful when saving an editor state for storage, conversion to other formats, or other usage within an application. convertFromHTML() #.
Read more >
Head First HTML - Index of
In other words, if you use anything in Head First HTML with CSS & XHTML ... here your brain is doing you a...
Read more >
Page 7 - Okler Themes
As you can see in our preview demo, the filter on the right sidebar are not functional. So EZY doesn't comes with a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found