Word wrap regexp question

From the rails helper, there’s a text wrap method that does this (I’ve
removed the trailing .strip):

text.gsub(/\n/, “\n\n”).gsub(/(.{1,#{line_width}})(\s+|$)/, “\1\n”)

The way I read this, it’s “replace every newline with two newlines
(and it’s not clear to me either what this first part is supposed to
accomplish), then replace each instance of the longest string you can
under the line length with that string plus a newline”.

This seems to work fine, except that if there are newlines in the
middle of the string, they get stripped.

So, a paragraph of text that was:

"Testing Testing Testing Testing Testing Testing Testing Testing Testing
Testing Testing Testing Testing Testing Testing Testing Testing Testing
Testing Testing Testing Testing Testing Testing.

Testing Testing Testing Testing Testing Testing Testing Testing Testing
Testing Testing Testing Testing Testing Testing Testing Testing Testing
Testing Testing Testing Testing Testing Testing Testing Testing Testing
Testing."

Becomes something like:

“Testing Testing Testing Testing Testing Testing Testing Testing
Testing Testing Testing Testing Testing Testing Testing Testing
Testing Testing Testing Testing Testing Testing Testing Testing.
Testing Testing Testing Testing Testing Testing Testing Testing
Testing Testing Testing Testing Testing Testing Testing Testing
Testing Testing Testing Testing Testing Testing Testing Testing
Testing Testing Testing Testing.”

Why is the middle newline being removed?


- Adam

** Expert Technical Project and Business Management
**** System Performance Analysis and Architecture
****** [ http://www.everylastounce.com ]

[ Adam Fields (weblog) - - entertaining hundreds of millions of eyeball atoms every day ] … Blog
[ Adam Fields Resume ]… Experience
[ Adam Fields | Flickr ] … Photos
[ http://www.aquicki.com/wiki ]…Wiki
[ http://del.icio.us/fields ] … Links