📄 html.pm
字号:
package Pod::Html;use strict;require Exporter;use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);$VERSION = 1.08;@ISA = qw(Exporter);@EXPORT = qw(pod2html htmlify);@EXPORT_OK = qw(anchorify);use Carp;use Config;use Cwd;use File::Spec;use File::Spec::Unix;use Getopt::Long;use locale; # make \w work right in non-ASCII lands=head1 NAMEPod::Html - module to convert pod files to HTML=head1 SYNOPSIS use Pod::Html; pod2html([options]);=head1 DESCRIPTIONConverts files from pod format (see L<perlpod>) to HTML format. Itcan automatically generate indexes and cross-references, and it keepsa cache of things it knows how to cross-reference.=head1 FUNCTIONS=head2 pod2html pod2html("pod2html", "--podpath=lib:ext:pod:vms", "--podroot=/usr/src/perl", "--htmlroot=/perl/nmanual", "--libpods=perlfunc:perlguts:perlvar:perlrun:perlop", "--recurse", "--infile=foo.pod", "--outfile=/perl/nmanual/foo.html");pod2html takes the following arguments:=over 4=item backlink --backlink="Back to Top"Adds "Back to Top" links in front of every C<head1> heading (except forthe first). By default, no backlinks are generated.=item cachedir --cachedir=nameCreates the item and directory caches in the given directory.=item css --css=stylesheetSpecify the URL of a cascading style sheet. Also disables all HTML/CSSC<style> attributes that are output by default (to avoid conflicts).=item flush --flushFlushes the item and directory caches.=item header --header --noheaderCreates header and footer blocks containing the text of the C<NAME>section. By default, no headers are generated.=item help --helpDisplays the usage message.=item hiddendirs --hiddendirs --nohiddendirsInclude hidden directories in the search for POD's in podpath if recurseis set.The default is not to traverse any directory whose name begins with C<.>.See L</"podpath"> and L</"recurse">.[This option is for backward compatibility only.It's hard to imagine that one would usefully create a module with aname component beginning with C<.>.]=item htmldir --htmldir=nameSets the directory in which the resulting HTML file is placed. Thisis used to generate relative links to other files. Not passing thiscauses all links to be absolute, since this is the value that tellsPod::Html the root of the documentation tree.=item htmlroot --htmlroot=nameSets the base URL for the HTML files. When cross-references are made,the HTML root is prepended to the URL.=item index --index --noindexGenerate an index at the top of the HTML file. This is the defaultbehaviour.=item infile --infile=nameSpecify the pod file to convert. Input is taken from STDIN if noinfile is specified.=item libpods --libpods=name:...:nameList of page names (eg, "perlfunc") which contain linkable C<=item>s.=item netscape --netscape --nonetscapeB<Deprecated>, has no effect. For backwards compatibility only.=item outfile --outfile=nameSpecify the HTML file to create. Output goes to STDOUT if no outfileis specified.=item podpath --podpath=name:...:nameSpecify which subdirectories of the podroot contain pod files whoseHTML converted forms can be linked to in cross references.=item podroot --podroot=nameSpecify the base directory for finding library pods.=item quiet --quiet --noquietDon't display I<mostly harmless> warning messages. These messageswill be displayed by default. But this is not the same as C<verbose>mode.=item recurse --recurse --norecurseRecurse into subdirectories specified in podpath (default behaviour).=item title --title=titleSpecify the title of the resulting HTML file.=item verbose --verbose --noverboseDisplay progress messages. By default, they won't be displayed.=back=head2 htmlify htmlify($heading);Converts a pod section specification to a suitable section specificationfor HTML. Note that we keep spaces and special characters except C<", ?> (Netscape problem) and the hyphen (writer's problem...).=head2 anchorify anchorify(@heading);Similar to C<htmlify()>, but turns non-alphanumerics into underscores. Notethat C<anchorify()> is not exported by default.=head1 ENVIRONMENTUses C<$Config{pod2html}> to setup default options.=head1 AUTHORTom Christiansen, E<lt>tchrist@perl.comE<gt>.=head1 SEE ALSOL<perlpod>=head1 COPYRIGHTThis program is distributed under the Artistic License.=cutmy($Cachedir);my($Dircache, $Itemcache);my @Begin_Stack;my @Libpods;my($Htmlroot, $Htmldir, $Htmlfile, $Htmlfileurl);my($Podfile, @Podpath, $Podroot);my $Css;my $Recurse;my $Quiet;my $HiddenDirs;my $Verbose;my $Doindex;my $Backlink;my($Listlevel, @Listend);my $After_Lpar;use vars qw($Ignore); # need to localize it later.my(%Items_Named, @Items_Seen);my($Title, $Header);my $Top;my $Paragraph;my %Sections;# Cachesmy %Pages = (); # associative array used to find the location # of pages referenced by L<> links.my %Items = (); # associative array used to find the location # of =item directives referenced by C<> linksmy %Local_Items;my $Is83;my $Curdir = File::Spec->curdir;init_globals();sub init_globals { $Cachedir = "."; # The directory to which item and directory # caches will be written. $Dircache = "pod2htmd.tmp"; $Itemcache = "pod2htmi.tmp"; @Begin_Stack = (); # begin/end stack @Libpods = (); # files to search for links from C<> directives $Htmlroot = "/"; # http-server base directory from which all # relative paths in $podpath stem. $Htmldir = ""; # The directory to which the html pages # will (eventually) be written. $Htmlfile = ""; # write to stdout by default $Htmlfileurl = "" ; # The url that other files would use to # refer to this file. This is only used # to make relative urls that point to # other files. $Podfile = ""; # read from stdin by default @Podpath = (); # list of directories containing library pods. $Podroot = $Curdir; # filesystem base directory from which all # relative paths in $podpath stem. $Css = ''; # Cascading style sheet $Recurse = 1; # recurse on subdirectories in $podpath. $Quiet = 0; # not quiet by default $Verbose = 0; # not verbose by default $Doindex = 1; # non-zero if we should generate an index $Backlink = ''; # text for "back to top" links $Listlevel = 0; # current list depth @Listend = (); # the text to use to end the list. $After_Lpar = 0; # set to true after a par in an =item $Ignore = 1; # whether or not to format text. we don't # format text until we hit our first pod # directive. @Items_Seen = (); # for multiples of the same item in perlfunc %Items_Named = (); $Header = 0; # produce block header/footer $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 %Local_Items = (); $Is83 = $^O eq 'dos'; # Is it an 8.3 filesystem?}## clean_data: global clean-up of pod data#sub clean_data($){ my( $dataref ) = @_; for my $i ( 0..$#{$dataref} ) { ${$dataref}[$i] =~ s/\s+\Z//; # have a look for all-space lines if( ${$dataref}[$i] =~ /^\s+$/m and $dataref->[$i] !~ /^\s/ ){ my @chunks = split( /^\s+$/m, ${$dataref}[$i] ); splice( @$dataref, $i, 1, @chunks ); } }}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(); # escape the backlink argument (same goes for title but is done later...) $Backlink = html_escape($Backlink) if defined $Backlink; # 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 // $Htmldir =~ s#/\z## ; # so we don't get a // if ( $Htmlroot eq '' && defined( $Htmldir ) && $Htmldir ne '' && substr( $Htmlfile, 0, length( $Htmldir ) ) eq $Htmldir ) { # Set the 'base' url for this file, so that we can use it # as the location from which to calculate relative links # to other files. If this is '', then absolute links will # be used throughout. $Htmlfileurl= "$Htmldir/" . substr( $Htmlfile, length( $Htmldir ) + 1); } # read the pod a paragraph at a time warn "Scanning for sections in input file(s)\n" if $Verbose; $/ = ""; my @poddata = <POD>; close(POD); # be eol agnostic for (@poddata) { if (/\r/) { if (/\r\n/) { @poddata = map { s/\r\n/\n/g; /\n\n/ ? map { "$_\n\n" } split /\n\n/ : $_ } @poddata; } else { @poddata = map { s/\r/\n/g; /\n\n/ ? map { "$_\n\n" } split /\n\n/ : $_ } @poddata; } last; } } clean_data( \@poddata ); # scan the pod for =head[1-6] directives and build an index my $index = scan_headings(\%Sections, @poddata); unless($index) { warn "No headings in $Podfile\n" if $Verbose; } # 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\b/m) { for my $para ( @poddata[$i, $i+1] ) { last TITLE_SEARCH if ($Title) = $para =~ /(\S+\s+-+.*\S)/s; } } } } } if (!$Title and $Podfile =~ /\.pod\z/) { # 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; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -