Skip to content

Instantly share code, notes, and snippets.

View Brendaneus's full-sized avatar
Hello

Brendan Crocker Brendaneus

Hello
View GitHub Profile
@henrik
henrik / unsimple_format.rb
Created November 28, 2008 09:04
Like Rails' simple_format but avoids <p>/<br /> around some block tags.
# From Rails
def simple_format(text, html_options={})
start_tag = '<p>'
text = text.to_s.dup
text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n
text.gsub!(/\n\n+/, "</p>\n\n#{start_tag}") # 2+ newline -> paragraph
text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
text.insert 0, start_tag
text << "</p>"
end
index
home
top
help
about
security
contact
connect
support
faq