Draft-js: Custom tags and attributes from pasted HTML

Created on 18 Jan 2017  路  2Comments  路  Source: facebook/draft-js

I can't find a way to extract custom attributes (like data-*) and tags when you paste a HTML content.

Am I missing something from the docs?

Most helpful comment

The problem happens when I use convertFromHTML and change the editorState, if I paste

<p data-something="1">Text</p>

the draft-js-export-html output will be

<p>Text</p>

I need to export to HTML because I am trying to replace a legacy editor with Draft, to maintain compatibility.

Does Draft save custom attributes and tags inside it's data structure? If yes, then this is a draft-js-export-html issue.

All 2 comments

@fmatoss you can use handlePastedText function.

handlePastedText( pastedText ) {
// pastedText is string and you can strip out from there..
}

The problem happens when I use convertFromHTML and change the editorState, if I paste

<p data-something="1">Text</p>

the draft-js-export-html output will be

<p>Text</p>

I need to export to HTML because I am trying to replace a legacy editor with Draft, to maintain compatibility.

Does Draft save custom attributes and tags inside it's data structure? If yes, then this is a draft-js-export-html issue.

Was this page helpful?
0 / 5 - 0 ratings