5 use vars qw($VERSION @ISA @EXPORT);
8 @EXPORT = qw(pod2html htmlify);
17 use locale; # make \w work right in non-ASCII lands
21 Pod::Html - module to convert pod files to HTML
30 Converts files from pod format (see L<perlpod>) to HTML format. It
31 can automatically generate indexes and cross-references, and it keeps
32 a cache of things it knows how to cross-reference.
36 Pod::Html takes the following arguments:
42 --backlink="Back to Top"
44 Adds "Back to Top" links in front of every HEAD1 heading (except for
45 the first). By default, no backlink are being generated.
51 Specify the URL of a cascading style sheet.
57 Flushes the item and directory caches.
64 Creates header and footer blocks containing the text of the NAME
65 section. By default, no headers are being generated.
71 Displays the usage message.
77 Sets the directory in which the resulting HTML file is placed. This
78 is used to generate relative links to other files. Not passing this
79 causes all links to be absolute, since this is the value that tells
80 Pod::Html the root of the documentation tree.
86 Sets the base URL for the HTML files. When cross-references are made,
87 the HTML root is prepended to the URL.
94 Generate an index at the top of the HTML file. This is the default
101 Specify the pod file to convert. Input is taken from STDIN if no
106 --libpods=name:...:name
108 List of page names (eg, "perlfunc") which contain linkable C<=item>s.
115 Use Netscape HTML directives when applicable. By default, they will
122 Specify the HTML file to create. Output goes to STDOUT if no outfile
127 --podpath=name:...:name
129 Specify which subdirectories of the podroot contain pod files whose
130 HTML converted forms can be linked-to in cross-references.
136 Specify the base directory for finding library pods.
143 Don't display I<mostly harmless> warning messages. These messages
144 will be displayed by default. But this is not the same as C<verbose>
152 Recurse into subdirectories specified in podpath (default behaviour).
158 Specify the title of the resulting HTML file.
165 Display progress messages. By default, they won't be displayed.
172 "--podpath=lib:ext:pod:vms",
173 "--podroot=/usr/src/perl",
174 "--htmlroot=/perl/nmanual",
175 "--libpods=perlfunc:perlguts:perlvar:perlrun:perlop",
178 "--outfile=/perl/nmanual/foo.html");
182 Uses $Config{pod2html} to setup default options.
186 Tom Christiansen, E<lt>tchrist@perl.comE<gt>.
194 This program is distributed under the Artistic License.
198 my $cache_ext = $^O eq 'VMS' ? ".tmp" : ".x~~";
199 my $dircache = "pod2htmd$cache_ext";
200 my $itemcache = "pod2htmi$cache_ext";
202 my @begin_stack = (); # begin/end stack
204 my @libpods = (); # files to search for links from C<> directives
205 my $htmlroot = "/"; # http-server base directory from which all
206 # relative paths in $podpath stem.
207 my $htmldir = ""; # The directory to which the html pages
208 # will (eventually) be written.
209 my $htmlfile = ""; # write to stdout by default
210 my $htmlfileurl = "" ; # The url that other files would use to
211 # refer to this file. This is only used
212 # to make relative urls that point to
214 my $podfile = ""; # read from stdin by default
215 my @podpath = (); # list of directories containing library pods.
216 my $podroot = "."; # filesystem base directory from which all
217 # relative paths in $podpath stem.
218 my $css = ''; # Cascading style sheet
219 my $recurse = 1; # recurse on subdirectories in $podpath.
220 my $quiet = 0; # not quiet by default
221 my $verbose = 0; # not verbose by default
222 my $doindex = 1; # non-zero if we should generate an index
223 my $backlink = ''; # text for "back to top" links
224 my $listlevel = 0; # current list depth
225 my @listend = (); # the text to use to end the list.
226 my $after_lpar = 0; # set to true after a par in an =item
227 my $ignore = 1; # whether or not to format text. we don't
228 # format text until we hit our first pod
231 my %items_named = (); # for the multiples of the same item in perlfunc
233 my $netscape = 0; # whether or not to use netscape directives.
234 my $title; # title to give the pod(s)
235 my $header = 0; # produce block header/footer
236 my $top = 1; # true if we are at the top of the doc. used
237 # to prevent the first <HR> directive.
238 my $paragraph; # which paragraph we're processing (used
239 # for error messages)
240 my $ptQuote = 0; # status of double-quote conversion
241 my %pages = (); # associative array used to find the location
242 # of pages referenced by L<> links.
243 my %sections = (); # sections within this page
244 my %items = (); # associative array used to find the location
245 # of =item directives referenced by C<> links
246 my %local_items = (); # local items - avoid destruction of %items
247 my $Is83; # is dos with short filenames (8.3)
250 $dircache = "pod2htmd$cache_ext";
251 $itemcache = "pod2htmi$cache_ext";
253 @begin_stack = (); # begin/end stack
255 @libpods = (); # files to search for links from C<> directives
256 $htmlroot = "/"; # http-server base directory from which all
257 # relative paths in $podpath stem.
258 $htmldir = ""; # The directory to which the html pages
259 # will (eventually) be written.
260 $htmlfile = ""; # write to stdout by default
261 $podfile = ""; # read from stdin by default
262 @podpath = (); # list of directories containing library pods.
263 $podroot = "."; # filesystem base directory from which all
264 # relative paths in $podpath stem.
265 $css = ''; # Cascading style sheet
266 $recurse = 1; # recurse on subdirectories in $podpath.
267 $quiet = 0; # not quiet by default
268 $verbose = 0; # not verbose by default
269 $doindex = 1; # non-zero if we should generate an index
270 $backlink = ''; # text for "back to top" links
271 $listlevel = 0; # current list depth
272 @listend = (); # the text to use to end the list.
273 $after_lpar = 0; # set to true after a par in an =item
274 $ignore = 1; # whether or not to format text. we don't
275 # format text until we hit our first pod
280 $netscape = 0; # whether or not to use netscape directives.
281 $header = 0; # produce block header/footer
282 $title = ''; # title to give the pod(s)
283 $top = 1; # true if we are at the top of the doc. used
284 # to prevent the first <HR> directive.
285 $paragraph = ''; # which paragraph we're processing (used
286 # for error messages)
287 %sections = (); # sections within this page
289 # These are not reinitialised here but are kept as a cache.
290 # See get_cache and related cache management code.
291 #%pages = (); # associative array used to find the location
292 # of pages referenced by L<> links.
293 #%items = (); # associative array used to find the location
294 # of =item directives referenced by C<> links
300 # clean_data: global clean-up of pod data
305 for( $i = 0; $i <= $#$dataref; $i++ ){
306 ${$dataref}[$i] =~ s/\s+\Z//;
308 # have a look for all-space lines
309 if( ${$dataref}[$i] =~ /^\s+$/m ){
310 my @chunks = split( /^\s+$/m, ${$dataref}[$i] );
311 splice( @$dataref, $i, 1, @chunks );
324 $Is83 = 0 if (defined (&Dos::UseLFN) && Dos::UseLFN());
326 # cache of %pages and %items from last time we ran pod2html
328 #undef $opt_help if defined $opt_help;
330 # parse the command-line parameters
331 parse_command_line();
333 # set some variables to their default values if necessary
335 unless (@ARGV && $ARGV[0]) {
336 $podfile = "-" unless $podfile; # stdin
337 open(POD, "<$podfile")
338 || die "$0: cannot open $podfile file for input: $!\n";
340 $podfile = $ARGV[0]; # XXX: might be more filenames
343 $htmlfile = "-" unless $htmlfile; # stdout
344 $htmlroot = "" if $htmlroot eq "/"; # so we don't get a //
345 $htmldir =~ s#/\z## ; # so we don't get a //
347 && defined( $htmldir )
349 && substr( $htmlfile, 0, length( $htmldir ) ) eq $htmldir
352 # Set the 'base' url for this file, so that we can use it
353 # as the location from which to calculate relative links
354 # to other files. If this is '', then absolute links will
355 # be used throughout.
356 $htmlfileurl= "$htmldir/" . substr( $htmlfile, length( $htmldir ) + 1);
359 # read the pod a paragraph at a time
360 warn "Scanning for sections in input file(s)\n" if $verbose;
364 clean_data( \@poddata );
366 # scan the pod for =head[1-6] directives and build an index
367 my $index = scan_headings(\%sections, @poddata);
370 warn "No headings in $podfile\n" if $verbose;
373 # open the output file
374 open(HTML, ">$htmlfile")
375 || die "$0: cannot open $htmlfile file for output: $!\n";
377 # put a title in the HTML file if one wasn't specified
380 for (my $i = 0; $i < @poddata; $i++) {
381 if ($poddata[$i] =~ /^=head1\s*NAME\b/m) {
382 for my $para ( @poddata[$i, $i+1] ) {
384 if ($title) = $para =~ /(\S+\s+-+.*\S)/s;
391 if (!$title and $podfile =~ /\.pod\z/) {
392 # probably a split pod so take first =head[12] as title
393 for (my $i = 0; $i < @poddata; $i++) {
394 last if ($title) = $poddata[$i] =~ /^=head[12]\s*(.*)/;
396 warn "adopted '$title' as title for $podfile\n"
397 if $verbose and $title;
400 $title =~ s/\s*\(.*\)//;
402 warn "$0: no title for $podfile" unless $quiet;
403 $podfile =~ /^(.*)(\.[^.\/]+)?\z/s;
404 $title = ($podfile eq "-" ? 'No Title' : $1);
405 warn "using $title" if $verbose;
407 my $csslink = $css ? qq(\n<LINK REL="stylesheet" HREF="$css" TYPE="text/css">) : '';
408 $csslink =~ s,\\,/,g;
409 $csslink =~ s,(/.):,$1|,;
411 my $block = $header ? <<END_OF_BLOCK : '';
412 <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
413 <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
414 <FONT SIZE=+1><STRONG><P CLASS=block> $title</P></STRONG></FONT>
419 print HTML <<END_OF_HEAD;
422 <TITLE>$title</TITLE>$csslink
423 <LINK REV="made" HREF="mailto:$Config{perladmin}">
430 # load/reload/validate/cache %pages and %items
431 get_cache($dircache, $itemcache, \@podpath, $podroot, $recurse);
433 # scan the pod for =item directives
434 scan_items( \%local_items, "", @poddata);
436 # put an index at the top of the file. note, if $doindex is 0 we
437 # still generate an index, but surround it with an html comment.
438 # that way some other program can extract it if desired.
440 print HTML "<A NAME=\"__index__\"></A>\n";
441 print HTML "<!-- INDEX BEGIN -->\n";
442 print HTML "<!--\n" unless $doindex;
444 print HTML "-->\n" unless $doindex;
445 print HTML "<!-- INDEX END -->\n\n";
446 print HTML "<HR>\n" if $doindex and $index;
448 # now convert this file
449 my $after_item; # set to true after an =item
450 warn "Converting input file $podfile\n" if $verbose;
451 foreach my $i (0..$#poddata){
452 $ptQuote = 0; # status of quote conversion
456 if (/^(=.*)/s) { # is it a pod directive?
460 if (/^=begin\s+(\S+)\s*(.*)/si) {# =begin
461 process_begin($1, $2);
462 } elsif (/^=end\s+(\S+)\s*(.*)/si) {# =end
464 } elsif (/^=cut/) { # =cut
466 } elsif (/^=pod/) { # =pod
469 next if @begin_stack && $begin_stack[-1] ne 'html';
471 if (/^=(head[1-6])\s+(.*\S)/s) { # =head[1-6] heading
472 process_head( $1, $2, $doindex && $index );
473 } elsif (/^=item\s*(.*\S)?/sm) { # =item text
474 warn "$0: $podfile: =item without bullet, number or text"
475 . " in paragraph $paragraph.\n" if !defined($1) or $1 eq '';
478 } elsif (/^=over\s*(.*)/) { # =over N
480 } elsif (/^=back/) { # =back
482 } elsif (/^=for\s+(\S+)\s*(.*)/si) {# =for
486 warn "$0: $podfile: unknown pod directive '$1' in "
487 . "paragraph $paragraph. ignoring.\n";
494 next if @begin_stack && $begin_stack[-1] ne 'html';
496 if( $text =~ /\A\s+/ ){
497 process_pre( \$text );
498 print HTML "<PRE>\n$text</PRE>\n";
501 process_text( \$text );
503 # experimental: check for a paragraph where all lines
504 # have some ...\t...\t...\n pattern
506 my @lines = split( "\n", $text );
509 foreach my $line ( @lines ){
510 if( $line =~ /\S/ && $line !~ /\t/ ){
516 $text =~ s/\t+/<TD>/g;
517 $text =~ s/^/<TR><TD>/gm;
518 $text = '<TABLE CELLSPACING=0 CELLPADDING=0>' .
523 ## end of experimental
526 print HTML "$text\n";
529 print HTML "<P>$text</P>\n";
536 # finish off any pending directives
540 print HTML "<P><A HREF=\"#__index__\"><SMALL>$backlink</SMALL></A></P>\n"
541 if $doindex and $index and $backlink;
543 print HTML <<END_OF_TAIL;
550 # close the html file
553 warn "Finished\n" if $verbose;
556 ##############################################################################
558 my $usage; # see below
561 warn "$0: $podfile: @_\n" if @_;
565 $usage =<<END_OF_USAGE;
566 Usage: $0 --help --htmlroot=<name> --infile=<name> --outfile=<name>
567 --podpath=<name>:...:<name> --podroot=<name>
568 --libpods=<name>:...:<name> --recurse --verbose --index
569 --netscape --norecurse --noindex
571 --backlink - set text for "back to top" links (default: none).
572 --css - stylesheet URL
573 --flush - flushes the item and directory caches.
574 --[no]header - produce block header/footer (default is no headers).
575 --help - prints this message.
576 --htmldir - directory for resulting HTML files.
577 --htmlroot - http-server base directory from which all relative paths
578 in podpath stem (default is /).
579 --[no]index - generate an index at the top of the resulting html
581 --infile - filename for the pod to convert (input taken from stdin
583 --libpods - colon-separated list of pages to search for =item pod
584 directives in as targets of C<> and implicit links (empty
585 by default). note, these are not filenames, but rather
586 page names like those that appear in L<> links.
587 --[no]netscape - will use netscape html directives when applicable.
588 (default is not to use them).
589 --outfile - filename for the resulting html file (output sent to
591 --podpath - colon-separated list of directories containing library
592 pods (empty by default).
593 --podroot - filesystem base directory from which all relative paths
594 in podpath stem (default is .).
595 --[no]quiet - supress some benign warning messages (default is off).
596 --[no]recurse - recurse on those subdirectories listed in podpath
598 --title - title that will appear in resulting html file.
599 --[no]verbose - self-explanatory (off by default).
603 sub parse_command_line {
604 my ($opt_backlink,$opt_css,$opt_flush,$opt_header,$opt_help,$opt_htmldir,
605 $opt_htmlroot,$opt_index,$opt_infile,$opt_libpods,$opt_netscape,
606 $opt_outfile,$opt_podpath,$opt_podroot,$opt_quiet,$opt_recurse,
607 $opt_title,$opt_verbose);
609 unshift @ARGV, split ' ', $Config{pod2html} if $Config{pod2html};
610 my $result = GetOptions(
611 'backlink=s' => \$opt_backlink,
612 'css=s' => \$opt_css,
613 'flush' => \$opt_flush,
614 'header!' => \$opt_header,
615 'help' => \$opt_help,
616 'htmldir=s' => \$opt_htmldir,
617 'htmlroot=s' => \$opt_htmlroot,
618 'index!' => \$opt_index,
619 'infile=s' => \$opt_infile,
620 'libpods=s' => \$opt_libpods,
621 'netscape!' => \$opt_netscape,
622 'outfile=s' => \$opt_outfile,
623 'podpath=s' => \$opt_podpath,
624 'podroot=s' => \$opt_podroot,
625 'quiet!' => \$opt_quiet,
626 'recurse!' => \$opt_recurse,
627 'title=s' => \$opt_title,
628 'verbose!' => \$opt_verbose,
630 usage("-", "invalid parameters") if not $result;
632 usage("-") if defined $opt_help; # see if the user asked for help
633 $opt_help = ""; # just to make -w shut-up.
635 @podpath = split(":", $opt_podpath) if defined $opt_podpath;
636 @libpods = split(":", $opt_libpods) if defined $opt_libpods;
638 $backlink = $opt_backlink if defined $opt_backlink;
639 $css = $opt_css if defined $opt_css;
640 $header = $opt_header if defined $opt_header;
641 $htmldir = $opt_htmldir if defined $opt_htmldir;
642 $htmlroot = $opt_htmlroot if defined $opt_htmlroot;
643 $doindex = $opt_index if defined $opt_index;
644 $podfile = $opt_infile if defined $opt_infile;
645 $netscape = $opt_netscape if defined $opt_netscape;
646 $htmlfile = $opt_outfile if defined $opt_outfile;
647 $podroot = $opt_podroot if defined $opt_podroot;
648 $quiet = $opt_quiet if defined $opt_quiet;
649 $recurse = $opt_recurse if defined $opt_recurse;
650 $title = $opt_title if defined $opt_title;
651 $verbose = $opt_verbose if defined $opt_verbose;
653 warn "Flushing item and directory caches\n"
654 if $opt_verbose && defined $opt_flush;
655 unlink($dircache, $itemcache) if defined $opt_flush;
662 my($dircache, $itemcache, $podpath, $podroot, $recurse) = @_;
663 my @cache_key_args = @_;
665 # A first-level cache:
666 # Don't bother reading the cache files if they still apply
667 # and haven't changed since we last read them.
669 my $this_cache_key = cache_key(@cache_key_args);
671 return if $saved_cache_key and $this_cache_key eq $saved_cache_key;
673 # load the cache of %pages and %items if possible. $tests will be
674 # non-zero if successful.
676 if (-f $dircache && -f $itemcache) {
677 warn "scanning for item cache\n" if $verbose;
678 $tests = load_cache($dircache, $itemcache, $podpath, $podroot);
681 # if we didn't succeed in loading the cache then we must (re)build
684 warn "scanning directories in pod-path\n" if $verbose;
685 scan_podpath($podroot, $recurse, 0);
687 $saved_cache_key = cache_key(@cache_key_args);
691 my($dircache, $itemcache, $podpath, $podroot, $recurse) = @_;
692 return join('!', $dircache, $itemcache, $recurse,
693 @$podpath, $podroot, stat($dircache), stat($itemcache));
697 # load_cache - tries to find if the caches stored in $dircache and $itemcache
698 # are valid caches of %pages and %items. if they are valid then it loads
699 # them and returns a non-zero value.
702 my($dircache, $itemcache, $podpath, $podroot) = @_;
708 open(CACHE, "<$itemcache") ||
709 die "$0: error opening $itemcache for reading: $!\n";
712 # is it the same podpath?
715 $tests++ if (join(":", @$podpath) eq $_);
717 # is it the same podroot?
720 $tests++ if ($podroot eq $_);
722 # load the cache if its good
728 warn "loading item cache\n" if $verbose;
735 warn "scanning for directory cache\n" if $verbose;
736 open(CACHE, "<$dircache") ||
737 die "$0: error opening $dircache for reading: $!\n";
741 # is it the same podpath?
744 $tests++ if (join(":", @$podpath) eq $_);
746 # is it the same podroot?
749 $tests++ if ($podroot eq $_);
751 # load the cache if its good
757 warn "loading directory cache\n" if $verbose;
769 # scan_podpath - scans the directories specified in @podpath for directories,
770 # .pod files, and .pm files. it also scans the pod files specified in
771 # @libpods for =item directives.
774 my($podroot, $recurse, $append) = @_;
776 my($libpod, $dirname, $pod, @files, @poddata);
783 # scan each directory listed in @podpath
786 || die "$0: error changing to directory $podroot: $!\n";
787 foreach $dir (@podpath) {
788 scan_dir($dir, $recurse);
791 # scan the pods listed in @libpods for =item directives
792 foreach $libpod (@libpods) {
793 # if the page isn't defined then we won't know where to find it
795 next unless defined $pages{$libpod} && $pages{$libpod};
797 # if there is a directory then use the .pod and .pm files within it.
798 # NOTE: Only finds the first so-named directory in the tree.
799 # if ($pages{$libpod} =~ /([^:]*[^(\.pod|\.pm)]):/) {
800 if ($pages{$libpod} =~ /([^:]*(?<!\.pod)(?<!\.pm)):/) {
801 # find all the .pod and .pm files within the directory
803 opendir(DIR, $dirname) ||
804 die "$0: error opening directory $dirname: $!\n";
805 @files = grep(/(\.pod|\.pm)\z/ && ! -d $_, readdir(DIR));
808 # scan each .pod and .pm file for =item directives
809 foreach $pod (@files) {
810 open(POD, "<$dirname/$pod") ||
811 die "$0: error opening $dirname/$pod for input: $!\n";
814 clean_data( \@poddata );
816 scan_items( \%items, "$dirname/$pod", @poddata);
819 # use the names of files as =item directives too.
820 ### Don't think this should be done this way - confuses issues.(WL)
821 ### foreach $pod (@files) {
822 ### $pod =~ /^(.*)(\.pod|\.pm)$/;
823 ### $items{$1} = "$dirname/$1.html" if $1;
825 } elsif ($pages{$libpod} =~ /([^:]*\.pod):/ ||
826 $pages{$libpod} =~ /([^:]*\.pm):/) {
827 # scan the .pod or .pm file for =item directives
829 open(POD, "<$pod") ||
830 die "$0: error opening $pod for input: $!\n";
833 clean_data( \@poddata );
835 scan_items( \%items, "$pod", @poddata);
837 warn "$0: shouldn't be here (line ".__LINE__."\n";
840 @poddata = (); # clean-up a bit
843 || die "$0: error changing to directory $pwd: $!\n";
845 # cache the item list for later use
846 warn "caching items for later use\n" if $verbose;
847 open(CACHE, ">$itemcache") ||
848 die "$0: error open $itemcache for writing: $!\n";
850 print CACHE join(":", @podpath) . "\n$podroot\n";
851 foreach my $key (keys %items) {
852 print CACHE "$key $items{$key}\n";
857 # cache the directory list for later use
858 warn "caching directories for later use\n" if $verbose;
859 open(CACHE, ">$dircache") ||
860 die "$0: error open $dircache for writing: $!\n";
862 print CACHE join(":", @podpath) . "\n$podroot\n";
863 foreach my $key (keys %pages) {
864 print CACHE "$key $pages{$key}\n";
871 # scan_dir - scans the directory specified in $dir for subdirectories, .pod
872 # files, and .pm files. notes those that it finds. this information will
873 # be used later in order to figure out where the pages specified in L<>
874 # links are on the filesystem.
877 my($dir, $recurse) = @_;
878 my($t, @subdirs, @pods, $pod, $dirname, @dirs);
884 opendir(DIR, $dir) ||
885 die "$0: error opening directory $dir: $!\n";
886 while (defined($_ = readdir(DIR))) {
887 if (-d "$dir/$_" && $_ ne "." && $_ ne "..") { # directory
888 $pages{$_} = "" unless defined $pages{$_};
889 $pages{$_} .= "$dir/$_:";
891 } elsif (/\.pod\z/) { # .pod
893 $pages{$_} = "" unless defined $pages{$_};
894 $pages{$_} .= "$dir/$_.pod:";
895 push(@pods, "$dir/$_.pod");
896 } elsif (/\.pm\z/) { # .pm
898 $pages{$_} = "" unless defined $pages{$_};
899 $pages{$_} .= "$dir/$_.pm:";
900 push(@pods, "$dir/$_.pm");
905 # recurse on the subdirectories if necessary
907 foreach my $subdir (@subdirs) {
908 scan_dir("$dir/$subdir", $recurse);
914 # scan_headings - scan a pod file for head[1-6] tags, note the tags, and
918 my($sections, @data) = @_;
919 my($tag, $which_head, $otitle, $listdepth, $index);
921 # here we need local $ignore = 0;
922 # unfortunately, we can't have it, because $ignore is lexical
928 # scan for =head directives, note their name, and build an index
929 # pointing to each of them.
930 foreach my $line (@data) {
931 if ($line =~ /^=(head)([1-6])\s+(.*)/) {
932 ($tag, $which_head, $otitle) = ($1,$2,$3);
934 my $title = depod( $otitle );
935 my $name = htmlify( $title );
936 $$sections{$name} = 1;
937 $title = process_text( \$otitle );
939 while ($which_head != $listdepth) {
940 if ($which_head > $listdepth) {
941 $index .= "\n" . ("\t" x $listdepth) . "<UL>\n";
943 } elsif ($which_head < $listdepth) {
945 $index .= "\n" . ("\t" x $listdepth) . "</UL>\n";
949 $index .= "\n" . ("\t" x $listdepth) . "<LI>" .
950 "<A HREF=\"#" . $name . "\">" .
951 $title . "</A></LI>";
955 # finish off the lists
956 while ($listdepth--) {
957 $index .= "\n" . ("\t" x $listdepth) . "</UL>\n";
960 # get rid of bogus lists
961 $index =~ s,\t*<UL>\s*</UL>\n,,g;
963 $ignore = 1; # restore old value;
969 # scan_items - scans the pod specified by $pod for =item directives. we
970 # will use this information later on in resolving C<> links.
973 my( $itemref, $pod, @poddata ) = @_;
978 $pod .= ".html" if $pod;
980 foreach $i (0..$#poddata) {
981 my $txt = depod( $poddata[$i] );
983 # figure out what kind of item it is.
984 # Build string for referencing this item.
985 if ( $txt =~ /\A=item\s+\*\s*(.*)\Z/s ) { # bullet
988 } elsif( $txt =~ /\A=item\s+(?>\d+\.?)\s*(.*)\Z/s ) { # numbered list
990 } elsif( $txt =~ /\A=item\s+(.*)\Z/s ) { # plain item
995 my $fid = fragment_id( $item );
996 $$itemref{$fid} = "$pod" if $fid;
1001 # process_head - convert a pod head[1-6] tag and convert it to HTML format.
1004 my($tag, $heading, $hasindex) = @_;
1006 # figure out the level of the =head
1007 $tag =~ /head([1-6])/;
1011 warn "$0: $podfile: unterminated list at =head in paragraph $paragraph. ignoring.\n";
1012 while( $listlevel ){
1018 if( $level == 1 && ! $top ){
1019 print HTML "<A HREF=\"#__index__\"><SMALL>$backlink</SMALL></A>\n"
1020 if $hasindex and $backlink;
1024 my $name = htmlify( depod( $heading ) );
1025 my $convert = process_text( \$heading );
1026 print HTML "<H$level><A NAME=\"$name\">$convert</A></H$level>\n";
1031 # emit_item_tag - print an =item's text
1032 # Note: The global $EmittedItem is used for inhibiting self-references.
1036 sub emit_item_tag($$$){
1037 my( $otext, $text, $compact ) = @_;
1038 my $item = fragment_id( $text );
1040 $EmittedItem = $item;
1041 ### print STDERR "emit_item_tag=$item ($text)\n";
1043 print HTML '<STRONG>';
1044 if ($items_named{$item}++) {
1045 print HTML process_text( \$otext );
1047 my $name = 'item_' . $item;
1048 print HTML qq{<A NAME="$name">}, process_text( \$otext ), '</A>';
1050 print HTML "</STRONG><BR>\n";
1051 undef( $EmittedItem );
1056 if( $items_seen[$listlevel]++ == 0 ){
1057 push( @listend, "</$tag>" );
1058 print HTML "<$tag>\n";
1060 print HTML $tag eq 'DL' ? '<DT>' : '<LI>';
1064 # process_item - convert a pod item tag and convert it to HTML format.
1069 # lots of documents start a list without doing an =over. this is
1070 # bad! but, the proper thing to do seems to be to just assume
1071 # they did do an =over. so warn them once and then continue.
1072 if( $listlevel == 0 ){
1073 warn "$0: $podfile: unexpected =item directive in paragraph $paragraph. ignoring.\n";
1077 # formatting: insert a paragraph if preceding item has >1 paragraph
1079 print HTML "<P></P>\n";
1083 # remove formatting instructions from the text
1084 my $text = depod( $otext );
1086 # all the list variants:
1087 if( $text =~ /\A\*/ ){ # bullet
1089 if ($text =~ /\A\*\s+(.+)\Z/s ) { # with additional text
1091 $otext =~ s/\A\*\s+//;
1092 emit_item_tag( $otext, $tag, 1 );
1095 } elsif( $text =~ /\A\d+/ ){ # numbered list
1097 if ($text =~ /\A(?>\d+\.?)\s*(.+)\Z/s ) { # with additional text
1099 $otext =~ s/\A\d+\.?\s*//;
1100 emit_item_tag( $otext, $tag, 1 );
1103 } else { # definition list
1105 if ($text =~ /\A(.+)\Z/s ){ # should have text
1106 emit_item_tag( $otext, $text, 1 );
1114 # process_over - process a pod over tag and start a corresponding HTML list.
1119 push( @items_seen, 0 );
1124 # process_back - process a pod back tag and convert it to HTML format.
1127 if( $listlevel == 0 ){
1128 warn "$0: $podfile: unexpected =back directive in paragraph $paragraph. ignoring.\n";
1132 # close off the list. note, I check to see if $listend[$listlevel] is
1133 # defined because an =item directive may have never appeared and thus
1134 # $listend[$listlevel] may have never been initialized.
1136 if( defined $listend[$listlevel] ){
1137 print HTML '<P></P>' if $after_lpar;
1138 print HTML $listend[$listlevel];
1144 # clean up item count
1149 # process_cut - process a pod cut tag, thus start ignoring pod directives.
1156 # process_pod - process a pod pod tag, thus stop ignoring pod directives
1157 # until we see a corresponding cut.
1160 # no need to set $ignore to 0 cause the main loop did it
1164 # process_for - process a =for pod tag. if it's for html, spit
1165 # it out verbatim, if illustration, center it, otherwise ignore it.
1168 my($whom, $text) = @_;
1169 if ( $whom =~ /^(pod2)?html$/i) {
1171 } elsif ($whom =~ /^illustration$/i) {
1172 1 while chomp $text;
1173 for my $ext (qw[.png .gif .jpeg .jpg .tga .pcl .bmp]) {
1174 $text .= $ext, last if -r "$text$ext";
1176 print HTML qq{<p align = "center"><img src = "$text" alt = "$text illustration"></p>};
1181 # process_begin - process a =begin pod tag. this pushes
1182 # whom we're beginning on the begin stack. if there's a
1183 # begin stack, we only print if it us.
1186 my($whom, $text) = @_;
1188 push (@begin_stack, $whom);
1189 if ( $whom =~ /^(pod2)?html$/) {
1190 print HTML $text if $text;
1195 # process_end - process a =end pod tag. pop the
1196 # begin stack. die if we're mismatched.
1199 my($whom, $text) = @_;
1201 if ($begin_stack[-1] ne $whom ) {
1202 die "Unmatched begin/end at chunk $paragraph\n"
1204 pop( @begin_stack );
1208 # process_pre - indented paragraph, made into <PRE></PRE>
1217 # insert spaces in place of tabs
1220 1 while $line =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e;
1224 # convert some special chars to HTML escapes
1225 $rest =~ s/&/&/g;
1226 $rest =~ s/</</g;
1227 $rest =~ s/>/>/g;
1228 $rest =~ s/"/"/g;
1230 # try and create links for all occurrences of perl.* within
1231 # the preformatted text.
1235 if ( defined $pages{$2} ){ # is a link
1236 qq($1<A HREF="$htmlroot/$pages{$2}">$2</A>);
1237 } elsif (defined $pages{dosify($2)}) { # is a link
1238 qq($1<A HREF="$htmlroot/$pages{dosify($2)}">$2</A>);
1244 (<A\ HREF="?) ([^>:]*:)? ([^>:]*) \.pod: ([^>:]*:)?
1247 if ( $htmlfileurl ne '' ){
1248 # Here, we take advantage of the knowledge
1249 # that $htmlfileurl ne '' implies $htmlroot eq ''.
1250 # Since $htmlroot eq '', we need to prepend $htmldir
1251 # on the fron of the link to get the absolute path
1252 # of the link's target. We check for a leading '/'
1253 # to avoid corrupting links that are #, file:, etc.
1255 $old_url = "$htmldir$old_url" if $old_url =~ m{^\/};
1256 $url = relativize_url( "$old_url.html", $htmlfileurl );
1263 # Look for embedded URLs and make them into links. We don't
1264 # relativize them since they are best left as the author intended.
1266 my $urls = '(' . join ('|', qw{
1279 my $gunk = '/#~:.?+=&%@!\-';
1281 my $any = "${ltrs}${gunk}${punc}";
1284 \b # start at word boundary
1286 $urls : # need resource and a colon
1287 (?!:) # Ignore File::, among others.
1288 [$any] +? # followed by on or more
1289 # of any valid character, but
1290 # be conservative and take only
1291 # what you need to....
1293 (?= # look-ahead non-consumptive assertion
1294 [$punc]* # either 0 or more puntuation
1295 [^$any] # followed by a non-url char
1297 $ # then end of the string
1299 }{<A HREF="$1">$1</A>}igox;
1301 # text should be as it is (verbatim)
1307 # pure text processing
1309 # pure_text/inIS_text: differ with respect to automatic C<> recognition.
1310 # we don't want this to happen within IS
1314 process_puretext( $text, \$ptQuote, 1 );
1319 process_puretext( $text, \$ptQuote, 0 );
1323 # process_puretext - process pure text (without pod-escapes) converting
1324 # double-quotes and handling implicit C<> links.
1326 sub process_puretext {
1327 my($text, $quote, $notinIS) = @_;
1329 ## Guessing at func() or [$@%&]*var references in plain text is destined
1330 ## to produce some strange looking ref's. uncomment to disable:
1333 my(@words, $lead, $trail);
1335 # convert double-quotes to single-quotes
1336 if( $$quote && $text =~ s/"/''/s ){
1339 while ($text =~ s/"([^"]*)"/``$1''/sg) {};
1340 $$quote = 1 if $text =~ s/"/``/s;
1342 # keep track of leading and trailing white-space
1343 $lead = ($text =~ s/\A(\s+)//s ? $1 : "");
1344 $trail = ($text =~ s/(\s+)\Z//s ? $1 : "");
1346 # split at space/non-space boundaries
1347 @words = split( /(?<=\s)(?=\S)|(?<=\S)(?=\s)/, $text );
1349 # process each word individually
1350 foreach my $word (@words) {
1352 next if $word =~ /^\s*$/;
1353 # see if we can infer a link
1354 if( $notinIS && $word =~ /^(\w+)\((.*)\)$/ ) {
1355 # has parenthesis so should have been a C<> ref
1356 ## try for a pagename (perlXXX(1))?
1357 my( $func, $args ) = ( $1, $2 );
1358 if( $args =~ /^\d+$/ ){
1359 my $url = page_sect( $word, '' );
1361 $word = "<A HREF=\"$url\">the $word manpage</A>";
1365 ## try function name for a link, append tt'ed argument list
1366 $word = emit_C( $func, '', "($args)");
1368 #### disabled. either all (including $\W, $\w+{.*} etc.) or nothing.
1369 ## } elsif( $notinIS && $word =~ /^[\$\@%&*]+\w+$/) {
1370 ## # perl variables, should be a C<> ref
1371 ## $word = emit_C( $word );
1373 } elsif ($word =~ m,^\w+://\w,) {
1375 # Don't relativize it: leave it as the author intended
1376 $word = qq(<A HREF="$word">$word</A>);
1377 } elsif ($word =~ /[\w.-]+\@[\w-]+\.\w/) {
1378 # looks like an e-mail address
1379 my ($w1, $w2, $w3) = ("", $word, "");
1380 ($w1, $w2, $w3) = ("(", $1, ")$2") if $word =~ /^\((.*?)\)(,?)/;
1381 ($w1, $w2, $w3) = ("<", $1, ">$2") if $word =~ /^<(.*?)>(,?)/;
1382 $word = qq($w1<A HREF="mailto:$w2">$w2</A>$w3);
1383 } elsif ($word !~ /[a-z]/ && $word =~ /[A-Z]/) { # all uppercase?
1384 $word = html_escape($word) if $word =~ /["&<>]/;
1385 $word = "\n<FONT SIZE=-1>$word</FONT>" if $netscape;
1387 $word = html_escape($word) if $word =~ /["&<>]/;
1391 # put everything back together
1392 return $lead . join( '', @words ) . $trail;
1397 # process_text - handles plaintext that appears in the input pod file.
1398 # there may be pod commands embedded within the text so those must be
1399 # converted to html commands.
1402 sub process_text1($$;$$);
1403 sub pattern ($) { $_[0] ? '[^\S\n]+'.('>' x ($_[0] + 1)) : '>' }
1404 sub closing ($) { local($_) = shift; (defined && s/\s+$//) ? length : 0 }
1409 my $res = process_text1( 0, $tref );
1413 sub process_text1($$;$$){
1414 my( $lev, $rstr, $func, $closing ) = @_;
1417 unless (defined $func) {
1423 # B<text> - boldface
1424 $res = '<STRONG>' . process_text1( $lev, $rstr ) . '</STRONG>';
1426 } elsif( $func eq 'C' ){
1427 # C<code> - can be a ref or <CODE></CODE>
1428 # need to extract text
1429 my $par = go_ahead( $rstr, 'C', $closing );
1431 ## clean-up of the link target
1432 my $text = depod( $par );
1434 ### my $x = $par =~ /[BI]</ ? 'yes' : 'no' ;
1435 ### print STDERR "-->call emit_C($par) lev=$lev, par with BI=$x\n";
1437 $res = emit_C( $text, $lev > 1 || ($par =~ /[BI]</) );
1439 } elsif( $func eq 'E' ){
1440 # E<x> - convert to character
1441 $$rstr =~ s/^(\w+)>//;
1444 } elsif( $func eq 'F' ){
1445 # F<filename> - italizice
1446 $res = '<EM>' . process_text1( $lev, $rstr ) . '</EM>';
1448 } elsif( $func eq 'I' ){
1449 # I<text> - italizice
1450 $res = '<EM>' . process_text1( $lev, $rstr ) . '</EM>';
1452 } elsif( $func eq 'L' ){
1454 ## L<text|cross-ref> => produce text, use cross-ref for linking
1455 ## L<cross-ref> => make text from cross-ref
1456 ## need to extract text
1457 my $par = go_ahead( $rstr, 'L', $closing );
1459 # some L<>'s that shouldn't be:
1460 # a) full-blown URL's are emitted as-is
1461 if( $par =~ m{^\w+://}s ){
1462 return make_URL_href( $par );
1464 # b) C<...> is stripped and treated as C<>
1465 if( $par =~ /^C<(.*)>$/ ){
1466 my $text = depod( $1 );
1467 return emit_C( $text, $lev > 1 || ($par =~ /[BI]</) );
1470 # analyze the contents
1471 $par =~ s/\n/ /g; # undo word-wrapped tags
1474 if( $par =~ s{^([^|]+)\|}{} ){
1478 # make sure sections start with a /
1481 my( $page, $section, $ident );
1483 # check for link patterns
1484 if( $par =~ m{^([^/]+?)/(?!")(.*?)$} ){ # name/ident
1485 # we've got a name/ident (no quotes)
1486 ( $page, $ident ) = ( $1, $2 );
1487 ### print STDERR "--> L<$par> to page $page, ident $ident\n";
1489 } elsif( $par =~ m{^(.*?)/"?(.*?)"?$} ){ # [name]/"section"
1490 # even though this should be a "section", we go for ident first
1491 ( $page, $ident ) = ( $1, $2 );
1492 ### print STDERR "--> L<$par> to page $page, section $section\n";
1494 } elsif( $par =~ /\s/ ){ # this must be a section with missing quotes
1495 ( $page, $section ) = ( '', $par );
1496 ### print STDERR "--> L<$par> to void page, section $section\n";
1499 ( $page, $section ) = ( $par, '' );
1500 ### print STDERR "--> L<$par> to page $par, void section\n";
1503 # now, either $section or $ident is defined. the convoluted logic
1504 # below tries to resolve L<> according to what the user specified.
1505 # failing this, we try to find the next best thing...
1506 my( $url, $ltext, $fid );
1509 if( defined $ident ){
1510 ## try to resolve $ident as an item
1511 ( $url, $fid ) = coderef( $page, $ident );
1513 if( ! defined( $linktext ) ){
1515 $linktext .= " in " if $ident && $page;
1516 $linktext .= "the $page manpage" if $page;
1518 ### print STDERR "got coderef url=$url\n";
1521 ## no luck: go for a section (auto-quoting!)
1524 ## now go for a section
1525 my $htmlsection = htmlify( $section );
1526 $url = page_sect( $page, $htmlsection );
1528 if( ! defined( $linktext ) ){
1529 $linktext = $section;
1530 $linktext .= " in " if $section && $page;
1531 $linktext .= "the $page manpage" if $page;
1533 ### print STDERR "got page/section url=$url\n";
1536 ## no luck: go for an ident
1543 ( $url, $fid ) = coderef( $page, $ident );
1545 if( ! defined( $linktext ) ){
1547 $linktext .= " in " if $ident && $page;
1548 $linktext .= "the $page manpage" if $page;
1550 ### print STDERR "got section=>coderef url=$url\n";
1554 # warning; show some text.
1555 $linktext = $opar unless defined $linktext;
1556 warn "$0: $podfile: cannot resolve L<$opar> in paragraph $paragraph.";
1559 # now we have an URL or just plain code
1560 $$rstr = $linktext . '>' . $$rstr;
1561 if( defined( $url ) ){
1562 $res = "<A HREF=\"$url\">" . process_text1( $lev, $rstr ) . '</A>';
1564 $res = '<EM>' . process_text1( $lev, $rstr ) . '</EM>';
1567 } elsif( $func eq 'S' ){
1568 # S<text> - non-breaking spaces
1569 $res = process_text1( $lev, $rstr );
1570 $res =~ s/ / /g;
1572 } elsif( $func eq 'X' ){
1574 $$rstr =~ s/^[^>]*>//;
1576 } elsif( $func eq 'Z' ){
1578 warn "$0: $podfile: invalid X<> in paragraph $paragraph."
1579 unless $$rstr =~ s/^>//;
1582 my $term = pattern $closing;
1583 while( $$rstr =~ s/\A(.*?)(([BCEFILSXZ])<(<+[^\S\n]+)?|$term)//s ){
1584 # all others: either recurse into new function or
1585 # terminate at closing angle bracket(s)
1587 $pt .= $2 if !$3 && $lev == 1;
1588 $res .= $lev == 1 ? pure_text( $pt ) : inIS_text( $pt );
1589 return $res if !$3 && $lev > 1;
1591 $res .= process_text1( $lev, $rstr, $3, closing $4 );
1595 $res .= pure_text( $$rstr );
1597 warn "$0: $podfile: undelimited $func<> in paragraph $paragraph.";
1604 # go_ahead: extract text of an IS (can be nested)
1607 my( $rstr, $func, $closing ) = @_;
1609 my @closing = ($closing);
1611 s/\A(.*?)(([BCEFILSXZ])<(<+[^\S\n]+)?|@{[pattern $closing[0]]})//s ){
1615 return $res unless @closing;
1617 unshift @closing, closing $4;
1621 warn "$0: $podfile: undelimited $func<> in paragraph $paragraph.";
1626 # emit_C - output result of C<text>
1627 # $text is the depod-ed text
1630 my( $text, $nocode, $args ) = @_;
1631 $args = '' unless defined $args;
1633 my( $url, $fid ) = coderef( undef(), $text );
1635 # need HTML-safe text
1636 my $linktext = html_escape( "$text$args" );
1638 if( defined( $url ) &&
1639 (!defined( $EmittedItem ) || $EmittedItem ne $fid ) ){
1640 $res = "<A HREF=\"$url\"><CODE>$linktext</CODE></A>";
1641 } elsif( 0 && $nocode ){
1644 $res = "<CODE>$linktext</CODE>";
1650 # html_escape: make text safe for HTML
1654 $rest =~ s/&/&/g;
1655 $rest =~ s/</</g;
1656 $rest =~ s/>/>/g;
1657 $rest =~ s/"/"/g;
1663 # dosify - convert filenames to 8.3
1667 return lc($str) if $^O eq 'VMS'; # VMS just needs casing
1670 $str =~ s/(\.\w+)/substr ($1,0,4)/ge;
1671 $str =~ s/(\w+)/substr ($1,0,8)/ge;
1677 # page_sect - make an URL from the text of a L<>
1680 my( $page, $section ) = @_;
1681 my( $linktext, $page83, $link); # work strings
1683 # check if we know that this is a section in this page
1684 if (!defined $pages{$page} && defined $sections{$page}) {
1687 ### print STDERR "reset page='', section=$section\n";
1690 $page83=dosify($page);
1691 $page=$page83 if (defined $pages{$page83});
1693 $link = "#" . htmlify( $section );
1694 } elsif ( $page =~ /::/ ) {
1696 # Search page cache for an entry keyed under the html page name,
1697 # then look to see what directory that page might be in. NOTE:
1698 # this will only find one page. A better solution might be to produce
1699 # an intermediate page that is an index to all such pages.
1700 my $page_name = $page ;
1701 $page_name =~ s,^.*/,,s ;
1702 if ( defined( $pages{ $page_name } ) &&
1703 $pages{ $page_name } =~ /([^:]*$page)\.(?:pod|pm):/
1708 # NOTE: This branch assumes that all A::B pages are located in
1709 # $htmlroot/A/B.html . This is often incorrect, since they are
1710 # often in $htmlroot/lib/A/B.html or such like. Perhaps we could
1711 # analyze the contents of %pages and figure out where any
1712 # cousins of A::B are, then assume that. So, if A::B isn't found,
1713 # but A::C is found in lib/A/C.pm, then A::B is assumed to be in
1714 # lib/A/B.pm. This is also limited, but it's an improvement.
1715 # Maybe a hints file so that the links point to the correct places
1719 $link = "$htmlroot/$page.html";
1720 $link .= "#" . htmlify( $section ) if ($section);
1721 } elsif (!defined $pages{$page}) {
1724 $section = htmlify( $section ) if $section ne "";
1725 ### print STDERR "...section=$section\n";
1727 # if there is a directory by the name of the page, then assume that an
1728 # appropriate section will exist in the subdirectory
1729 # if ($section ne "" && $pages{$page} =~ /([^:]*[^(\.pod|\.pm)]):/) {
1730 if ($section ne "" && $pages{$page} =~ /([^:]*(?<!\.pod)(?<!\.pm)):/) {
1731 $link = "$htmlroot/$1/$section.html";
1732 ### print STDERR "...link=$link\n";
1734 # since there is no directory by the name of the page, the section will
1735 # have to exist within a .html of the same name. thus, make sure there
1736 # is a .pod or .pm that might become that .html
1738 $section = "#$section" if $section;
1739 ### print STDERR "...section=$section\n";
1741 # check if there is a .pod with the page name
1742 if ($pages{$page} =~ /([^:]*)\.pod:/) {
1743 $link = "$htmlroot/$1.html$section";
1744 } elsif ($pages{$page} =~ /([^:]*)\.pm:/) {
1745 $link = "$htmlroot/$1.html$section";
1753 # Here, we take advantage of the knowledge that $htmlfileurl ne ''
1754 # implies $htmlroot eq ''. This means that the link in question
1755 # needs a prefix of $htmldir if it begins with '/'. The test for
1756 # the initial '/' is done to avoid '#'-only links, and to allow
1757 # for other kinds of links, like file:, ftp:, etc.
1759 if ( $htmlfileurl ne '' ) {
1760 $link = "$htmldir$link" if $link =~ m{^/}s;
1761 $url = relativize_url( $link, $htmlfileurl );
1762 # print( " b: [$link,$htmlfileurl,$url]\n" );
1775 # relativize_url - convert an absolute URL to one relative to a base URL.
1776 # Assumes both end in a filename.
1778 sub relativize_url {
1779 my ($dest,$source) = @_ ;
1781 my ($dest_volume,$dest_directory,$dest_file) =
1782 File::Spec::Unix->splitpath( $dest ) ;
1783 $dest = File::Spec::Unix->catpath( $dest_volume, $dest_directory, '' ) ;
1785 my ($source_volume,$source_directory,$source_file) =
1786 File::Spec::Unix->splitpath( $source ) ;
1787 $source = File::Spec::Unix->catpath( $source_volume, $source_directory, '' ) ;
1790 if ( $dest ne '' ) {
1791 $rel_path = File::Spec::Unix->abs2rel( $dest, $source ) ;
1794 if ( $rel_path ne '' &&
1795 substr( $rel_path, -1 ) ne '/' &&
1796 substr( $dest_file, 0, 1 ) ne '#'
1798 $rel_path .= "/$dest_file" ;
1801 $rel_path .= "$dest_file" ;
1809 # coderef - make URL from the text of a C<>
1812 my( $page, $item ) = @_;
1815 my $fid = fragment_id( $item );
1816 if( defined( $page ) ){
1817 # we have been given a $page...
1820 # Do we take it? Item could be a section!
1821 my $base = $items{$fid} || "";
1822 $base =~ s{[^/]*/}{};
1823 if( $base ne "$page.html" ){
1824 ### print STDERR "coderef( $page, $item ): items{$fid} = $items{$fid} = $base => discard page!\n";
1829 # no page - local items precede cached items
1830 if( defined( $fid ) ){
1831 if( exists $local_items{$fid} ){
1832 $page = $local_items{$fid};
1834 $page = $items{$fid};
1839 # if there was a pod file that we found earlier with an appropriate
1840 # =item directive, then create a link to that page.
1841 if( defined $page ){
1843 if( exists $pages{$page} and $pages{$page} =~ /([^:.]*)\.[^:]*:/){
1844 $page = $1 . '.html';
1846 my $link = "$htmlroot/$page#item_$fid";
1848 # Here, we take advantage of the knowledge that $htmlfileurl
1849 # ne '' implies $htmlroot eq ''.
1850 if ( $htmlfileurl ne '' ) {
1851 $link = "$htmldir$link" ;
1852 $url = relativize_url( $link, $htmlfileurl ) ;
1857 $url = "#item_" . $fid;
1860 confess "url has space: $url" if $url =~ /"[^"]*\s[^"]*"/;
1862 return( $url, $fid );
1868 # Adapted from Nick Ing-Simmons' PodToHtml package.
1870 my $source_file = shift ;
1871 my $destination_file = shift;
1873 my $source = URI::file->new_abs($source_file);
1874 my $uo = URI::file->new($destination_file,$source)->abs;
1875 return $uo->rel->as_string;
1880 # finish_list - finish off any pending HTML lists. this should be called
1881 # after the entire pod file has been read and converted.
1884 while ($listlevel > 0) {
1885 print HTML "</DL>\n";
1891 # htmlify - converts a pod section specification to a suitable section
1892 # specification for HTML. Note that we keep spaces and special characters
1893 # except ", ? (Netscape problem) and the hyphen (writer's problem...).
1897 $heading =~ s/(\s+)/ /g;
1898 $heading =~ s/\s+\Z//;
1899 $heading =~ s/\A\s+//;
1900 # The hyphen is a disgrace to the English language.
1901 $heading =~ s/[-"?]//g;
1902 $heading = lc( $heading );
1907 # depod - convert text by eliminating all interior sequences
1908 # Note: can be called with copy or modify semantics
1915 $E2c{amp} = '&'; # in Tk's pods
1923 ${$_[0]} = depod1( \$string );
1931 my( $rstr, $func, $closing ) = @_;
1933 return $res unless defined $$rstr;
1934 if( ! defined( $func ) ){
1935 # skip to next begin of an interior sequence
1936 while( $$rstr =~ s/\A(.*?)([BCEFILSXZ])<(<+[^\S\n]+)?// ){
1937 # recurse into its text
1938 $res .= $1 . depod1( $rstr, $2, closing $3);
1941 } elsif( $func eq 'E' ){
1942 # E<x> - convert to character
1943 $$rstr =~ s/^(\w+)>//;
1944 $res .= $E2c{$1} || "";
1945 } elsif( $func eq 'X' ){
1947 $$rstr =~ s/^[^>]*>//;
1948 } elsif( $func eq 'Z' ){
1952 # all others: either recurse into new function or
1953 # terminate at closing angle bracket
1954 my $term = pattern $closing;
1955 while( $$rstr =~ s/\A(.*?)(([BCEFILSXZ])<(<+[^\S\n]+)?|$term)// ){
1958 $res .= depod1( $rstr, $3, closing $4 );
1960 ## If we're here and $2 ne '>': undelimited interior sequence.
1961 ## Ignored, as this is called without proper indication of where we are.
1962 ## Rely on process_text to produce diagnostics.
1968 # fragment_id - construct a fragment identifier from:
1970 # b) contents of C<...>
1975 $text =~ s/\s+\Z//s;
1977 # a method or function?
1978 return $1 if $text =~ /(\w+)\s*\(/;
1979 return $1 if $text =~ /->\s*(\w+)\s*\(?/;
1982 return $1 if $text =~ /^([$@%*]\S+)/;
1984 # some pattern matching operator?
1985 return $1 if $text =~ m|^(\w+/).*/\w*$|;
1987 # fancy stuff... like "do { }"
1988 return $1 if $text =~ m|^(\w+)\s*{.*}$|;
1990 # honour the perlfunc manpage: func [PAR[,[ ]PAR]...]
1991 # and some funnies with ... Module ...
1992 return $1 if $text =~ m{^([a-z\d]+)(\s+[A-Z\d,/& ]+)?$};
1993 return $1 if $text =~ m{^([a-z\d]+)\s+Module(\s+[A-Z\d,/& ]+)?$};
1996 $text =~ s/\s+/_/sg;
1998 defined( $hc[ord($1)] ) ? $hc[ord($1)]
1999 : ( $hc[ord($1)] = sprintf( "%%%02X", ord($1) ) ) }gxe;
2000 $text = substr( $text, 0, 50 );
2007 # make_URL_href - generate HTML href from URL
2008 # Special treatment for CGI queries.
2010 sub make_URL_href($){
2013 s{^(http:[-\w/#~:.+=&%@!]+)(\?.*)$}{<A HREF="$1$2">$1</A>}i ){
2014 $url = "<A HREF=\"$url\">$url</A>";