I'm using Facebook's draft-js
to create a WYSIWYG. I'm trying to convert HTML to editorState using the native convertFromHtml
. But it's not recognizing the img
tag.
import draftJs from 'draft-js'
const blocksFromHTML = convertFromHTML("<img src='some/img.png' />", draftJs.getSafeBodyFromHTML, draftJs.DefaultDraftBlockRenderMap);
const contentState = draftJs.ContentState.createFromBlockArray(blocksFromHTML);
editorState = draftJs.EditorState.createWithContent(contentState);
Doing so completely removes the image. Any ideas?
Example of using convertFromHTML in draft-js 0.10.0 should work (the code was a bit simplified by me):
const sampleMarkup = '<img src="image.png" />';
const blocksFromHTML = convertFromHTML(sampleMarkup);
const state = ContentState.createFromBlockArray(
blocksFromHTML.contentBlocks,
blocksFromHTML.entityMap,
);
this.state = {
editorState: EditorState.createWithContent(state),
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With