Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2011
    Thanked 0 Times in 0 Posts

    unterminated string literal from Paste


    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?

  • #2
    Senior Coder
    Join Date
    Apr 2011
    London, England
    Thanked 354 Times in 353 Posts
    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'

    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.
    Last edited by AndrewGSW; 06-30-2011 at 11:52 PM.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • Users who have thanked AndrewGSW for this post:

    itsafluke (07-04-2011)

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Thanked 132 Times in 123 Posts
    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.

  • Users who have thanked mrhoo for this post:

    itsafluke (07-04-2011)


    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts