React-draft-wysiwyg: Text color is lost after converting raw content / HTML back to EditorState

Created on 8 May 2017  路  6Comments  路  Source: jpuri/react-draft-wysiwyg

I typed "this is very interesting thing" and make the text green color in Editor and then saved the following raw content using convertToRaw: JSFiddle: https://jsfiddle.net/wc4cxnvx/

{
    entityMap:{},
    blocks:[{"key":"5bbf7","text":"this is very interesting thing",
"type":"unstyled",
"depth":0,
"inlineStyleRanges":[{"offset":0,"length":30,"style":"color-rgb(26,188,156)"}],
"entityRanges":[],
"data":{}}]
    }

Its translated Html using draftjs-to-html:
<p><span style=\"color: rgb(26,188,156);\">this is very interesting thing</span></p>

I tried to restore editor state using both raw content and HTML, neither shows text color in editor. For each case, only plain "this is very interesting thing" without green color was shown.

The code I was using to restore to editorstate:

1) From raw:
editorState = EditorState.createWithContent(convertFromRaw(raw));

2) From Html:

     let htmlContent = convertFromHTML(html);
     let editorState = EditorState.createWithContent(ContentState.createFromBlockArray(htmlContent.contentBlocks, htmlContent.entityMap));

Is this a bug??

Most helpful comment

not working for me too. Currently using version 1.12.13

All 6 comments

This issue is gone after upgrading to latest 1.9.8 version.

I have also crashed on this problem, may I ask your solution to fix it? Now I'm using 1.10.0 @jasonfoy99

The issue was fixed for me when using 1.9.8 version. Not sure of 1.10.0.

+1 on this issue. When changing color from the editor, the change is immediately visible. However, after restoring state from the saved html output, the color is lost. Currently using version 1.12.13

it will be lost ,when i use convertFromHTML,but it ok on convertFromRaw.

not working for me too. Currently using version 1.12.13

Was this page helpful?
0 / 5 - 0 ratings