question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The convertFromHTML() method currently strips inline style attribute from HTML string.

See original GitHub issue

Do you want to request a feature or report a bug? Report a bug.

What is the current behavior? The convertFromHTML() method strips inline style attribute from HTML strings.

When importing this HTML string (via convertFromHTML()): "<p>This is some <span style="color: #f0ad4e">colorful</span> text.</p>"

The line is converted to this: "<p>This is some colorful text.</p>"

What is the expected behavior? Keep inline style attribute when using convertFromHTML()

Which versions of Draft.js, and which browser / OS are affected by this issue? Did this work in previous versions of Draft.js? Draft JS v0.8.1 running in Chrome

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:29 (2 by maintainers)

github_iconTop GitHub Comments

56reactions
AkyunaAkishcommented, Jul 31, 2019

This code worked for me(particularly lines 12-16) when I wanted to convert HTML as a string to draftjs data and load it in the editor’s state without stripping the HTML attributes:

import htmlToDraft from 'html-to-draftjs';
const contentBlock = htmlToDraft(htmlString);
const contentState = ContentState.createFromBlockArray(contentBlock.contentBlocks);
const editorState = EditorState.createWithContent(contentState);

https://github.com/jpuri/react-draft-wysiwyg/blob/master/stories/ConvertFromHTML/index.js

39reactions
kumarabhirupcommented, Mar 15, 2019

every damn thing in universe is unclear

Read more comments on GitHub >

github_iconTop Results From Across the Web

Recently Active 'draftjs' Questions - Stack Overflow
Draft.js convertFromHtml, htmlToDraft and stateFromHTML ignores style attribute. I want to initialize a Draft.js text editor with the initial state.
Read more >
How can I use iText to convert HTML with images and ...
I'm using Asp.mvc 5. Just one method of the ImageProviderClass has to be changed. public virtual string GetImageRootPath() { return null; }. to...
Read more >
draft-js | Yarn - Package Manager
convertFromHTML breaks after converting \n string, issue #1822 (#1823) ... into inline style to resolve insertion issues; handleDrop prop method for Editor ...
Read more >
HTML.c - LYNX
$LynxId: HTML.c,v 1.192 2018/04/01 23:26:24 tom Exp ... else { /* * Just put in the ALT or pseudo-ALT string for the current...
Read more >
AppleScript to create thumbnail of select… - Apple Community
You now select the files to process in the Finder, and then run the script. All comments are gone from the HTML and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found