man2html takes formatted nroff in standard input (STDIN) and outputs the
HTML to standard output (STDOUT). The formatted nroff output is surrounded
with <PRE> tags with the following exceptions/additions:
man2html also does the following:
man2html the page size and margin
width/heights of the formatted nroff. Depagination can be turned off with
the -nodepage command-line option.
man2html does not put a title, <TITLE>, in the HTML file. However,
one can specify a title via the -title command-line option.
man2html also has support for processing output generated from manpage
keyword search, "man -k". See Keyword Search for more information.
man2html is invoked from a Unix shell, with the following syntax:
% man2html [options] < infile > out.html
% man unix_command | man2html [options] > out.html
The following options are available:
-bare
man2html from inserting the HTML, HEAD, BODY
tags from the output. This is useful if you want to incorporate the output
from man2html into an HTML document.
-botm #
-cgiurl string
-headmap file
-help
man2html. No other action is taken.
-k
-leftm #
-nodepage
-noheads
-pgsize #
-seealso
-sun
-sun because it was on a Sun workstation
that section heads in manpages were not overstriked.
-title string
-topm #
man2html allows you to customize what HTML header tags, <H1> ... <H6>, are
used in manpage section headings (via the -headmap option). Normally,
man2html treats lines that are flush to the left margin (-leftm), and contain
overstriking (overstrike check is canceled with the -sun option), as section heads.
However, you can augment/override what HTML header tags are used for any
given section head.
In order to write a section head map file, you will need to know about Perl associative arrays. You do not need to be an expert in Perl to write a map file. However, having knowledge of Perl allows you to be more clever when writing a map file.
man2html, your map file will contain
lines with the following syntax
where,$SectionHead{'<section head text>'} = '<html header tag>';
%SectionHead = (
'<section head text>', '<html header tag>',
'<section head text>', '<html header tag>',
# ... More section head/tag pairs
'<section head text>', '<html header tag>',
);
man2html:
%SectionHead = (
'\S.*OPTIONS.*', '<H2>',
'AUTHORS?', '<H2>',
'BUGS', '<H2>',
'COMPATIBILITY', '<H2>',
'DEPENDENCIES', '<H2>',
'DESCRIPTION', '<H2>',
'DIAGNOSTICS', '<H2>',
'ENVIRONMENT', '<H2>',
'ERRORS', '<H2>',
'EXAMPLES', '<H2>',
'EXTERNAL INFLUENCES', '<H2>',
'FILES', '<H2>',
'LIMITATIONS', '<H2>',
'NAME', '<H2>',
'NOTES?', '<H2>',
'OPTIONS', '<H2>',
'REFERENCES', '<H2>',
'RETURN VALUE', '<H2>',
'SECTION.*:', '<H2>',
'SEE ALSO', '<H2>',
'STANDARDS CONFORMANCE', '<H2>',
'STYLE CONVENTION', '<H2>',
'SYNOPSIS', '<H2>',
'SYNTAX', '<H2>',
'WARNINGS', '<H2>',
'\s+Section.*:', '<H3>',
);
$HeadFallback = '<H2>'; # Fallback tag if above is not found.
Check the Perl source code of man2html for the latest default mapping.
You can reassign the $HeadFallback variable to a different value if you choose.
This value is used as the header tag of a section head if no matches are found in the
SectionHead map.
\s" or "*".
man2html actual treats the <section head text> as a Perl regular expression. If you
are comfortable with Perl regular expressions, then you have the full power of
them to use in your map file.
man2html already anchors the regular expression to the beginning of the
line with left margin spacing specified by the -leftm option. Therefore, do
not use the `^' character to anchor your regular expression to the
beginning. However, you may end your expression with a `$' to anchor it
to the end of the line.
\' character if you want
Perl to treat the character "as is": [ ] ( ) . ^ { } $ * ? + \ |
\' characters for character escaping
or when the `\' is used for special Perl character matching sequences (eg.
\s \w \S ).
#' character. Anything
after, and including, the '#' character is ignored, up to the end of line.
You might be thinking that the above is quite-a-bit-of-stuff just for doing manpage section heads. However, you'll be surprised how much better the HTML output looks with header tags, even though, everything else is in a <PRE> tag.
man2html allows the ability to link to other manpages referenced. If the -cgiurl
option is specified, man2html will create anchors that link to other manpages.
The URL entered with the -cgiurl option is actually a template that determines the actual URL used to link to other manpages. The following variables are defined during run time that may be used in the template string:
$title : The title of the manual page referenced.
$section: The section number of the manual page referenced.
$subsection: The subsection of the manual page referenced.
man2html evaluates the template string as a Perl expression. Therefore,
one might need to surround the variable names with '{}' (eg. ${title})
so man2html properly recognizes the variable.
man2html is actuall a shell script or a Perl
program, make sure to properly escape the '$' character in the URL
template to avoid variable interpolation by the CGI program.
man.cgi?$section$subsection+$title
If the ls(1) manpage is referenced in the 'SEE ALSO' section, the above template
will translate to the following URL:
man.cgi?1+ls
The actual HTML markup will look like the following:
<A HREF="man.cgi?1+ls">ls(1)</A>
http://foo.org/man$section/$title.$section$subsection.html
If the mount(1M) manpage is referenced, the above template will translate to the
following URL:
http://foo.org/man1/mount.1M.html
The actual HTML markup will look like the following:
<A HREF="http://foo.org/man1/mount.1M.html">mount(1M)</A>
man2html has the ability to process output generated from "man -k", or a
keyword search. The options -k and -cgiurl must be specified inorder for
man2html to parse the input as a keyword search. man2html will generate an
HTML document of the keyword search with the following format:
man(1). Even if you have statically converted manpages to
HTML via another man->HTML program, you can use man2html, and "man -k",
to provide keyword search capabilites easily for your HTML manpages.
-leftm 1 -topm 8
-sun
man2html depaginates the text. To avoid this
problem man2html keeps track of the margin indent right before, and
after, a page break. If the margin width of the line after the page break is
less than the line before the page break, man2html inserts a blank line in
the HTML output.
[A-z.-+_]+([0-9][A-z]?)
man2html only recognizes lines with " - " (the normal separator between
manpage references and summary text) while in keyword search mode.
man2html can be hooked in a CGI script/program to convert manpages
on the fly. This is the reason for the -cgiurl option.