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 6989033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:09:35+00:00 2026-05-27T19:09:35+00:00

I’m trying to have greentext support for my Rails imageboard (though it should be

  • 0

I’m trying to have greentext support for my Rails imageboard (though it should be mentioned that this is strictly a Ruby problem, not a Rails problem)

basically, what my code does is:
1. chop up a post, line by line
2. look at the first character of each line. if it’s a “>”, start the greentexting
3. at the end of the line, close the greentexting
4. piece the lines back together

My code looks like this:

def filter_comment(c) #use for both OP's and comments

c1 = c.content

str1 = '<p class = "unkfunc">' #open greentext
str2 = '</p>' #close greentext

if c1 != nil
arr_lines = c1.split('\n') #split the text into lines

arr_lines.each do |a|
  if a[0] == ">"
    a.insert(0, str1) #add the greentext tag
    a << str2 #close the greentext tag

  end
end

c1 = ""

arr_lines.each do |a|
  strtmp = '\n'
  if arr_lines.index(a) == (arr_lines.size - 1) #recombine the lines into text
    strtmp = ""
  end
  c1 += a + strtmp
end


c2 = c1.gsub("\n", '<br/>').html_safe

end

But for some reason, it isn’t working! I’m having weird things where greentexting only works on the first line, and if you have greentext on the first line, normal text doesn’t work on the second line!

  • 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-27T19:09:35+00:00Added an answer on May 27, 2026 at 7:09 pm

    I think the problem lies with the spliting the lines in array.

       names = "Alice \n Bob \n Eve"
       names_a = names.split('\n')
       => ["Alice \n Bob \n Eve"]
    

    Note the the string was not splited when \n was encountered.

    Now lets try this

      names = "Alice \n Bob \n Eve"
      names_a = names.split(/\n/)
      => ["Alice ", " Bob ", " Eve"]
    

    or This “\n” in double quotes. (thanks to Eric’s Comment)

      names = "Alice \n Bob \n Eve"
      names_a = names.split("\n")
      => ["Alice ", " Bob ", " Eve"]
    

    This got split in array. now you can check and append the data you want

    May be this is what you want.

    def filter_comment(c) #use for both OP's and comments
    
    c1 = c.content
    
    str1 = '<p class = "unkfunc">' #open greentext
    str2 = '</p>' #close greentext
    
    if c1 != nil
    arr_lines = c1.split(/\n/) #split the text into lines
    
    arr_lines.each do |a|
      if a[0] == ">"
        a.insert(0, str1) #add the greentext tag 
         # Use a.insert id you want the existing ">" appended to it <p class = "unkfunc">>
         # Or else just assign a[0] = str1 
        a << str2 #close the greentext tag
    
      end
    end
    
    c1 = arr_lines.join('<br/>')
    c2 = c1.html_safe  
    
    end
    

    Hope this helps..!!

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is

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.