diff --git a/railties/guides/rails_guides/textile_extensions.rb b/railties/guides/rails_guides/textile_extensions.rb
index 352c5e91dd54717299c261ab33cc92a111ee8978..0887ebf76b56f81e6f9f3b68a1001419307b0643 100644
--- a/railties/guides/rails_guides/textile_extensions.rb
+++ b/railties/guides/rails_guides/textile_extensions.rb
@@ -15,10 +15,11 @@ def notestuff(body)
end
def tip(body)
- body.gsub!(/^TIP[.:](.*)$/) do |m|
+ body.gsub!(/^TIP[.:](.*?)(\n\Z|\n\n+|\Z)/m) do |m|
result = "
"
result << $1.strip
result << '
'
+ result << $2 if $2
result
end
end
diff --git a/railties/test/guides/textile_extionsions_test.rb b/railties/test/guides/textile_extionsions_test.rb
new file mode 100644
index 0000000000000000000000000000000000000000..9f1068d9be5b7b48e63014a529a5ec0258273a7e
--- /dev/null
+++ b/railties/test/guides/textile_extionsions_test.rb
@@ -0,0 +1,37 @@
+require 'isolation/abstract_unit'
+require 'guides/rails_guides/textile_extensions'
+
+class TextileExtensionsTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
+ include RailsGuides::TextileExtensions
+
+ test "tips can handle a single line" do
+ expected_output = "this is a single line tip
"
+ assert_equal expected_output, tip('TIP. this is a single line tip')
+ end
+
+ def setup
+ @multi_line_tip = "This is a multi-line tip.\n" +
+ "Isn't it fantastic?"
+ end
+
+ test "tips can handle a multi-line tip" do
+ expected_output = ""
+
+ assert_equal expected_output, tip("TIP. #{@multi_line_tip}")
+ end
+
+ test "muli-line tips handles text before and after the tip" do
+ pre_line = "This is text before hand.\n\n"
+ post_line = "\n\nThis is some text after"
+ input_text = pre_line +
+ "TIP. #{@multi_line_tip}" +
+ post_line
+
+ expected_output = pre_line +
+ "" +
+ post_line
+
+ assert_equal expected_output, tip(input_text)
+ end
+end
\ No newline at end of file