RailsのTextHelper#textilizeがまともに動かない。

TextHelper#textilize は少なくとも手元の環境(Rails 1.2.6/RedCloth 3.0.4)ではまともに動かないっぽい。以下の手順で確認した。

$ ./script/console
>> a = ActionView::Base.new

# リストから脱出ができない。
>> a.textilize("abc\n* def\n\n\nghi")
=> "abc\n\t<ul>\n\t<li>def<br />\nghi</li>\n\t</ul>"

# \nをたくさん書いてもリストから脱出ができない。
>> a.textilize("abc\n* def\n\n\n\n\n\n\n\n\nghi")
=> "abc\n\t<ul>\n\t<li>def<br />\nghi</li>\n\t</ul>"

# 普通にRedClothを使うと最低1行空ければうまくいく。
>> RedCloth.new("abc\n* def\n\nghi").to_html
=> "abc\n\t<ul>\n\t<li>def</li>\n\t</ul>\n\n\n\t<p>ghi</p>"

# hard_breaksオプションを付けるとうまくいかなくなる。
>> RedCloth.new("abc\n* def\n\n\nghi", [:hard_breaks]).to_html
=> "abc\n\t<ul>\n\t<li>def<br />\nghi</li>\n\t</ul>"

RedClothの:hard_breaksオプションが問題なようだ。

trunkでも:hard_breaksオプションが付いてるので、最新のバージョンでもうまくいかないんじゃないだろうか……。

自前でhelperに足すのがいいみたい。

module ApplicationHelper  
  def textilize(text)
    RedCloth.new(text).to_html
  end
end