6

I am new on Draft-JS and able to create a decent enough text editor for my consumption, But I need to add a UL list with LI items at the bottom of my Textarea by coding.

I have tried using Import HTML and then adding my HTML into it and then Exporting it back to the editor state, But Undo and Redo are not working like this. I may sound strange but your help will be highly appreciated as I am unable to find good resources of Draft-JS

My Code for adding html which I am currently using is:

  let currentHTML = stateToHTML(this.state.editorState.getCurrentContent());
  currentHTML =   currentHTML + "<li>" + value +"</li>"
  let contentState = stateFromHTML(currentHTML);
  this.setState({editorState : editorState.createWithContent(contentState)});

In the above code I am taking html from the editor state and then append the desired html string and regenerate the content state from html and edit the editor state. Thank You..

Rahul
  • 1,070
  • 3
  • 21
  • 47
  • Please include a runnable snippet of what you were trying (share with http://jsbin.com for example) so that the community could see what you did and suggest how you might go differently. – Gosha A Jun 27 '16 at 13:05
  • @GoshaArinich I guess now I am a bit more clear, its a simple problem of inserting some HTML in the Draft js text editor. – Rahul Jun 28 '16 at 07:05
  • draftjs use it's own model. you need compose the draftjs model. inserting html to draft is not easy. – Jiang YD Aug 02 '16 at 01:38

0 Answers0