Search code examples
javascriptsummernote

Pre-fill Summernote with content string Javascript


I have a Summernote WYSIWYG where content has to be pre-filled with content from a string that was already extracted from another Summernote instance.

$("#summernote").summernote("code", 'This is thing's content from anither instance');

The problem occurs when there are quotation characters in the string which will break the scope of the string prematurely (the ' in the word thing's).

Is there another way in which I can do this?

The only other way that has come to my mind is by removing ' characters before setting it to the function that loads the text to the editor.


Solution

  • Escape troublesome characters with '\' like:

    $("#summernote").summernote("code", "This is thing\'s content from anither instance");
    

    Or if it's prefilled parse it with str_replace:

    $("#summernote").summernote("code", str_replace("'", "\\'", str));