Trans
8/13/2008 7:51:00 PM
On Aug 13, 2:02=A0pm, Daniel Choi <dhc...@gmail.com> 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.
Well, here's something I've used for part of what you are asking for:
class String
#
def unfold_paragraphs
blank =3D false
text =3D ''
split(/\n/).each do |line|
if /\S/ !~ line
text << "\n\n"
blank =3D true
else
if /^(\s+|[*])/ =3D~ line
text << (line.rstrip + "\n")
else
text << (line.rstrip + " ")
end
blank =3D false
end
end
return text
end
end
T.