Reputation: 34013
I use the following to replace every linebreak with a <br>
:
h(my_string).gsub(/(?:\n\r?|\r\n?)/, '<br>').html_safe
I wonder if there would be any solution where if there's a single linebreak, then replace it with a single <br>
. And if there are two or more linebreaks, then replace all with only two <br>
, i.e. <br><br>
?
Upvotes: 0
Views: 72
Reputation: 2020
You can iterate couple of times
h(my_string).gsub(/(\n\r?){2,}/, '<br><br>').gsub(/\n/, '<br>').html_safe
Upvotes: 2