-
Notifications
You must be signed in to change notification settings - Fork 2.6k
convertFromHTML
merged <p> tags into one <p> tag
#523
Comments
What do you mean, "when I save data"? |
@spicyj, sorry for my uncleared explanation. here is an example, Basically the result that I've got from I expected to get 3 ContentBlock objects as there are 3 paragraphs. |
Thanks, I can repro this. |
@spicyj I can take a look at this this week if no one else is. |
@CLowbrow Go for it. |
Is there currently a workaround for this? |
Workaround: convertFromHTML takes as its optional third argument a "block render map" -- I believe if you specify a map that includes the |
Thanks @spicyj |
I tried applying the workaround but without success. Did you figure out a solution @abhoopathy ?
Thanks! Edit: I ended up storing my input content as draftjs |
Same here, couldn't get that render map to work correctly. tags just kept getting combined. My workaround was to replace 'p' tags with 'div' tags in my HTML. Obviously this workaround only works if you have access to the input HTML. |
OK. Seems @jbrozena22 I tried same approach, but it only worked in case all blocks were My 'workaround' was to replace all |
@N1kto this workaround works but has a severe drawback: deleting there's a function called |
@NdYAG well, haven't even noticed that drawback to be honest. Comparing to initial problem that's a minor issue, at least for me.
However don't know what would be other consequences of doing that - it has been added there for some reason. Also it might be overwritten by default |
This worked for me: import {
DefaultDraftBlockRenderMap,
ContentState,
convertFromHTML,
getSafeBodyFromHTML
} from 'draft-js';
const blockRenderMap = DefaultDraftBlockRenderMap.set('p', { element: 'p' });
const blocksFromHTML = convertFromHTML(html, getSafeBodyFromHTML, blockRenderMap)
.map(block => (block.get('type') === 'p' ? block.set('type', 'unstyled') : block));
const contentState = ContentState.createFromBlockArray(blocksFromHTML); edited to show imports |
@davidchang you've closed both this task and #757 (where you said you were closing that one in favor of this one) and there is no consolidated task created (at least not referenced). Is it intentional? |
This issue is still open. |
@spicyj @davidchang I am sorry, must have overlooked. |
@tomconroy Can you tell me please what getSafeBodyFromHTML looks like? Without that, browser shows an error |
@ZeroCho Maybe you can use a jsdom to do this behavior on the server. Like this:
|
@tomconroy @landrade |
I just realised this is particularly problematic when copy-pasting Draft.js images from one editor to another. If the Edit: this also happens for other empty tags, not just Here's an example from my demo site: In that example, the content changes from |
Here is another illustration from Facebook Notes: If there was a viable workaround for this, out of all place I imagine it would have one. |
I'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.
However, when I save data and refresh the page, it displays as below (all in one line)
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.
The text was updated successfully, but these errors were encountered: