Export DraftPasteProcessor, or better access to its methods
See original GitHub issueFor use cases in which I have fragments of pre-existing HTML that I need to load into an editor as the initial content, my impression is that I’d need to make use of the built-in DraftPasteProcessor
that is part of the paste handling.
Something like this is working for me:
import Draft from 'draft-js';
const {Editor, EditorState, RichUtils, ContentState} = Draft;
import DraftPasteProcessor from 'draft-js/lib/DraftPasteProcessor';
const htmlFragment = '<div><p>Hello <b>world!</b></p><ul><li>again</li></ul></div>';
class RichEditorExample extends React.Component {
constructor(props) {
super(props);
const processedHTML = DraftPasteProcessor.processHTML(htmlFragment);
const initialState = ContentState.createFromBlockArray(processedHTML);
this.state = {editorState: EditorState.createWithContent(initialState)};
But it would appear that DraftPasteProcessor
isn’t exported along with the built package, so the import syntax is less than ideal, and I cannot use it if including only the dist file on the front-end.
Is there a better method for loading pre-existing HTML content, or could the paste-cleaning tools be included as part of the exported dist?
Issue Analytics
- State:
- Created 8 years ago
- Comments:17 (6 by maintainers)
Top Results From Across the Web
draftjs how to initiate an editor with content - Stack Overflow
The first argument to EditorState.createWithContent is a ContentState , not a string. You need to import ContentState
Read more >Articy Help Center - Export to .xlsx for Re-Import
The import of data from Microsoft® Excel® into articy:draft requires a specific format of the .xlsx-sheet. So, make sure to use the new...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @hobenkr88 , I have done it in this way while saving data in database I converted it to RAW as this
For Editing content you can initialize editor with content as below code
this.setState({editorState:EditorState.createWithContent(convertFromRaw(JSON.parse(content)))})
For displaying data on html web page you can convert it to html as below code
<p dangerouslySetInnerHTML={{__html: stateToHTML(convertFromRaw(JSON.parse(content)))}}>
You need to import stateToHTML from plugin draft-js-export-html
Please let me know if this answers to your query or you can chat with me on akshay.goyal1008@gmail.com
There is now a convertFromHtml method so initializing with default html could be done like: