View Full Version : unterminated string literal from Paste

06-30-2011, 09:44 PM

I created a simple WYSIWYG for creating CSS based webpages. It works exactly as assumed in Safari and Chrome. However, in firefox, when you copy/paste more than one line of text, instead of formatting it as html, in puts in line breaks causing the array storing all of the data to break into multiple lines and causing an unterminated string literal.

Can anyone,
1. suggest why it is behaving this way?
2. suggest a work around to allow it to work on FF?

06-30-2011, 11:47 PM
I had a similar issue previously and, as I recall, I used a regular expression to replace line breaks '\n' with either HTML '<br>' tags or '' to remove them. I think I had to double escape the line breaks as well '\\n' or even '\\\\n' :thumbsup:

I've lost track of my code though, unfortunately, but I think you'll need to post some of your own code anyway.

Added: Here's an example:

someText = someText.replace(/(\r\n|\n|\r)/gm,"");
The 'm' is required for a multi-line replace.

07-01-2011, 12:19 AM
You only need the multiline flag if you anchor your search pattern to the beginning or end of the string (or each line, in multiline).

someinnerHTML+= text.replace(/\s*\n+$/gm,'<br>');

You can safely remove any whitespace preceding a new line.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum