simple_format option for intentionally long line breaks

There are quite a lot of line break issues with Rails on StackOverflow and the web in general. A lot of solutions are ugly and a lot modify simple_format so I’ve created a patch that I’d like to hear thoughts on before submitting a PR.

I’ve made a slight modification to split_paragraphs and how it gsubs the newline characters in paragraphs up so that if you pass it a line option, instead of getting rid of all newlines and return carriage characters, it can substitute \r\n for an html break element.

This way if a saved chunk of text is the following then it won’t be stripped down to just the 2 lines of text but
will have the
tags that were obviously intended:

“\r\n\r\n\r\n\r\n\r\n\r\n\r\n
r\nBig gap.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nPlease.”

This doesn’t affect the regular behaviour of simple_format and will still return the usual result without the option.

I
find that this isn’t an edge case but is frequent enough to warrant this and not have people overriding simple_format and split_paragraphs in their application helper.

Thoughts?

Some more food for thought:

If multiple breaks are frowned upon, then the following scenario should also be considered:

simple_format(Post.some_multiline_text, {}, wrapper_tag: “div”)

Because the wrapper_tag isn’t a

element, the lines will not have a nice spacing between them even if the text includes \n\n etc.