我正在使用Facebook的draft-js创建一个WYSIWYG.我正在尝试使用本机convertFrom
Html将HTML转换为editorState.但它没有识别img标签.
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);
这样做会完全删除图像.有任何想法吗?
解决方法
Example of using convertFromHTML in draft-js 0.10.0应该工作(我的代码有点简化):
const sampleMarkup = '<img src="image.png" />'; const blocksFromHTML = convertFromHTML(sampleMarkup); const state = ContentState.createFromBlockArray( blocksFromHTML.contentBlocks,blocksFromHTML.entityMap,); this.state = { editorState: EditorState.createWithContent(state),};