# How to keep formatting of text in textarea?

**URL:** <https://www.ruby-forum.com/t/how-to-keep-formatting-of-text-in-textarea/78952>\
**Category:** Rails\
**Created:** [March 9, 2006, 12:59pm UTC](https://www.ruby-forum.com/t/how-to-keep-formatting-of-text-in-textarea/78952 "2006-03-09T12:59:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![g0nzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3bc359/32.png) [@g0nzo](https://www.ruby-forum.com/u/g0nzo)\
**Post date:** [March 9, 2006, 12:59pm UTC](https://www.ruby-forum.com/t/how-to-keep-formatting-of-text-in-textarea/78952/1 "2006-03-09T12:59:30Z")

</div>

Hi!

I’ve got a form for creating news and i’d like to keep formatting of the  
text in the textarea - if user presses enter twice, or presses space ten  
times it should be visible when editing or showing the news.

Probably i should add before\_save filter and some regexps for adding  
html tags, but i know almost nothing about regexp. Maybe there’s a  
simpler way also.

---

<div class="post-metadata">

**Author:** ![g0nzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3bc359/32.png) [@g0nzo](https://www.ruby-forum.com/u/g0nzo)\
**Post date:** [March 9, 2006, 1:28pm UTC](https://www.ruby-forum.com/t/how-to-keep-formatting-of-text-in-textarea/78952/2 "2006-03-09T13:28:46Z")

</div>

On 09/03/06, szymek [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’ve got a form for creating news and i’d like to keep formatting of the  
> text in the textarea - if user presses enter twice, or presses space ten  
> times it should be visible when editing or showing the news.
> 
> Probably i should add before\_save filter and some regexps for adding  
> html tags, but i know almost nothing about regexp. Maybe there’s a  
> simpler way also.

Use RedCloth ([http://whytheluckystiff.net/ruby/redcloth/](http://whytheluckystiff.net/ruby/redcloth/)) 🙂

Install RedCloth gem (preferably version 3.0.3 as 3.0.4 is somewhat  
broken). Then when presenting contents of field use textilize() helper  
like this:

\<%= textilize(@item.description) %\>

---

<div class="post-metadata">

**Author:** ![g0nzo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3bc359/32.png) [@g0nzo](https://www.ruby-forum.com/u/g0nzo)\
**Post date:** [March 9, 2006, 1:57pm UTC](https://www.ruby-forum.com/t/how-to-keep-formatting-of-text-in-textarea/78952/3 "2006-03-09T13:57:00Z")

</div>

Dzieki!!!

Is there already function for everything? 🙂
