From: Eric Hodel Date: 2005-11-20T17:00:09+09:00 Subject: Re: problems with making wordwrap On Nov 19, 2005, at 10:07 PM, luke wrote: > hi, > > 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. I use Text::Format for this: def wrap(text) formatter = Text::Format.new formatter.columns = 72 # 70 + '> ' = 72 formatter.format_style = Text::Format::LEFT_ALIGN formatter.first_indent = 0 formatted = [] text.split(/\r?\n\r?\n/).each do |chunk| formatted << formatter.paragraphs(chunk) end return formatted.join("\n") end http://www.halostatue.ca/ruby/Text__Format.html -- Eric Hodel - drbrain@segment7.net - http://segment7.net FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04