# Textilize problems with line breaks

**URL:** <https://www.ruby-forum.com/t/textilize-problems-with-line-breaks/55912>\
**Category:** Rails\
**Created:** [March 25, 2006, 3:12am UTC](https://www.ruby-forum.com/t/textilize-problems-with-line-breaks/55912 "2006-03-25T03:12:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmarkow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bc8723/32.png) [@dmarkow](https://www.ruby-forum.com/u/dmarkow)\
**Post date:** [March 25, 2006, 3:12am UTC](https://www.ruby-forum.com/t/textilize-problems-with-line-breaks/55912/1 "2006-03-25T03:12:16Z")

</div>

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??

---

<div class="post-metadata">

**Author:** ![dmarkow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bc8723/32.png) [@dmarkow](https://www.ruby-forum.com/u/dmarkow)\
**Post date:** [March 25, 2006, 7:31pm UTC](https://www.ruby-forum.com/t/textilize-problems-with-line-breaks/55912/2 "2006-03-25T19:31:55Z")

</div>

try:

sometext = RedCloth.new(@body, :hard\_breaks)  
sometext.to\_html

although, judging by [http://redcloth.rubyforge.org/rdoc/](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?

---

<div class="post-metadata">

**Author:** ![dmarkow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bc8723/32.png) [@dmarkow](https://www.ruby-forum.com/u/dmarkow)\
**Post date:** [March 25, 2006, 8:55pm UTC](https://www.ruby-forum.com/t/textilize-problems-with-line-breaks/55912/3 "2006-03-25T20:55:47Z")

</div>

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:

Test1.  
Test2.  
Test3.  
Test4.

RedCloth.new(@body).to\_html (without hard\_breaks) gives me:

Test1.

Test2.

Test3. Test4.

I’ve also tried doing a textilize(@body.gsub("\r\n","  
")) to  
force one   
 per line break, but then it screws up things like  
bulleted and numbered lists.
