jpuri / draftjs-to-html

Library for converting Draftjs editor content state to HTML

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HTML tags stripped

svanetten1976 opened this issue · comments

Hi @jpuri first of all, thank you for all your great work on this suite of projects for the react-draft-wysiwyg editor. Everything is working great, the only problem I am running is that enclosing DIV tags are getting stripped out somewhere. Basically, I have a templating system that should include some Bootstrap classes and they are all getting stripped out (not sure if this happens in draftToHtml or htmlToDraft functions. I'm using both of these plugins to handle HTML in / HTML out. Can you tell me if there is a workaround for this? Here is some sample code (assume that the argument 'newContent' looks something like this):
const newContent = '

<iframe width="250" height="141" src="https://www.youtube.com/embed/E0tgKVOxihI" frameborder="0" allowfullscreen></iframe>
'

appendContent = (newContent) => {
const { editorState } = this.state
// const content = stateToHTML(editorState.getCurrentContent())
const content = draftToHtml(convertToRaw(editorState.getCurrentContent()))
console.log(newContent)
const newHTML = htmlToDraft(<div>${content}${newContent}</div>)
const state = ContentState.createFromBlockArray(newHTML.contentBlocks)
this.setState({
editorState: EditorState.createWithContent(state)
},
() => {
this.setState({ dialogOpen: false })
console.log(draftToHtml(convertToRaw(this.state.editorState.getCurrentContent())))
}
)
}

When I go to pull the content as HTML, all of the DIV tags are gone. Can you tell me if there is a work-around for this? Thanks, Steve

Hi @svanetten1976 , htmlToDraft can work only with html produced by react-draft-wysiwyg. I do not hope it to work with custom html mentioned above.