html - Replace 1 newline with <br>, >= 2 with <br><br> -


i use following replace every linebreak <br>:

h(my_string).gsub(/(?:\n\r?|\r\n?)/, '<br>').html_safe 

i wonder if there solution if there's single linebreak, replace single <br>. , if there 2 or more linebreaks, replace 2 <br>, i.e. <br><br>?

you can iterate couple of times

h(my_string).gsub(/(\n\r?){2,}/, '<br><br>').gsub(/\n/, '<br>').html_safe 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -