# Change simple format

**URL:** <https://discuss.rubyonrails.org/t/change-simple-format/30203>\
**Category:** rubyonrails-talk\
**Created:** [June 4, 2008, 7:41am UTC](https://discuss.rubyonrails.org/t/change-simple-format/30203 "2008-06-04T07:41:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [June 4, 2008, 7:41am UTC](https://discuss.rubyonrails.org/t/change-simple-format/30203/1 "2008-06-04T07:41:07Z")

</div>

Hi, &nbsp;&nbsp;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? &nbsp;&nbsp;&nbsp;I want a such method which format all white spaces, new line, paragraphs. &nbsp;&nbsp;&nbsp;how it possible in ruby?

example:

def my\_format(text) &nbsp;&nbsp;&nbsp;&nbsp;text.gsub!(/(' ')/, "&nbsp;") &nbsp;&nbsp;&nbsp;&nbsp;text.gsub!(/(\r\n|\n|\r)/, "\n") # lets make them newlines crossplatform &nbsp;&nbsp;&nbsp;&nbsp;text.gsub!(/\n\n+/, "\n\n") # zap dupes &nbsp;&nbsp;&nbsp;&nbsp;text.gsub!(/\n\n/, '\</p\>\0\<p\>') # turn two newlines into paragraph &nbsp;&nbsp;&nbsp;&nbsp;text.gsub!(/([^\n])(\n)([^\n])/, '\1\2\<br /\>\3') # turn single newline into &nbsp;&nbsp;&nbsp;&nbsp;content\_tag("p", text) &nbsp;&nbsp;end
