Pod-HtmlHelp
view release on metacpan or search on metacpan
$ignore = 1; # whether or not to format text. we don't
# format text until we hit our first pod
# directive.
@items_seen = ();
%items_named = ();
$netscape = 0; # whether or not to use netscape directives.
$title = ''; # title to give the pod(s)
$top = 1; # true if we are at the top of the doc. used
# to prevent the first <HR> directive.
$paragraph = ''; # which paragraph we're processing (used
# for error messages)
%sections = (); # sections within this page
# These are not reinitialised here but are kept as a cache.
# See get_cache and related cache management code.
#%pages = (); # associative array used to find the location
# of pages referenced by L<> links.
#%items = (); # associative array used to find the location
# of =item directives referenced by C<> links
$Is83=$^O eq 'dos';
}
my $hashead;
sub pod2html {
local(@ARGV) = @_;
local($/);
local $_;
init_globals();
$Is83 = 0 if (defined (&Dos::UseLFN) && Dos::UseLFN());
# cache of %pages and %items from last time we ran pod2html
#undef $opt_help if defined $opt_help;
# parse the command-line parameters
parse_command_line();
# Setup the stylsheet link if one was provided
$csslink = qq(<link rel="stylesheet" href="$css" type="text/css">)
if $css;
# set some variables to their default values if necessary
local *POD;
unless (@ARGV && $ARGV[0]) {
$podfile = "-" unless $podfile; # stdin
open(POD, "<$podfile")
|| die "$0: cannot open $podfile file for input: $!\n";
} else {
$podfile = $ARGV[0]; # XXX: might be more filenames
*POD = *ARGV;
}
$htmlfile = "-" unless $htmlfile; # stdout
$htmlroot = "" if $htmlroot eq "/"; # so we don't get a //
# read the pod a paragraph at a time
warn "Scanning for sections in input file(s)\n" if $verbose;
$/ = "";
my @poddata = <POD>;
close(POD);
# scan the pod for =head[1-6] directives and build an index
my $index = scan_headings(\%sections, @poddata);
unless($index) {
warn "No pod in $podfile\n" if $verbose;
return;
}
# open the output file
open(HTML, ">$htmlfile")
|| die "$0: cannot open $htmlfile file for output: $!\n";
# put a title in the HTML file if one wasn't specified
if ($title eq '') {
TITLE_SEARCH: {
for (my $i = 0; $i < @poddata; $i++) {
if ($poddata[$i] =~ /^=head1\s*(NAME|\Q¦WºÙ\E)/m) {
for my $para ( @poddata[$i, $i+1] ) {
last TITLE_SEARCH
if ($title) = $para =~ /(\S+\s+-+.*\S)/s;
}
}
}
}
}
if (!$title and $podfile =~ /\.pod$/) {
$doindex = 0; # XXX autrijus
# probably a split pod so take first =head[12] as title
# for (my $i = 0; $i < @poddata; $i++) {
# last if ($title) = $poddata[$i] =~ /^=head[12]\s*(.*)/;
# }
# warn "adopted '$title' as title for $podfile\n"
# if $verbose and $title;
}
if ($title) {
$title =~ s/\s*\(.*\)//;
} else {
$hashead = grep { /^=head1\s/ } @poddata;
# warn "$0: no title for $podfile";
# $podfile =~ /^(.*)(\.[^.\/]+)?$/;
# $title = ($podfile eq "-" ? 'No Title' : $1);
# warn "using $title" if $verbose;
}
my $charset = qq(
<meta Http-Equiv="Content-Type" Content="text/html; charset=big5">
) if $htmlfile =~ /zh[-_]tw/;
my $h1 = $title ? "<H1>$title</H1>" : '';
print HTML <<END_OF_HEAD;
<HTML>
<HEAD>
<TITLE>$title</TITLE>
<LINK REV="made" HREF="mailto:autrijus\@autrijus.org">
$charset
$csslink
</HEAD><BODY>
( run in 0.857 second using v1.01-cache-2.11-cpan-364913b4093 )