> > i've found a great bit of code from
> >
> > http://dev.rubyonrails.org/ticket/1449
> >
> > that takes some text and makes it wrap at 80 lines. the only issue is
that
> > it takes multiple line breaks (like paragraphs), and makes them into
single
> > line breaks.
> >
> > this is the code:
> >
> > text.gsub( /\n/, "\n\n" ).gsub( /(.{1,80})(\s+|$)/, "\\1\n")
> >
> > i've tinkered with it for a while, but i can't work out how to not have
it
> > eat lines breaks so hungrily.
>
> Hi Luke,
>
> can you tell us how you want to treat whitespace in the given text? You
> talked about newlines, but what should be the result in the following
cases:
>
>    "abcde\n  c".wrap(5)  # => "abcde\nc" or "abcde\n  c"
>    "a   e\na".wrap(5)    # => "a   e\na" or "a e a"
>
> Regards,
> Pit
>

hi pit,

thanks for your help.

ideally how i would like it to behave given your examples, would be like:

"abcde\n  c".wrap(5)  # => "abcde\nc"
"a   e\na".wrap(5)    # => "a   e\na"

does that make sense? so text would be flush with the left margin with no
white space at the beginning of new lines. but whitespace within a line
should remain intact.

thanks

luke