Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6677265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:05:50+00:00 2026-05-26T04:05:50+00:00

I’m using the following javascript: if (theSelection) { for (var i = 0, l

  • 0

I’m using the following javascript:

   if (theSelection)
   {
      for (var i = 0, l = theSelection.length; i < l; i++)
      {
         if (theSelection[i] == '[' && theSelection[i+1] == 'q') level++; 
         if (theSelection[i-6] == 'q' && theSelection[i-7] == '/' && theSelection[i-8] == '[') level--;
         if (level<1) tmp.push(theSelection[i]);
      }
      theSelection = tmp.join('');
   }

… to remove nested quotes from text before it is sent to a reply box, but it leaves behind line breaks in place of the purged nested quotes. So, for instance, if I quote a post from User 1 which says…

Text.

[quote="User 2"]Quote text.[/quote]

More text.

It shows up in the reply box as…

[quote="User 1"]Text.



More text.[/quote]

What would I add to this javascript to either remove this space or limit the space between new lines to just two line breaks, so that the final text displayed in the reply box appears as:

[quote="User 1"]Text.

More text.[/quote]

Thanks for any help.

EDIT:

Here’s a larger bit of the code:

if (theSelection)
{
    for (var i = 0, l = theSelection.length; i < l; i++)
    {
        if (theSelection[i] == '[' && theSelection[i+1] == 'q') level++; 
        if (theSelection[i-6] == 'q' && theSelection[i-7] == '/' && theSelection[i-8] == '[') level--;
        if (level<1) tmp.push(theSelection[i]);
    }
    theSelection = tmp.join('');
}

if (theSelection)
{
    if (bbcodeEnabled)
    {
        insert_text('[quote="' + username + '"]' + '\n' + '\n' + theSelection + '[/quote]' + '\n' + '\n');
    }
        else
        {
            insert_text(username + ' ' + l_wrote + ':' + '\n');
            var lines = split_lines(theSelection);
            for (i = 0; i < lines.length; i++)
            {
                insert_text('> ' + lines[i] + '\n');
            }
        }
}

I placed…

if (theSelection)
{
    theSelection = theSelection.replace(/\n{2,}/g, "\n\n");
}

… between the two existing “if (theSelection)” statements, and it worked great. One remaining issue though. The nested quote removal happens before the quoted text is placed within its own quote tags, and two line breaks are added after the opening quote tag. So if a quoted post contained a nested quote before any original text, then the text that the above code generates has four line breaks at the opening instead of the intended two. So I think I would need to place…

if (theSelection)
{
    theSelection = theSelection.replace(/\n{2,}/g, "\n\n");
}

… after theSelection is inserted within its own quote tags, at which point “if (theSelection)” seems to no longer work, and I’m so new to javascript that I don’t know how to replace “theSelection” with something that will reflect the output of the previous “if (theSelection)” statement. I hope that made at least a little sense.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:05:51+00:00Added an answer on May 26, 2026 at 4:05 am

    Use a RegExp. The following code will replace 2+ new lines by two newlines.

    string = string.replace(/\n{2,}/g, "\n\n")
    

    I recommend to show a sign that notifies the reader of the fact that a quote has disappeared. Consider the following:

    Post 50 by userA: My fish died =(
    ============================
    Post 51 by userB:

    [quote=Niceidea]
    (2 pages ago) What about blabla. …
    [/quote]

    Awesome!

    ============================

    After applying your code:

    ============================
    Post 50 by userA: My fish died =(
    ============================
    Post 51 by userB: Awesome!

    ============================

    The previous poster might be offended, because he didn’t know the context of the reply.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
I'm making a simple page using Google Maps API 3. My first. One marker
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.