⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 html.pm

📁 UNIX下perl实现代码
💻 PM
📖 第 1 页 / 共 4 页
字号:
package Pod::Html;use strict;require Exporter;use vars qw($VERSION @ISA @EXPORT);$VERSION = 1.03;@ISA = qw(Exporter);@EXPORT = qw(pod2html htmlify);use Carp;use Config;use Cwd;use File::Spec::Unix;use Getopt::Long;use Pod::Functions;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 ARGUMENTSPod::Html takes the following arguments:=over 4=item backlink    --backlink="Back to Top"Adds "Back to Top" links in front of every HEAD1 heading (except forthe first).  By default, no backlink are being generated.=item css    --css=stylesheetSpecify the URL of a cascading style sheet.=item flush    --flushFlushes the item and directory caches.=item header    --header    --noheaderCreates header and footer blocks containing the text of the NAMEsection.  By default, no headers are being generated.=item help    --helpDisplays the usage message.=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    --nonetscapeUse Netscape HTML directives when applicable.  By default, they willB<not> be used.=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=head1 EXAMPLE    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");=head1 ENVIRONMENTUses $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 $cache_ext = $^O eq 'VMS' ? ".tmp" : ".x~~";my $dircache = "pod2htmd$cache_ext";my $itemcache = "pod2htmi$cache_ext";my @begin_stack = ();		# begin/end stackmy @libpods = ();	    	# files to search for links from C<> directivesmy $htmlroot = "/";	    	# http-server base directory from which all				#   relative paths in $podpath stem.my $htmldir = "";		# The directory to which the html pages				# will (eventually) be written.my $htmlfile = "";		# write to stdout by defaultmy $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.my $podfile = "";		# read from stdin by defaultmy @podpath = ();		# list of directories containing library pods.my $podroot = ".";		# filesystem base directory from which all				#   relative paths in $podpath stem.my $css = '';                   # Cascading style sheetmy $recurse = 1;		# recurse on subdirectories in $podpath.my $quiet = 0;			# not quiet by defaultmy $verbose = 0;		# not verbose by defaultmy $doindex = 1;   	    	# non-zero if we should generate an indexmy $backlink = '';              # text for "back to top" linksmy $listlevel = 0;		# current list depthmy @listend = ();		# the text to use to end the list.my $after_lpar = 0;             # set to true after a par in an =itemmy $ignore = 1;			# whether or not to format text.  we don't				#   format text until we hit our first pod				#   directive.my %items_named = ();		# for the multiples of the same item in perlfuncmy @items_seen = ();my $netscape = 0;		# whether or not to use netscape directives.my $title;			# title to give the pod(s)my $header = 0;			# produce block header/footermy $top = 1;			# true if we are at the top of the doc.  used				#   to prevent the first <HR> directive.my $paragraph;			# which paragraph we're processing (used				#   for error messages)my $ptQuote = 0;                # status of double-quote conversionmy %pages = ();			# associative array used to find the location				#   of pages referenced by L<> links.my %sections = ();		# sections within this pagemy %items = ();			# associative array used to find the location				#   of =item directives referenced by C<> linksmy %local_items = ();           # local items - avoid destruction of %itemsmy $Is83;                       # is dos with short filenames (8.3)sub init_globals {$dircache = "pod2htmd$cache_ext";$itemcache = "pod2htmi$cache_ext";@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$podfile = "";		# read from stdin by default@podpath = ();		# list of directories containing library pods.$podroot = ".";		# 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 = ();%items_named = ();$netscape = 0;		# whether or not to use netscape directives.$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# 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%local_items = ();$Is83=$^O eq 'dos';}## clean_data: global clean-up of pod data#sub clean_data($){    my( $dataref ) = @_;    my $i;    for( $i = 0; $i <= $#$dataref; $i++ ){	${$dataref}[$i] =~ s/\s+\Z//;        # have a look for all-space lines	if( ${$dataref}[$i] =~ /^\s+$/m ){	    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();    # 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);    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;    }     if ($title) {	$title =~ s/\s*\(.*\)//;    } else {	warn "$0: no title for $podfile" unless $quiet;	$podfile =~ /^(.*)(\.[^.\/]+)?\z/s;	$title = ($podfile eq "-" ? 'No Title' : $1);	warn "using $title" if $verbose;    }    my $csslink = $css ? qq(\n<LINK REL="stylesheet" HREF="$css" TYPE="text/css">) : '';    $csslink =~ s,\\,/,g;    $csslink =~ s,(/.):,$1|,;    my $block = $header ? <<END_OF_BLOCK : '';<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%><TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc"><FONT SIZE=+1><STRONG><P CLASS=block>&nbsp;$title</P></STRONG></FONT></TD></TR></TABLE>END_OF_BLOCK    print HTML <<END_OF_HEAD;<HTML><HEAD><TITLE>$title</TITLE>$csslink<LINK REV="made" HREF="mailto:$Config{perladmin}"></HEAD><BODY>$blockEND_OF_HEAD    # load/reload/validate/cache %pages and %items    get_cache($dircache, $itemcache, \@podpath, $podroot, $recurse);    # scan the pod for =item directives    scan_items( \%local_items, "", @poddata);    # put an index at the top of the file.  note, if $doindex is 0 we    # still generate an index, but surround it with an html comment.    # that way some other program can extract it if desired.    $index =~ s/--+/-/g;    print HTML "<A NAME=\"__index__\"></A>\n";    print HTML "<!-- INDEX BEGIN -->\n";    print HTML "<!--\n" unless $doindex;    print HTML $index;    print HTML "-->\n" unless $doindex;    print HTML "<!-- INDEX END -->\n\n";    print HTML "<HR>\n" if $doindex and $index;    # now convert this file    my $after_item;             # set to true after an =item    warn "Converting input file $podfile\n" if $verbose;    foreach my $i (0..$#poddata){        $ptQuote = 0; # status of quote conversion	$_ = $poddata[$i];	$paragraph = $i+1;	if (/^(=.*)/s) {	# is it a pod directive?	    $ignore = 0;	    $after_item = 0;	    $_ = $1;	    if (/^=begin\s+(\S+)\s*(.*)/si) {# =begin		process_begin($1, $2);	    } elsif (/^=end\s+(\S+)\s*(.*)/si) {# =end		process_end($1, $2);	    } elsif (/^=cut/) {			# =cut		process_cut();	    } elsif (/^=pod/) {			# =pod		process_pod();	    } else {		next if @begin_stack && $begin_stack[-1] ne 'html';		if (/^=(head[1-6])\s+(.*\S)/s) {	# =head[1-6] heading		    process_head( $1, $2, $doindex && $index );		} elsif (/^=item\s*(.*\S)?/sm) {	# =item text		    warn "$0: $podfile: =item without bullet, number or text"		       . " in paragraph $paragraph.\n" if !defined($1) or $1 eq '';		    process_item( $1 );		    $after_item = 1;		} elsif (/^=over\s*(.*)/) {		# =over N		    process_over();		} elsif (/^=back/) {		# =back		    process_back();		} elsif (/^=for\s+(\S+)\s*(.*)/si) {# =for		    process_for($1,$2);		} else {		    /^=(\S*)\s*/;		    warn "$0: $podfile: unknown pod directive '$1' in "		       . "paragraph $paragraph.  ignoring.\n";		}	    }	    $top = 0;	}	else {	    next if $ignore;	    next if @begin_stack && $begin_stack[-1] ne 'html';	    my $text = $_;	    if( $text =~ /\A\s+/ ){		process_pre( \$text );	        print HTML "<PRE>\n$text</PRE>\n";	    } else {		process_text( \$text );		# experimental: check for a paragraph where all lines		# have some ...\t...\t...\n pattern		if( $text =~ /\t/ ){		    my @lines = split( "\n", $text );		    if( @lines > 1 ){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -