Text::Markup is a small library for parsing and emitting marked-up text.

<https://github.com/martindemello/text-markup>

Details:

Text::Markup defines a common representation (Text::Markup::Tree) for
marked-up text. A set of modules deal with conversion to and from this
representation of a variety of "marked-up text" formats.

- Current modules: ANSI (parse and emit) and HTML (emit)

- Currently supported markup attributes are bold, italics, underline,
strikethrough, fgcolor and bgcolor.

Quick example from the README:

require 'text/markup/ansi'
require 'text/markup/html'

ansi = "\e[1m\e[31mBold red text\e[44mon blue\n\e[21m\e[32mGreen
text\e[0mnone\n"
tree = Text::Markup::ANSI.parse(ansi)
html = Text::Markup::HTML.format(tree)
puts html

<b><span style='color:red'>Bold red text<span
style='background-color:blue'>on blue<br/></span></span></b><span
style='background-color:blue'><span style='color:green'>Green
text</span></span>none<br/>

The stream->tree parser currently fixes badly nested tags, but does
not make any attempt to optimise the resulting tree via node
rearrangement. (On the TODO list, patches welcome. Should be a fun
problem. e.g. <red><bold>text</bold></red><blue><bold>text</bold></blue>
could be transformed to <bold><red>text</red><blue>text</blue></bold>
and a smart formatter could drop the </red>)

TODO:

Version 0.02 will add a port of perl's Tk::TextANSIColor
<http://search.cpan.org/~tjenness/Tk-TextANSIColor-0.15/TextANSIColor.pm>

Comments, requests and patches all welcome.

martin