Ticket #2539: allow_redcloth_restrictions_rev2.diff
| File allow_redcloth_restrictions_rev2.diff, 2.3 kB (added by josh, 2 years ago) |
|---|
-
test/template/text_helper_test.rb
old new 347 347 assert_equal "This has a here.", strip_tags("This has a <!-- comment --> here.") 348 348 [nil, '', ' '].each { |blank| assert_equal blank, strip_tags(blank) } 349 349 end 350 351 def test_textilize 352 assert_equal("", textilize("")) 353 assert_equal("", textilize(:text => "")) 354 assert_equal("<p>Large <span style=\"color:red;\">Colorful</span> Signs!</p>", textilize("Large %{color:red}Colorful% Signs!")) 355 assert_equal("This is <strong>just</strong> a test.", textilize(:text => "This is *just* a test.", :restrictions => [:lite_mode])) 356 assert_equal("<p>This is<br />only a test.</p>", textilize(:text => "This is\nonly a test.", :restrictions => [:hard_breaks])) 357 assert_equal("<strong>well isn’t this handy</strong>", textilize_without_paragraph("*well isn't this handy*")) 358 end 350 359 end -
lib/action_view/helpers/text_helper.rb
old new 112 112 # Returns the text with all the Textile codes turned into HTML tags. 113 113 # <i>This method is only available if RedCloth[http://whytheluckystiff.net/ruby/redcloth/] 114 114 # is available</i>. 115 def textilize(text) 116 if text.blank? 117 "" 118 else 119 textilized = RedCloth.new(text, [ :hard_breaks ]) 120 textilized.hard_breaks = true if textilized.respond_to?("hard_breaks=") 121 textilized.to_html 115 def textilize(options) 116 case options 117 when String 118 if options.empty? 119 "" 120 else 121 textilized = RedCloth.new(options, [ :hard_breaks ]) 122 textilized.to_html 123 end 124 when Hash 125 if options[:text] 126 textilized = RedCloth.new(options[:text], (options[:restrictions] || [])) 127 textilized.to_html 128 else 129 "" 130 end 122 131 end 123 132 end 124 133