I'm having a problem formatting some text. I have a textarea that I input my text into, which will then be put into an e-mail and sent out. The problem I am having is when there is a single line break. Multiple line breaks work fine (hitting enter twice), but single line breaks don't seem to work properly. Take the following input: Line1. Line2. Line3. Line4. Using <%= textilize @body %> gives me: Line1. Line2. Line3. Line4. Knowing that there's an issue in rails with hard_breaks and textilize, I tried RedCloth.new(@body).to_html, which gave me: Line1. Line2. Line3.Line4. Am I missing something??
on 2006-03-25 03:12
on 2006-03-25 19:31
try: sometext = RedCloth.new(@body, :hard_breaks) sometext.to_html although, judging by http://redcloth.rubyforge.org/rdoc/ that should be the default behaviour, and the rails 'textilize' method should also do that by default: # File vendor/rails/actionpack/lib/action_view/helpers/text_helper.rb, line 84 84: def textilize(text) 85: if text.blank? 86: "" 87: else 88: textilized = RedCloth.new(text, [ :hard_breaks ]) 89: textilized.hard_breaks = true if textilized.respond_to?("hard_breaks=") 90: textilized.to_html 91: end 92: end I've had loads of problems with various platforms and hard_breaks. what is your actual html output from the various options you tried?
on 2006-03-25 20:55
Doing that gives me the exact same output that textilize(@body) does. Textilize(@body) and RedCloth.new(@body, [:hard_breaks]).to_html both give me: <p>Test1.<br />Test2.<br />Test3.<br />Test4.</p> RedCloth.new(@body).to_html (without hard_breaks) gives me: <p>Test1.</p><p>Test2.</p><p>Test3. Test4.</p> I've also tried doing a textilize(@body.gsub("\r\n","<br/>")) to force one <br/> per line break, but then it screws up things like bulleted and numbered lists.