Our web application allows the user to submit rich text (with some whitelisted HTML tags) to our server. The client-side form uses CKEDITOR to capture the rich text.
Once the user submits their input, I need to retrieve the rich text on a separate page for rendering. The render has to happen dynamically. On document ready, I pull the server side value, create a div element, and dump the rich text into the innerHTML attribute of the div.
i.e. :
var container = document.createElement('div');
div.innerHTML = '{!server_side_value}'; // String interpolation to retrieve the user's input
The problem that the server-side rich text is stored with newline characters. When I attempt to assign the innerHTML attribute, I get the "Unexpected token ILLEGAL" error. I cannot assign the string to innerHTML, nor can I pass it as an argument to a function that strips the new line characters using RegEx. Both attempts result in the 'Unexpected Token' error.
My question is: is it impossible to massage the rich text value in JavaScript because it has new line characters? I am working on a 3rd party platform, so the details of how user input is stored are somewhat hidden in a black box. However, I think I can add a hook to pre-process the data before save. In either case, I am just curious what to do in JavaScript if the server-side string returned with newline characters.
EDIT: Here is the highlighted line in the console. The reason why I thought it had to do with the newline was because of the space between the first 'p' tag and starting of the second. I know JavaScript multiline strings must use the + operator for concatenation. Another SO user had a similar issue: Javascript: Unexpected Token ILLEGAL Error with appendChild()
var richText = '<p class="p1"><span class="s1">Here is some text.</span></p>
<p class="p1"><span class="s1">Here is some more text</span><br><br></p>';