qbxk has asked for the wisdom of the Perl Monks concerning the following question:

I'd like to capture the output of a script and convert it to html, it uses color text on output quite a bit (printed by Term::ANSIColor) and I'd like to preserve it, any suggestions?

It's not what you look like, when you're doin' what you’re doin'.
It's what you’re doin' when you’re doin' what you look like you’re doin'!
     - Charles Wright & the Watts 103rd Street Rhythm Band, Express yourself

Replies are listed 'Best First'.
Re: Convert Term::ANSIColor to HTML?
by Fletch (Bishop) on Apr 28, 2008 at 21:01 UTC
    • Read through the output looking for start of "markup" sequences (\e[)
    • Parse the color information up to the end of the sequence (digits through the next m)
    • Convert the color information to <span style="color: foo;"> markup
    • Spit out the matching closing </span> token when you hit the reset sequence (\e[0m)
    • Profit!

    Season appropriately if sequences can be nested in your output (e.g. red text which has a span of reversed text characters in the middle).

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

        Case closed, thanks a-non-e-monk!

        It's not what you look like, when you're doin' what you’re doin'.
        It's what you’re doin' when you’re doin' what you look like you’re doin'!
             - Charles Wright & the Watts 103rd Street Rhythm Band, Express yourself