HTML::FromANSI - Mark up ANSI sequences as HTML
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.");
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.
ansi2html()
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:
%Options
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.
The constructor. See "OPTIONS" for the options it takes.
Adds text input to the terminal emulator.
Renders the screen as computed by terminal_object into HTML.
terminal_object
A convenience method.
Calls add_text and then html.
add_text
html
The underlying terminal emulator object.
These are parameters you can pass to new.
new
A boolean value to specify whether to wrap lines that exceeds width specified by col, or simply truncate them. Defaults to 1.
col
1
Only takes effect if you override terminal_class or terminal_object with a Term::VT102 (instead of Term::VT102::Boundless).
terminal_class
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.
\r\n
0
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.
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.)
<
>
"
&
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.
Term::VT102::Boundless
When using Term::VT102 (by overriding terminal_class or terminal_object) then the number of columns is fixed.
Term::VT102
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.
A string used as the face attribute to the font tag enclosing the HTML text; defaults to fixedsys, lucida console, terminal, vga, monospace.
face
font
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.
font_face
A boolean value specifying whether the HTML text should be enclosed in a tt tag or not. Defaults to 1.
tt
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.
show_cursor
The class to instantiate terminal_object with. Defaults to Term::VT102::Boundless.
Any Term::VT102 compatible object should work here.
If you override it most values like cols, rows, terminal_class etc will be ignored.
cols
rows
Term::VT102::Boundless, HTML::Entities, Term::ANSIScreen
Audrey Tang <audreyt@audreyt.org> Yuval Kogman <nothingmuch@woobling.org>
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:
You forgot a '=back' before '=head1'
To install HTML::FromANSI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTML::FromANSI
CPAN shell
perl -MCPAN -e shell install HTML::FromANSI
For more information on module installation, please visit the detailed CPAN module installation guide.