Bitten By The Hard Breaks Again
Another turn around the textile wheel of fortune in a rails application today yielded a lesson learned long ago but forgotten. The textilize helper included with rails enables the hard_breaks mode by default. Hard Breaks converts 1 new line to a br and 2 newlines to a p tag. When you disable hard breaks mode you only get p tags.
Here’s how the source for that method looks:
def textilize(text)
if text.blank? "" else textilized = RedCloth.new(text, [ :hard_breaks ])
textilized.hard_breaks = true if textilized.respond_to?("hard_breaks=") textilized.to_html
end
end
Here’s a simple override of it you can put in your application_helper.rb if you want the no hard breaks behaviour.
def textilize(text)
if text.blank?
""
else
RedCloth.new(text).to_html
end
end
Nothing new, just posting it here as a reminder to myself and a hopefully helpful tip to anyone not yet familiar with this difference.