Forum: Ruby-Forum.com formatting in ruby

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3548d30217e9921c410db19ce8ce38d0?d=identicon&s=25 Sunny Bogawat (sunny_bogawat)
on 2008-06-04 09:41
Hi,
  I am changed simple format method and added first line code for
replacing spaces
 for formatting  in this it works but other code means new line
paragraphs are not working?
   I want a such method which format all white spaces, new line,
paragraphs.
   how it possible in ruby?

example:

def my_format(text)
    text.gsub!(/(' ')/, " ")
    text.gsub!(/(\r\n|\n|\r)/, "\n") # lets make them newlines
crossplatform
    text.gsub!(/\n\n+/, "\n\n") # zap dupes
    text.gsub!(/\n\n/, '</p>\0<p>') # turn two newlines into paragraph
    text.gsub!(/([^\n])(\n)([^\n])/, '\1\2<br />\3') # turn single
newline into
    content_tag("p", text)
  end
F2f799fba0d5fed49c61e25ac3cdea26?d=identicon&s=25 Ritwik Banerjee (chronos)
on 2008-08-25 08:13
You haven't what your target format is. What do you want to replace all
the white space with?

Sunny Bogawat wrote:
> Hi,
>   I am changed simple format method and added first line code for
> replacing spaces
>  for formatting  in this it works but other code means new line
> paragraphs are not working?
>    I want a such method which format all white spaces, new line,
> paragraphs.
This topic is locked and can not be replied to.