The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

HTML::FromANSI - Mark up ANSI sequences as HTML

SYNOPSIS

    use HTML::FromANSI (); # avoid exports if using OO
    use Term::ANSIColor;

    my $h = HTML::FromANSI->new(
        fill_cols => 1,
    );


    $h->add_text(color('bold blue'), "This text is bold blue.");

    print $h->html;


    # you can append text in the new api:

    $h->add_text(color('bold blue'), " still blue.");

    print $h->html



    # The old API still works:

    $HTML::FromANSI::Options{fill_cols} = 1; # fill all 80 cols
    print ansi2html(color('bold blue'), "This text is bold blue.");

DESCRIPTION

This small module converts ANSI text sequences to corresponding HTML codes, using stylesheets to control color and blinking properties.

It exports ansi2html() by default, which takes an array, joins it it into a single scalar, and returns its HTML rendering.

From version 2.00 an object oriented api which is safer for multiple uses (no more manipulation of shared %Options) is available. It is reccomended that you no longer import any functions by doing:

    use HTML::FromANSI ();

and use the new documented API instead of the functional one.

The underlying ANSI code processing is done by Term::VT102, a DEC VT102 terminal emulator. To generate ANSI codes for color changes, cursor movements etc, take a look at Term::ANSIScreen and Term::ANSIColor.

METHODS

new

The constructor. See "OPTIONS" for the options it takes.

add_text @text

Adds text input to the terminal emulator.

html

Renders the screen as computed by terminal_object into HTML.

ansi_to_html @text

A convenience method.

Calls add_text and then html.

terminal_object

The underlying terminal emulator object.

OPTIONS

These are parameters you can pass to new.

linewrap

A boolean value to specify whether to wrap lines that exceeds width specified by col, or simply truncate them. Defaults to 1.

Only takes effect if you override terminal_class or terminal_object with a Term::VT102 (instead of Term::VT102::Boundless).

lf_to_crlf

A boolean value to specify whether to translate all incoming \n into \r\n or not; you generally wants to use this if your data is from a file using unix line endings. The default is 0 on MSWin32 and MacOS, and 1 on other platforms.

fill_cols

A boolean value to specify whether to fill empty columns with space; use this if you want to maintain a screen-like appearance in the resulting HTML, so that each row will be aligned properly. Defaults to 0.

html_entity

A boolean value to specify whether to escape all high-bit characters to HTML entities or not; defaults to 0, which means only <, >, " and & will be escaped. (Handy when processing most ANSI art entries.)

cols

A number specifying the width of the virtual terminal; defaults to 80.

When Term::VT102::Boundless is in use (the default) this specifies the minimum number of rows to draw.

When using Term::VT102 (by overriding terminal_class or terminal_object) then the number of columns is fixed.

rows

When Term::VT102::Boundless is in use (the default) this specifies the minimum number of rows to draw.

When Term::VT102 is in use (by overriding terminal_class or terminal_object) then it sets the height of the virtual terminal; rows that exceeds this number will be truncated.

font_face

A string used as the face attribute to the font tag enclosing the HTML text; defaults to fixedsys, lucida console, terminal, vga, monospace.

If this option and the style option are both set to empty strings, the font tag will be omitted.

style

A string used as the style attribute to the font tag enclosing the HTML text; defaults to <line-height: 1; letter-spacing: 0; font-size: 12pt>.

If this option and the font_face option are both set to empty strings, the font tag will be omitted.

tt

A boolean value specifying whether the HTML text should be enclosed in a tt tag or not. Defaults to 1.

show_cursor

A boolean value to control whether to highlight the character under the cursor position, by reversing its background and foregroud color. Defaults to 0.

If the cursor is on it's own line and show_cursor is set, then that row will be omitted.

terminal_class

The class to instantiate terminal_object with. Defaults to Term::VT102::Boundless.

terminal_object

Any Term::VT102 compatible object should work here.

If you override it most values like cols, rows, terminal_class etc will be ignored.

SEE ALSO

Term::VT102::Boundless, HTML::Entities, Term::ANSIScreen

AUTHORS

Audrey Tang <audreyt@audreyt.org> Yuval Kogman <nothingmuch@woobling.org>

COPYRIGHT

Copyright 2001, 2002, 2003 by Audrey Tang <audreyt@audreyt.org>.

Copyright 2007 Yuval Kogman <nothingmuch@Woobling.org>

This program is free software; you can redistribute it and/or modify it under the terms of the MIT license or the same terms as Perl itself.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 388:

You forgot a '=back' before '=head1'