# Change simple format

**URL:** <https://www.ruby-forum.com/t/change-simple-format/139475>\
**Category:** Rails\
**Created:** [June 4, 2008, 9:41am UTC](https://www.ruby-forum.com/t/change-simple-format/139475 "2008-06-04T09:41:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [June 4, 2008, 9:41am UTC](https://www.ruby-forum.com/t/change-simple-format/139475/1 "2008-06-04T09:41:07Z")

</div>

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!(/(’ ')/, "&nbsp;")  
text.gsub!(/(\r\n|\n|\r)/, “\n”) # lets make them newlines  
crossplatform  
text.gsub!(/\n\n+/, “\n\n”) # zap dupes  
text.gsub!(/\n\n/, ‘

\0

’) # turn two newlines into paragraph  
text.gsub!(/([^\n])(\n)([^\n])/, ‘\1\2  
\3’) # turn single  
newline into  
content\_tag(“p”, text)  
end
