jpuri / html-to-draftjs

MIT License
158 stars 104 forks source link

HTML tags stripped #24

Open svanetten1976 opened 7 years ago

svanetten1976 commented 7 years ago

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 = '

'

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

jpuri commented 7 years ago

Hi @svanetten1976:

Glad that you liked it :)

This lib can only handle html as its generated by react-draft-wysiwyg. Thus you can experience trouble with html which is not generated by the editor.

May be you can try to add div tags outside the editor to add additional classes to it. (I hope I understood your requirement correctly.)

ahoys commented 5 years ago

Non-html tags are also stripped. For example you could have an email message containing lines like: "CC: <my.email@gmail.com>", which ends up being "CC: ". For example Outlook does CCs like this.

So, for handling email html-to-draftjs is not fully suitable at its current state.

Huespal commented 5 years ago

But could be cool to allow an options parameter to htmlToDraft, with current supported types. To allow more than p, h1, h2, etc. For example script.

Like this: -> https://github.com/jpuri/react-draft-wysiwyg/issues/772#issuecomment-460251352

Thanks.