From 5bf4cbbdb74dfaaac258dc93e54dcae8295211e9 Mon Sep 17 00:00:00 2001
From: Rick Olson We want to put a paragraph... ...right there.
tag is appended. This
# method does not remove the newlines from the +text+.
#
+ # You can pass any HTML attributes into html_options. These
+ # will be added to all created paragraphs.
# ==== Examples
# my_text = "Here is some basic text...\n...with a line break."
#
@@ -301,11 +303,17 @@ module ActionView
#
# simple_format(more_text)
# # => "
"). # 2+ newline -> paragraph
- gsub(/([^\n]\n)(?=[^\n])/, '\1
') # 1 newline -> br
+ #
+ # simple_format("Look ma! A class!", :class => 'description')
+ # # => "
Look ma! A class!
" + def simple_format(text, html_options={}) + start_tag = tag('p', html_options, true) + text = text.to_s.dup + text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n + text.gsub!(/\n\n+/, "\n\n#{start_tag}") # 2+ newline -> paragraph + text.gsub!(/([^\n]\n)(?=[^\n])/, '\1