ruby nl2br outside <code> ... </code>

Posted by Julien P. on Stack Overflow See other posts from Stack Overflow or by Julien P.
Published on 2010-03-08T21:22:36Z Indexed on 2010/04/16 13:23 UTC
Read the original article Hit count: 471

Filed under:
|
|
|
|

Hi everyone, I've been struggling on this thing for a week without being able to find what I'm looking for.

Here is what I'd like to do:

I'm setting up a wiki where I can post all my knowledge to (yes, I know a couple things :p) but I can't render it the way I'd like to. The bodies of my posts are text fields. In order to render them the right way I run the following command:

@post.body.gsub("\n", "<br />")

I also have some tags with some code inside that looks like this < code> my code < /code>.

Here come's the issue. Every line between the < code> and < /code> tags are changed to
but it doesn'r render properly since I'm using a code render template.

Therefore, I'd like to know if there is a way to change all \n to < br /> except for those between < code> and < /code>

Thank you everyone for reading this and helping me out.

PS: Please do not consider the spaces after the < in each tag. I had to do this to "espace" them.

Julien

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about string