Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Underline style is removed after converting HTML to DraftJS Editor content #61

Open
vkolova opened this issue Oct 1, 2018 · 7 comments

Comments

@vkolova
Copy link

vkolova commented Oct 1, 2018

Let's say I pass this HTML:
<p><u>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</u></p>

When I convert it to DraftJS content and set it as editor state, the editor shows no trace of any underlined text. I checked if the issue is possibly with the package that I use to convert back to HTML string, but it doesn't seems like it.

Here's what I do:

`

setEditorState = (slide = this.props.editor.slide) => {
    const blocksFromHTML = htmlToDraft(slide.text.text || '');

    const state = blocksFromHTML.contentBlocks
        ? EditorState.createWithContent(
            ContentState.createFromBlockArray(
                blocksFromHTML.contentBlocks,
                blocksFromHTML.entityMap
            )
        )
        : createEditorStateWithText('');

    return state;
};

`

Am I doing something wrong, or is there a bug with the package?

@vkolova
Copy link
Author

vkolova commented Oct 8, 2018

Anyone?

@ahoys
Copy link

ahoys commented Nov 12, 2018

Hey,

I wondered the same, apparently, it is "ins" in this context, not "u". And b is strong.
It is beyond me why any of these converter libraries don't support all of the tags, even the most common ones.

@philmetzger
Copy link

philmetzger commented Dec 6, 2018

Any solution? I would like for to not be stripped away. And its definitely because of the ins/u issue as if I use <ins> then underlines are maintained

@gigiskarlett
Copy link

Same for me the package converts the ins to just a span without the underline. Any solutions?

@ForumT
Copy link

ForumT commented Jun 1, 2021

This is a pretty old issue. any update on this one ?

@Amitmath0987
Copy link

Amitmath0987 commented Dec 28, 2022

here i find the solution of this problem:-
use different converter -> import { convertFromHTML } from "draft-js instead of htmlToDraft

Example:-

let markup = "<p><u>Amit Mathur</u></p>"; const contentBlock = convertFromHTML(editorData); if (contentBlock) { const contentState = ContentState.createFromBlockArray( contentBlock.contentBlocks, contentBlock.entityMap ); setEditorState(() => EditorState.createWithContent(contentState)); }

My issue is resolved,hope your also by doing this
Thanks

@palashc2011
Copy link

@Amitmath0987 thanks.. your solution worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants