`convertFromHTML` merged <p> tags into one <p> tag
See original GitHub issueI’m having some problems with the convertFromHTML
, it doesn’t render the right data as I expected.
For example,
html: <p>Paragraph 1</p>, <p>Paragraph 2</p>, <p>Paragraph 3</p>
editorState:
EditorState.createWithContent(ContentState.createFromBlockArray(convertFromHTML(_html_)), Decorator)
The html at this stage render correctly as expected.
Paragraph 1 Paragraph 2 Paragraph 3
However, when I save data and refresh the page, it displays as below (all in one line)
Paragraph 1 Paragraph 2 Paragraph 3
Then, I clicked on the editor and suddenly the html turned into
<p>Paragraph 1 Paragraph 2 Paragraph 3</p>
Does anyone has similar problem like this? Thanks.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:7
- Comments:22 (8 by maintainers)
Top Results From Across the Web
Developers - `convertFromHTML` merged <p> tags into one <p> tag -
`convertFromHTML` merged <p> tags into one <p> tag ... I'm having some problems with the convertFromHTML , it doesn't render the right data...
Read more >How to solve Draft.js convertFromHTML combining adjacent ...
I solved this by adding a custom DraftBlockRenderMap element for paragraph <p> tags for convertFromHTML because the default one doesn't ...
Read more >Custom Block Rendering - Draft.js
This article discusses how to customize Draft default block rendering. ... type by matching the Draft block render map with the matched tag....
Read more >Convert from HTML - Draft.js example - CodePen
1. <!--. 2. Source of the code: https://github.com/facebook/draft-js/tree/master/examples/draft-0-10-0/convertFromHTML. 3. -->. 4. <!DOCTYPE html>.
Read more >DraftJs : Custom button to add custom HTML + CSS
first, create a map of types by merging the default supported tags with the button tag import { ... DefaultDraftBlockRenderMap, .
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This worked for me:
edited to show imports
OK. Seems
<p>
tags wont work in DraftJS. Maybe I was doing smth wrong, but it looks DraftJS wraps any text contents intodiv -> span
and then wraps this into whateverelement
you provide in yourblockRenderMap
. Since<p>
element supports onlyPhrasing content
children it throwsviolation
error since<div>
cannot be a child of<p>
.@jbrozena22 I tried same approach, but it only worked in case all blocks were
<p />
. If there was at least some known block right after<p />
, say<h2 />
it combined all<p />
's into one<div />
with text being concatenated. My use case was copy/pasting content from other editor (Medium).My ‘workaround’ was to replace all
<p>
tags with<section>
ones (since I have access to input HTML string). And then addsection
toblockRenderMap