package HTML::FromANSI; $HTML::FromANSI::VERSION = '2.03'; use strict; use base qw/Exporter/; use vars qw/@EXPORT @EXPORT_OK @Color %Options/; use Term::VT102::Boundless; use HTML::Entities; use Scalar::Util qw(blessed reftype); use Carp qw(croak); =head1 NAME HTML::FromANSI - Mark up ANSI sequences as HTML =head1 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."); =head1 DESCRIPTION This small module converts ANSI text sequences to corresponding HTML codes, using stylesheets to control color and blinking properties. It exports C 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 C<%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 L, a DEC VT102 terminal emulator. To generate ANSI codes for color changes, cursor movements etc, take a look at L and L. =head1 METHODS =over 4 =item new The constructor. See L for the options it takes. =item add_text @text Adds text input to the terminal emulator. =item html Renders the screen as computed by C into HTML. =item ansi_to_html @text A convenience method. Calls C and then C. =item terminal_object The underlying terminal emulator object. =back =head1 OPTIONS These are parameters you can pass to C. =over 4 =item linewrap A boolean value to specify whether to wrap lines that exceeds width specified by C, or simply truncate them. Defaults to C<1>. Only takes effect if you override C or C with a L (instead of L). =item lf_to_crlf A boolean value to specify whether to translate all incoming \n into C<\r\n> or not; you generally wants to use this if your data is from a file using unix line endings. The default is C<0> on MSWin32 and MacOS, and C<1> on other platforms. =item fill_cols A boolean value to specify whether to fill empty columns with space; use this if you want to maintain a I appearance in the resulting HTML, so that each row will be aligned properly. Defaults to C<0>. =item html_entity A boolean value to specify whether to escape all high-bit characters to HTML entities or not; defaults to C<0>, which means only C>, C>, C<"> and C<&> will be escaped. (Handy when processing most ANSI art entries.) =item cols A number specifying the width of the virtual terminal; defaults to 80. When C is in use (the default) this specifies the minimum number of rows to draw. When using C (by overriding C or C) then the number of columns is fixed. =item rows When C is in use (the default) this specifies the minimum number of rows to draw. When L is in use (by overriding C or L) then it sets the height of the virtual terminal; rows that exceeds this number will be truncated. =item font_face A string used as the C attribute to the C tag enclosing the HTML text; defaults to C. If this option and the C