0

If I start rails console and enter:

Redcarpet::Markdown.new(Redcarpet::Render::HTML.new).render("line 1  \nline 2").html_safe

(Remember in markdown 2 spaces before a line break means a forced line break) I get the expected: <p>line 1<br>\nline 2</p>\n

But if I use this code in ERB, all I see in my page source is the original text wrapped in a <p>. The line break escape characters are preserved, but the 2 spaces are gone and there is no <br>.

What gives? Thanks for your wisdom. Extra kudos if you explain how I could isolate the problem myself!

2 Answers2

0

I belive You chould do something like

...render("line 1  \nline 2".gsub(/\n/, '<br/>')).html_safe

Well explained here

Community
  • 1
  • 1
alv_721
  • 305
  • 3
  • 18
0

The workaround that I settled on is to use the "hard wrap" option in Redcarpet. This actually is totally acceptable for my use case but I am still curious, so I'll change the accepted answer if anyone comes up with a solution to the original problem.