From: elliottcable Date: 2008-08-14T08:08:10+09:00 Subject: Re: script for wrapping and unwrapping text? I was working on something similar to this last night - it may be able to help you. My requirements are slightly different - I wanted something that would wrap text to a given terminal size for a IM/IRC client I am writing - my requirements are that wrapped text 'look' good (i.e. not break words unless absolutely necessary, not leave mostly-blank lines due to a really long 'word' [URL/links/code strings/whatever], and not screw with existing whitespace if you're pasting code or something into a chat). I wrote a little library in the process that 'intelligently' splits a string into an array of words, allowing me to include Enumerable into String. Called it StringRay (I know, retarded... sorry), you can check it out here: http://github.com/elliottcable/stringray The actual wrapping code is available here - you'll need to gem install stringray and include it into class String to use this: http://github.com/elliottcable/rat/tree/master/lib/rat/core_ext/string.rb#L28-80 (That's a direct link - if you're reading this in the archives, the line number references have probably changed. The link may no longer be applicable either.) On Aug 13, 2008, at 10:02 AM, Daniel Choi wrote: > > I'm interested in storing, say, wiki pages as flat files that can be > edited with Vim or Emacs and also processed with line-based unix text > tools and version control systems like Git. All these tools work much > better with linebreaks after every line of text. For example, diffs > are much easier to deal with when a text file has line breaks after > every line of text. > > But it's awkward to edit these same files through a textarea on a > webpage with all the line breaks. Is there a good Ruby tool or script > that can convert a text file written in, say Markdown or Asciidoc, > into a version that removes the line breaks for editing in a browser > textarea and then reinserts them on the update? > > The problem is complicated a bit by the fact that you might want to > preserve line breaks in some parts of a Markdown or Asciidoc document, > like where you have a bulleted list. But you would want to wrap and > unwrap flowing text in a paragraph or in an item of a list. > >