.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "HTML::FormatExternal 3pm" .TH HTML::FormatExternal 3pm "2022-11-19" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" HTML::FormatExternal \- HTML to text formatting using external programs .SH "DESCRIPTION" .IX Header "DESCRIPTION" This is a collection of formatter modules which turn \s-1HTML\s0 into plain text by dumping it through the respective external programs. .PP .Vb 8 \& HTML::FormatText::Elinks \& HTML::FormatText::Html2text \& HTML::FormatText::Links \& HTML::FormatText::Lynx \& HTML::FormatText::Netrik \& HTML::FormatText::Vilistextum \& HTML::FormatText::W3m \& HTML::FormatText::Zen .Ve .PP The module interfaces are compatible with \f(CW\*(C`HTML::Formatter\*(C'\fR modules such as \&\f(CW\*(C`HTML::FormatText\*(C'\fR, but the external programs do all the work. .PP Common formatting options are used where possible, such as \f(CW\*(C`leftmargin\*(C'\fR and \&\f(CW\*(C`rightmargin\*(C'\fR. So just by switching the class you can use a different program (or the plain \f(CW\*(C`HTML::FormatText\*(C'\fR) according to personal preference, or strengths and weaknesses, or what you've got. .PP There's nothing particularly difficult about piping through these programs, but a unified interface hides details like how to set margins and how to force input or output charsets. .SH "FUNCTIONS" .IX Header "FUNCTIONS" Each of the classes above provide the following functions. The \f(CW\*(C`XXX\*(C'\fR in the class names here is a placeholder for any of \f(CW\*(C`Elinks\*(C'\fR, \f(CW\*(C`Lynx\*(C'\fR, etc as above. .PP See \fIexamples/demo.pl\fR in the HTML-FormatExternal sources for a complete sample program. .SS "Formatter Compatible Functions" .IX Subsection "Formatter Compatible Functions" .ie n .IP """$text = HTML::FormatText::XXX\->format_file ($filename, key=>value,...)""" 4 .el .IP "\f(CW$text = HTML::FormatText::XXX\->format_file ($filename, key=>value,...)\fR" 4 .IX Item "$text = HTML::FormatText::XXX->format_file ($filename, key=>value,...)" .PD 0 .ie n .IP """$text = HTML::FormatText::XXX\->format_string ($html_string, key=>value,...)""" 4 .el .IP "\f(CW$text = HTML::FormatText::XXX\->format_string ($html_string, key=>value,...)\fR" 4 .IX Item "$text = HTML::FormatText::XXX->format_string ($html_string, key=>value,...)" .PD Run the formatter program over a file or string with the given options and return the formatted result as a string. See \*(L"\s-1OPTIONS\*(R"\s0 below for possible key/value options. For example, .Sp .Vb 1 \& $text = HTML::FormatText::Lynx\->format_file (\*(Aq/my/file.html\*(Aq); \& \& $text = HTML::FormatText::W3m\->format_string \& (\*(Aq

Hello world!

\*(Aq); .Ve .Sp \&\f(CW\*(C`format_file()\*(C'\fR ensures any \f(CW$filename\fR is interpreted as a filename (by escaping as necessary against however the programs interpret command line arguments). .ie n .IP """$formatter = HTML::FormatText::XXX\->new (key=>value, ...)""" 4 .el .IP "\f(CW$formatter = HTML::FormatText::XXX\->new (key=>value, ...)\fR" 4 .IX Item "$formatter = HTML::FormatText::XXX->new (key=>value, ...)" Create a formatter object with the given options. In the current implementation an object doesn't do much more than remember the options for future use. .Sp .Vb 1 \& $formatter = HTML::FormatText::Elinks\->new(rightmargin => 60); .Ve .ie n .IP """$text = $formatter\->format ($tree_or_string)""" 4 .el .IP "\f(CW$text = $formatter\->format ($tree_or_string)\fR" 4 .IX Item "$text = $formatter->format ($tree_or_string)" Run the \f(CW$formatter\fR program on a \f(CW\*(C`HTML::TreeBuilder\*(C'\fR tree or a string, using the options in \f(CW$formatter\fR, and return the result as a string. .Sp A TreeBuilder argument (ie. a \f(CW\*(C`HTML::Element\*(C'\fR) is accepted for compatibility with \f(CW\*(C`HTML::Formatter\*(C'\fR. The tree is simply turned into a string with \f(CW\*(C`$tree\->as_HTML\*(C'\fR to pass to the program, so if you've got a string already then give that instead of a tree. .Sp \&\f(CW\*(C`HTML::Element\*(C'\fR itself has a \f(CW\*(C`format()\*(C'\fR method (see \&\*(L"format\*(R" in HTML::Element) which runs a given \f(CW$formatter\fR. A \f(CW\*(C`HTML::FormatExternal\*(C'\fR object can be used for \f(CW$formatter\fR. .Sp .Vb 1 \& $text = $tree\->format($formatter); \& \& # which dispatches to \& $text = $formatter\->format($tree); .Ve .SS "Extra Functions" .IX Subsection "Extra Functions" The following are extra methods not available in the plain \&\f(CW\*(C`HTML::FormatText\*(C'\fR. .ie n .IP """HTML::FormatText::XXX\->program_version ()""" 4 .el .IP "\f(CWHTML::FormatText::XXX\->program_version ()\fR" 4 .IX Item "HTML::FormatText::XXX->program_version ()" .PD 0 .ie n .IP """HTML::FormatText::XXX\->program_full_version ()""" 4 .el .IP "\f(CWHTML::FormatText::XXX\->program_full_version ()\fR" 4 .IX Item "HTML::FormatText::XXX->program_full_version ()" .ie n .IP """$formatter\->program_version ()""" 4 .el .IP "\f(CW$formatter\->program_version ()\fR" 4 .IX Item "$formatter->program_version ()" .ie n .IP """$formatter\->program_full_version ()""" 4 .el .IP "\f(CW$formatter\->program_full_version ()\fR" 4 .IX Item "$formatter->program_full_version ()" .PD Return the version number of the formatter program as reported by its \&\f(CW\*(C`\-\-version\*(C'\fR or similar option. If the formatter program is not available then return \f(CW\*(C`undef\*(C'\fR. .Sp \&\f(CW\*(C`program_version()\*(C'\fR is the bare version number, perhaps with \*(L"beta\*(R" or similar indication. \f(CW\*(C`program_full_version()\*(C'\fR is the entire version output, which may include build options, copyright notice, etc. .Sp .Vb 2 \& $str = HTML::FormatText::Lynx\->program_version(); \& # eg. "2.8.7dev.10" \& \& $str = HTML::FormatText::W3m\->program_full_version(); \& # eg. "w3m version w3m/0.5.2, options lang=en,m17n,image,..." .Ve .Sp The version number of the respective Perl module itself is available in the usual way (see \*(L"\s-1VERSION\*(R"\s0 in \s-1UNIVERSAL\s0). .Sp .Vb 2 \& $modulever = HTML::FormatText::Netrik\->VERSION; \& $modulever = $formatter\->VERSION .Ve .SH "CHARSETS" .IX Header "CHARSETS" File or byte string input is by default interpreted by the programs in their usual ways. This should mean \s-1HTML\s0 Latin\-1 but user configurations might override that and some programs recognise a \f(CW\*(C`\*(C'\fR charset declaration or a Unicode \s-1BOM.\s0 The \f(CW\*(C`input_charset\*(C'\fR option below can force the input charset. .PP Perl wide-character input string is encoded and passed to the program in whatever way it best understands. Usually this is \s-1UTF\-8\s0 but in some cases it is entitized instead. The \f(CW\*(C`input_charset\*(C'\fR option can force the input charset to use if for some reason \s-1UTF\-8\s0 is not best. .PP The output string is either bytes or wide chars. By default output is the same as input, so wide char string input gives wide output and byte input string or file input gives byte output. The \f(CW\*(C`output_wide\*(C'\fR option can force the output type (and is the way to get wide chars back from \&\f(CW\*(C`format_file()\*(C'\fR). .PP Byte output is whatever the program produces. Its default might be the locale charset or other user configuration which suits direct display to the user's terminal. The \f(CW\*(C`output_charset\*(C'\fR option can force the output to be certain or to be ready for further processing. .PP Wide char output is done by choosing the best output charset the program can do and decoding its output. Usually this means \s-1UTF\-8\s0 but some of the programs may only have less. The \f(CW\*(C`output_charset\*(C'\fR option can force the charset used and decoded. If it's something less than \s-1UTF\-8\s0 then some programs might for example give \s-1ASCII\s0 art approximations of otherwise unrepresentable characters. .PP Byte input is usual for \s-1HTML\s0 downloaded from a \s-1HTTP\s0 server or from a \s-1MIME\s0 email and the headers have the \f(CW\*(C`input_charset\*(C'\fR which applies. Byte output is good to go straight out to a tty or back to more \s-1MIME\s0 etc. The input and output charsets could differ if a server gives something other than what you want for final output. .PP Wide chars are most convenient for crunching text within Perl. The default wide input giving wide output is designed to be transparent for this. .PP For reference, if a \f(CW\*(C`HTML::Element\*(C'\fR tree contains wide char strings then its usual \f(CW\*(C`as_HTML()\*(C'\fR method, which is used by \f(CW\*(C`format()\*(C'\fR above, produces wide char \s-1HTML\s0 so the formatters here give wide char text. Actually \&\f(CW\*(C`as_HTML()\*(C'\fR produces all \s-1ASCII\s0 because its default behaviour is to entitize anything \*(L"unsafe\*(R", but it's still a wide char string so the formatted output text is wide. .SH "OPTIONS" .IX Header "OPTIONS" The following options can be given to the constructor or to the formatting methods. The defaults are whatever the respective programs do. The programs generally read their config files when dumping so the defaults and formatting details may follow the user's personal preferences. Usually this is a good thing. .ie n .IP """leftmargin => INTEGER""" 4 .el .IP "\f(CWleftmargin => INTEGER\fR" 4 .IX Item "leftmargin => INTEGER" .PD 0 .ie n .IP """rightmargin => INTEGER""" 4 .el .IP "\f(CWrightmargin => INTEGER\fR" 4 .IX Item "rightmargin => INTEGER" .PD The column numbers for the left and right hand ends of the text. \&\f(CW\*(C`leftmargin\*(C'\fR 0 means no padding on the left. \f(CW\*(C`rightmargin\*(C'\fR is the text width, so for instance 60 would mean the longest line is 60 characters (inclusive of any \f(CW\*(C`leftmargin\*(C'\fR). These options are compatible with \&\f(CW\*(C`HTML::FormatText\*(C'\fR. .Sp \&\f(CW\*(C`rightmargin\*(C'\fR is not necessarily a hard limit. Some of the programs will exceed it in a \s-1HTML\s0 literal \f(CW\*(C`
\*(C'\fR, or a run of \f(CW\*(C` \*(C'\fR or similar.
.ie n .IP """input_charset => STRING""" 4
.el .IP "\f(CWinput_charset => STRING\fR" 4
.IX Item "input_charset => STRING"
Force the \s-1HTML\s0 input to be interpreted as bytes of the given charset,
irrespective of locale, user configuration, \f(CW\*(C`\*(C'\fR in the \s-1HTML,\s0 etc.
.ie n .IP """output_charset => STRING""" 4
.el .IP "\f(CWoutput_charset => STRING\fR" 4
.IX Item "output_charset => STRING"
Force the text output to be encoded as the given charset.  The default
varies among the programs, but usually defaults to the locale.
.ie n .IP """output_wide => 0,1,""as_input""""" 4
.el .IP "\f(CWoutput_wide => 0,1,``as_input''\fR" 4
.IX Item "output_wide => 0,1,""as_input"""
Select output string as wide characters rather than bytes.  The default is
\&\f(CW"as_input"\fR which means a wide char input string results in a wide char
output string and a byte input or file input is byte output.  See
\&\*(L"\s-1CHARSETS\*(R"\s0 above for how wide characters work.
.Sp
Bytes or wide chars output can be forced by 0 or 1 respectively.  For
example to get wide char output when formatting a file,
.Sp
.Vb 2
\&    $wide_char_text = HTML::FormatText::W3m\->format_file
\&                       (\*(Aq/my/file.html\*(Aq, output_wide => 1);
.Ve
.ie n .IP """base => STRING""" 4
.el .IP "\f(CWbase => STRING\fR" 4
.IX Item "base => STRING"
Set the base \s-1URL\s0 for any relative links within the \s-1HTML\s0 (similar to
\&\f(CW\*(C`HTML::FormatText::WithLinks\*(C'\fR).  Usually this should be the location the
\&\s-1HTML\s0 was downloaded from.
.Sp
If the document contains its own \f(CW\*(C`\*(C'\fR setting then currently the
document takes precedence.  Only Lynx and Elinks display absolutized link
targets and the option has no effect on the other programs.
.SH "TAINT MODE"
.IX Header "TAINT MODE"
The formatter modules can be used under \f(CW\*(C`perl \-T\*(C'\fR taint mode.  They run
external programs so it's necessary to untaint \f(CW$ENV{PATH}\fR in the usual
way per \*(L"Cleaning Up Your Path\*(R" in perlsec.
.PP
The formatted text strings returned are always tainted, on the basis that
they use or include data from outside the Perl program.  The
\&\f(CW\*(C`program_version()\*(C'\fR and \f(CW\*(C`program_full_version()\*(C'\fR strings are tainted too.
.SH "BUGS"
.IX Header "BUGS"
\&\f(CW\*(C`leftmargin\*(C'\fR is implemented by adding spaces to the program output.  For
byte output it this is \s-1ASCII\s0 spaces and that will be badly wrong for unusual
output like \s-1UTF\-16\s0 which is not a byte superset of \s-1ASCII.\s0  For wide char
output the margin is applied after decoding to wide chars so is correct.
It'd be better to ask the programs to do the margin but their options for
that are poor.
.PP
There's nothing done with errors or warning messages from the programs.
Generally they make a best effort on doubtful \s-1HTML,\s0 but fatal errors like
bad options or missing libraries ought to be somehow trapped.
.SH "OTHER POSSIBILITIES"
.IX Header "OTHER POSSIBILITIES"
\&\f(CW\*(C`elinks\*(C'\fR (from Aug 2008 onwards) and \f(CW\*(C`netrik\*(C'\fR can produce \s-1ANSI\s0 escapes for
colours, underline, etc, and \f(CW\*(C`html2text\*(C'\fR and \f(CW\*(C`lynx\*(C'\fR can produce tty style
backspace overstriking.  This might be good for text destined for a tty or
further crunching.  Perhaps an \f(CW\*(C`ansi\*(C'\fR or \f(CW\*(C`tty\*(C'\fR option could enable this,
where possible, but for now it's deliberately turned off in those programs
to keep the default as plain text.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
HTML::FormatText::Elinks,
HTML::FormatText::Html2text,
HTML::FormatText::Links,
HTML::FormatText::Netrik,
HTML::FormatText::Lynx,
HTML::FormatText::Vilistextum,
HTML::FormatText::W3m,
HTML::FormatText::Zen
.PP
HTML::FormatText,
HTML::FormatText::WithLinks,
HTML::FormatText::WithLinks::AndTables
.SH "HOME PAGE"
.IX Header "HOME PAGE"

.SH "LICENSE"
.IX Header "LICENSE"
Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2015 Kevin Ryde
.PP
HTML-FormatExternal is free software; you can redistribute it and/or modify
it under the terms of the \s-1GNU\s0 General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any later
version.
.PP
HTML-FormatExternal is distributed in the hope that it will be useful, but
\&\s-1WITHOUT ANY WARRANTY\s0; without even the implied warranty of \s-1MERCHANTABILITY\s0
or \s-1FITNESS FOR A PARTICULAR PURPOSE.\s0  See the \s-1GNU\s0 General Public License for
more details.
.PP
You should have received a copy of the \s-1GNU\s0 General Public License along with
HTML-FormatExternal.  If not, see .