jpuri / jpuri/html-to-draftjs

image position is lost when converting from html to EditorState

Open
#101 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
163
Forks
104
PR merge metrics
No merged PRs in 30d

Description

when saving the image in react-draft-wysiwyg I get the following output as html:

<div style="text-align:right;"><img src="srcHere" alt="" style="height: auto;width: auto"/></div>

after converting this back to the EditorState and logging out html again I receive:

<p style="text-align:right;"></p> <img src="srcHere" alt="" style="height: auto;width: auto"/>

The image position is lost and wrapping div is converted into adjacent empty p element with same styling as div.

the code that converts the html back to EditorState:

  ...
  const contentBlock = htmlToDraft(fieldHtml);
  
  const contentState = ContentState.createFromBlockArray(contentBlock.contentBlocks);

  return EditorState.createWithContent(contentState);

I imagine this might be similar if not the same issue as #98

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the htmlToDraft conversion path shown in the report and reproduce it using the supplied div and image HTML. Inspect how the conversion handles a styled div containing an image, then verify that converting to ContentState and back preserves the image alignment without creating an empty adjacent paragraph.

Written by the indexing model from the issue text.

Assessment

Tech stack
html, javascript, react
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.