5 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
8 @EXPORT = qw(pod2html htmlify);
9 @EXPORT_OK = qw(anchorify);
18 use locale; # make \w work right in non-ASCII lands
22 Pod::Html - module to convert pod files to HTML
31 Converts files from pod format (see L<perlpod>) to HTML format. It
32 can automatically generate indexes and cross-references, and it keeps
33 a cache of things it knows how to cross-reference.
37 Pod::Html takes the following arguments:
43 --backlink="Back to Top"
45 Adds "Back to Top" links in front of every C<head1> heading (except for
46 the first). By default, no backlinks are generated.
52 Creates the item and directory caches in the given directory.
58 Specify the URL of a cascading style sheet. Also disables all HTML/CSS
59 C<style> attributes that are output by default (to avoid conflicts).
65 Flushes the item and directory caches.
72 Creates header and footer blocks containing the text of the C<NAME>
73 section. By default, no headers are generated.
79 Displays the usage message.
86 Include hidden directories in the search for POD's in podpath if recurse
88 The default is not to traverse any directory whose name begins with C<.>.
89 See L</"podpath"> and L</"recurse">.
91 [This option is for backward compatibility only.
92 It's hard to imagine that one would usefully create a module with a
93 name component beginning with C<.>.]
99 Sets the directory in which the resulting HTML file is placed. This
100 is used to generate relative links to other files. Not passing this
101 causes all links to be absolute, since this is the value that tells
102 Pod::Html the root of the documentation tree.
108 Sets the base URL for the HTML files. When cross-references are made,
109 the HTML root is prepended to the URL.
116 Generate an index at the top of the HTML file. This is the default
123 Specify the pod file to convert. Input is taken from STDIN if no
128 --libpods=name:...:name
130 List of page names (eg, "perlfunc") which contain linkable C<=item>s.
137 B<Deprecated>, has no effect. For backwards compatibility only.
143 Specify the HTML file to create. Output goes to STDOUT if no outfile
148 --podpath=name:...:name
150 Specify which subdirectories of the podroot contain pod files whose
151 HTML converted forms can be linked to in cross references.
157 Specify the base directory for finding library pods.
164 Don't display I<mostly harmless> warning messages. These messages
165 will be displayed by default. But this is not the same as C<verbose>
173 Recurse into subdirectories specified in podpath (default behaviour).
179 Specify the title of the resulting HTML file.
186 Display progress messages. By default, they won't be displayed.
193 "--podpath=lib:ext:pod:vms",
194 "--podroot=/usr/src/perl",
195 "--htmlroot=/perl/nmanual",
196 "--libpods=perlfunc:perlguts:perlvar:perlrun:perlop",
199 "--outfile=/perl/nmanual/foo.html");
203 Uses C<$Config{pod2html}> to setup default options.
207 Tom Christiansen, E<lt>tchrist@perl.comE<gt>.
215 This program is distributed under the Artistic License.
221 my($Dircache, $Itemcache);
224 my($Htmlroot, $Htmldir, $Htmlfile, $Htmlfileurl);
225 my($Podfile, @Podpath, $Podroot);
235 my($Listlevel, @Listend);
237 use vars qw($Ignore); # need to localize it later.
239 my(%Items_Named, @Items_Seen);
248 my %Pages = (); # associative array used to find the location
249 # of pages referenced by L<> links.
250 my %Items = (); # associative array used to find the location
251 # of =item directives referenced by C<> links
257 my $Curdir = File::Spec->curdir;
262 $Cachedir = "."; # The directory to which item and directory
263 # caches will be written.
265 $Dircache = "pod2htmd.tmp";
266 $Itemcache = "pod2htmi.tmp";
268 @Begin_Stack = (); # begin/end stack
270 @Libpods = (); # files to search for links from C<> directives
271 $Htmlroot = "/"; # http-server base directory from which all
272 # relative paths in $podpath stem.
273 $Htmldir = ""; # The directory to which the html pages
274 # will (eventually) be written.
275 $Htmlfile = ""; # write to stdout by default
276 $Htmlfileurl = "" ; # The url that other files would use to
277 # refer to this file. This is only used
278 # to make relative urls that point to
281 $Podfile = ""; # read from stdin by default
282 @Podpath = (); # list of directories containing library pods.
283 $Podroot = $Curdir; # filesystem base directory from which all
284 # relative paths in $podpath stem.
285 $Css = ''; # Cascading style sheet
286 $Recurse = 1; # recurse on subdirectories in $podpath.
287 $Quiet = 0; # not quiet by default
288 $Verbose = 0; # not verbose by default
289 $Doindex = 1; # non-zero if we should generate an index
290 $Backlink = ''; # text for "back to top" links
291 $Listlevel = 0; # current list depth
292 @Listend = (); # the text to use to end the list.
293 $After_Lpar = 0; # set to true after a par in an =item
294 $Ignore = 1; # whether or not to format text. we don't
295 # format text until we hit our first pod
298 @Items_Seen = (); # for multiples of the same item in perlfunc
300 $Header = 0; # produce block header/footer
301 $Title = ''; # title to give the pod(s)
302 $Top = 1; # true if we are at the top of the doc. used
303 # to prevent the first <hr /> directive.
304 $Paragraph = ''; # which paragraph we're processing (used
305 # for error messages)
306 $PTQuote = 0; # status of double-quote conversion
307 %Sections = (); # sections within this page
310 $Is83 = $^O eq 'dos'; # Is it an 8.3 filesystem?
314 # clean_data: global clean-up of pod data
318 for my $i ( 0..$#{$dataref} ) {
319 ${$dataref}[$i] =~ s/\s+\Z//;
321 # have a look for all-space lines
322 if( ${$dataref}[$i] =~ /^\s+$/m and $dataref->[$i] !~ /^\s/ ){
323 my @chunks = split( /^\s+$/m, ${$dataref}[$i] );
324 splice( @$dataref, $i, 1, @chunks );
337 $Is83 = 0 if (defined (&Dos::UseLFN) && Dos::UseLFN());
339 # cache of %Pages and %Items from last time we ran pod2html
341 #undef $opt_help if defined $opt_help;
343 # parse the command-line parameters
344 parse_command_line();
346 # escape the backlink argument (same goes for title but is done later...)
347 $Backlink = html_escape($Backlink) if defined $Backlink;
349 # set some variables to their default values if necessary
351 unless (@ARGV && $ARGV[0]) {
352 $Podfile = "-" unless $Podfile; # stdin
353 open(POD, "<$Podfile")
354 || die "$0: cannot open $Podfile file for input: $!\n";
356 $Podfile = $ARGV[0]; # XXX: might be more filenames
359 $Htmlfile = "-" unless $Htmlfile; # stdout
360 $Htmlroot = "" if $Htmlroot eq "/"; # so we don't get a //
361 $Htmldir =~ s#/\z## ; # so we don't get a //
363 && defined( $Htmldir )
365 && substr( $Htmlfile, 0, length( $Htmldir ) ) eq $Htmldir
368 # Set the 'base' url for this file, so that we can use it
369 # as the location from which to calculate relative links
370 # to other files. If this is '', then absolute links will
371 # be used throughout.
372 $Htmlfileurl= "$Htmldir/" . substr( $Htmlfile, length( $Htmldir ) + 1);
375 # read the pod a paragraph at a time
376 warn "Scanning for sections in input file(s)\n" if $Verbose;
385 @poddata = map { s/\r\n/\n/g;
387 map { "$_\n\n" } split /\n\n/ :
390 @poddata = map { s/\r/\n/g;
392 map { "$_\n\n" } split /\n\n/ :
399 clean_data( \@poddata );
401 # scan the pod for =head[1-6] directives and build an index
402 my $index = scan_headings(\%Sections, @poddata);
405 warn "No headings in $Podfile\n" if $Verbose;
408 # open the output file
409 open(HTML, ">$Htmlfile")
410 || die "$0: cannot open $Htmlfile file for output: $!\n";
412 # put a title in the HTML file if one wasn't specified
415 for (my $i = 0; $i < @poddata; $i++) {
416 if ($poddata[$i] =~ /^=head1\s*NAME\b/m) {
417 for my $para ( @poddata[$i, $i+1] ) {
419 if ($Title) = $para =~ /(\S+\s+-+.*\S)/s;
426 if (!$Title and $Podfile =~ /\.pod\z/) {
427 # probably a split pod so take first =head[12] as title
428 for (my $i = 0; $i < @poddata; $i++) {
429 last if ($Title) = $poddata[$i] =~ /^=head[12]\s*(.*)/;
431 warn "adopted '$Title' as title for $Podfile\n"
432 if $Verbose and $Title;
435 $Title =~ s/\s*\(.*\)//;
437 warn "$0: no title for $Podfile.\n" unless $Quiet;
438 $Podfile =~ /^(.*)(\.[^.\/]+)?\z/s;
439 $Title = ($Podfile eq "-" ? 'No Title' : $1);
440 warn "using $Title" if $Verbose;
442 $Title = html_escape($Title);
445 my $bodystyle = ' style="background-color: white"';
446 my $tdstyle = ' style="background-color: #cccccc"';
449 $csslink = qq(\n<link rel="stylesheet" href="$Css" type="text/css" />);
450 $csslink =~ s,\\,/,g;
451 $csslink =~ s,(/.):,$1|,;
456 my $block = $Header ? <<END_OF_BLOCK : '';
457 <table border="0" width="100%" cellspacing="0" cellpadding="3">
458 <tr><td class="block"$tdstyle valign="middle">
459 <big><strong><span class="block"> $Title</span></strong></big>
464 print HTML <<END_OF_HEAD;
465 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
466 <html xmlns="http://www.w3.org/1999/xhtml">
468 <title>$Title</title>$csslink
469 <link rev="made" href="mailto:$Config{perladmin}" />
476 # load/reload/validate/cache %Pages and %Items
477 get_cache($Dircache, $Itemcache, \@Podpath, $Podroot, $Recurse);
479 # scan the pod for =item directives
480 scan_items( \%Local_Items, "", @poddata);
482 # put an index at the top of the file. note, if $Doindex is 0 we
483 # still generate an index, but surround it with an html comment.
484 # that way some other program can extract it if desired.
486 print HTML "<p><a name=\"__index__\"></a></p>\n";
487 print HTML "<!-- INDEX BEGIN -->\n";
488 print HTML "<!--\n" unless $Doindex;
490 print HTML "-->\n" unless $Doindex;
491 print HTML "<!-- INDEX END -->\n\n";
492 print HTML "<hr />\n" if $Doindex and $index;
494 # now convert this file
495 my $after_item; # set to true after an =item
497 warn "Converting input file $Podfile\n" if $Verbose;
498 foreach my $i (0..$#poddata){
499 $PTQuote = 0; # status of quote conversion
503 if (/^(=.*)/s) { # is it a pod directive?
508 if (/^=begin\s+(\S+)\s*(.*)/si) {# =begin
509 process_begin($1, $2);
510 } elsif (/^=end\s+(\S+)\s*(.*)/si) {# =end
512 } elsif (/^=cut/) { # =cut
514 } elsif (/^=pod/) { # =pod
517 next if @Begin_Stack && $Begin_Stack[-1] ne 'html';
519 if (/^=(head[1-6])\s+(.*\S)/s) { # =head[1-6] heading
520 process_head( $1, $2, $Doindex && $index );
521 } elsif (/^=item\s*(.*\S)?/sm) { # =item text
522 $need_dd = process_item( $1 );
524 } elsif (/^=over\s*(.*)/) { # =over N
526 } elsif (/^=back/) { # =back
528 } elsif (/^=for\s+(\S+)\s*(.*)/si) {# =for
532 warn "$0: $Podfile: unknown pod directive '$1' in "
533 . "paragraph $Paragraph. ignoring.\n";
540 next if @Begin_Stack && $Begin_Stack[-1] ne 'html';
541 print HTML and next if @Begin_Stack && $Begin_Stack[-1] eq 'html';
542 print HTML "<dd>\n" if $need_dd;
544 if( $text =~ /\A\s+/ ){
545 process_pre( \$text );
546 print HTML "<pre>\n$text</pre>\n";
549 process_text( \$text );
551 # experimental: check for a paragraph where all lines
552 # have some ...\t...\t...\n pattern
554 my @lines = split( "\n", $text );
557 foreach my $line ( @lines ){
558 if( $line =~ /\S/ && $line !~ /\t/ ){
564 $text =~ s/\t+/<td>/g;
565 $text =~ s/^/<tr><td>/gm;
566 $text = '<table cellspacing="0" cellpadding="0">' .
571 ## end of experimental
574 print HTML "$text\n";
577 print HTML "<p>$text</p>\n";
580 print HTML "</dd>\n" if $need_dd;
585 # finish off any pending directives
589 print HTML "<p><a href=\"#__index__\"><small>$Backlink</small></a></p>\n"
590 if $Doindex and $index and $Backlink;
592 print HTML <<END_OF_TAIL;
599 # close the html file
602 warn "Finished\n" if $Verbose;
605 ##############################################################################
609 warn "$0: $podfile: @_\n" if @_;
611 Usage: $0 --help --htmlroot=<name> --infile=<name> --outfile=<name>
612 --podpath=<name>:...:<name> --podroot=<name>
613 --libpods=<name>:...:<name> --recurse --verbose --index
614 --netscape --norecurse --noindex --cachedir=<name>
616 --backlink - set text for "back to top" links (default: none).
617 --cachedir - directory for the item and directory cache files.
618 --css - stylesheet URL
619 --flush - flushes the item and directory caches.
620 --[no]header - produce block header/footer (default is no headers).
621 --help - prints this message.
622 --hiddendirs - search hidden directories in podpath
623 --htmldir - directory for resulting HTML files.
624 --htmlroot - http-server base directory from which all relative paths
625 in podpath stem (default is /).
626 --[no]index - generate an index at the top of the resulting html
628 --infile - filename for the pod to convert (input taken from stdin
630 --libpods - colon-separated list of pages to search for =item pod
631 directives in as targets of C<> and implicit links (empty
632 by default). note, these are not filenames, but rather
633 page names like those that appear in L<> links.
634 --outfile - filename for the resulting html file (output sent to
636 --podpath - colon-separated list of directories containing library
637 pods (empty by default).
638 --podroot - filesystem base directory from which all relative paths
639 in podpath stem (default is .).
640 --[no]quiet - supress some benign warning messages (default is off).
641 --[no]recurse - recurse on those subdirectories listed in podpath
643 --title - title that will appear in resulting html file.
644 --[no]verbose - self-explanatory (off by default).
645 --[no]netscape - deprecated, has no effect. for backwards compatibility only.
651 sub parse_command_line {
652 my ($opt_backlink,$opt_cachedir,$opt_css,$opt_flush,$opt_header,$opt_help,
653 $opt_htmldir,$opt_htmlroot,$opt_index,$opt_infile,$opt_libpods,
654 $opt_netscape,$opt_outfile,$opt_podpath,$opt_podroot,$opt_quiet,
655 $opt_recurse,$opt_title,$opt_verbose,$opt_hiddendirs);
657 unshift @ARGV, split ' ', $Config{pod2html} if $Config{pod2html};
658 my $result = GetOptions(
659 'backlink=s' => \$opt_backlink,
660 'cachedir=s' => \$opt_cachedir,
661 'css=s' => \$opt_css,
662 'flush' => \$opt_flush,
663 'header!' => \$opt_header,
664 'help' => \$opt_help,
665 'hiddendirs!'=> \$opt_hiddendirs,
666 'htmldir=s' => \$opt_htmldir,
667 'htmlroot=s' => \$opt_htmlroot,
668 'index!' => \$opt_index,
669 'infile=s' => \$opt_infile,
670 'libpods=s' => \$opt_libpods,
671 'netscape!' => \$opt_netscape,
672 'outfile=s' => \$opt_outfile,
673 'podpath=s' => \$opt_podpath,
674 'podroot=s' => \$opt_podroot,
675 'quiet!' => \$opt_quiet,
676 'recurse!' => \$opt_recurse,
677 'title=s' => \$opt_title,
678 'verbose!' => \$opt_verbose,
680 usage("-", "invalid parameters") if not $result;
682 usage("-") if defined $opt_help; # see if the user asked for help
683 $opt_help = ""; # just to make -w shut-up.
685 @Podpath = split(":", $opt_podpath) if defined $opt_podpath;
686 @Libpods = split(":", $opt_libpods) if defined $opt_libpods;
688 $Backlink = $opt_backlink if defined $opt_backlink;
689 $Cachedir = $opt_cachedir if defined $opt_cachedir;
690 $Css = $opt_css if defined $opt_css;
691 $Header = $opt_header if defined $opt_header;
692 $Htmldir = $opt_htmldir if defined $opt_htmldir;
693 $Htmlroot = $opt_htmlroot if defined $opt_htmlroot;
694 $Doindex = $opt_index if defined $opt_index;
695 $Podfile = $opt_infile if defined $opt_infile;
696 $HiddenDirs = $opt_hiddendirs if defined $opt_hiddendirs;
697 $Htmlfile = $opt_outfile if defined $opt_outfile;
698 $Podroot = $opt_podroot if defined $opt_podroot;
699 $Quiet = $opt_quiet if defined $opt_quiet;
700 $Recurse = $opt_recurse if defined $opt_recurse;
701 $Title = $opt_title if defined $opt_title;
702 $Verbose = $opt_verbose if defined $opt_verbose;
704 warn "Flushing item and directory caches\n"
705 if $opt_verbose && defined $opt_flush;
706 $Dircache = "$Cachedir/pod2htmd.tmp";
707 $Itemcache = "$Cachedir/pod2htmi.tmp";
708 if (defined $opt_flush) {
709 1 while unlink($Dircache, $Itemcache);
717 my($dircache, $itemcache, $podpath, $podroot, $recurse) = @_;
718 my @cache_key_args = @_;
720 # A first-level cache:
721 # Don't bother reading the cache files if they still apply
722 # and haven't changed since we last read them.
724 my $this_cache_key = cache_key(@cache_key_args);
726 return if $Saved_Cache_Key and $this_cache_key eq $Saved_Cache_Key;
728 # load the cache of %Pages and %Items if possible. $tests will be
729 # non-zero if successful.
731 if (-f $dircache && -f $itemcache) {
732 warn "scanning for item cache\n" if $Verbose;
733 $tests = load_cache($dircache, $itemcache, $podpath, $podroot);
736 # if we didn't succeed in loading the cache then we must (re)build
739 warn "scanning directories in pod-path\n" if $Verbose;
740 scan_podpath($podroot, $recurse, 0);
742 $Saved_Cache_Key = cache_key(@cache_key_args);
746 my($dircache, $itemcache, $podpath, $podroot, $recurse) = @_;
747 return join('!', $dircache, $itemcache, $recurse,
748 @$podpath, $podroot, stat($dircache), stat($itemcache));
752 # load_cache - tries to find if the caches stored in $dircache and $itemcache
753 # are valid caches of %Pages and %Items. if they are valid then it loads
754 # them and returns a non-zero value.
757 my($dircache, $itemcache, $podpath, $podroot) = @_;
763 open(CACHE, "<$itemcache") ||
764 die "$0: error opening $itemcache for reading: $!\n";
767 # is it the same podpath?
770 $tests++ if (join(":", @$podpath) eq $_);
772 # is it the same podroot?
775 $tests++ if ($podroot eq $_);
777 # load the cache if its good
783 warn "loading item cache\n" if $Verbose;
790 warn "scanning for directory cache\n" if $Verbose;
791 open(CACHE, "<$dircache") ||
792 die "$0: error opening $dircache for reading: $!\n";
796 # is it the same podpath?
799 $tests++ if (join(":", @$podpath) eq $_);
801 # is it the same podroot?
804 $tests++ if ($podroot eq $_);
806 # load the cache if its good
812 warn "loading directory cache\n" if $Verbose;
824 # scan_podpath - scans the directories specified in @podpath for directories,
825 # .pod files, and .pm files. it also scans the pod files specified in
826 # @Libpods for =item directives.
829 my($podroot, $recurse, $append) = @_;
831 my($libpod, $dirname, $pod, @files, @poddata);
838 # scan each directory listed in @Podpath
841 || die "$0: error changing to directory $podroot: $!\n";
842 foreach $dir (@Podpath) {
843 scan_dir($dir, $recurse);
846 # scan the pods listed in @Libpods for =item directives
847 foreach $libpod (@Libpods) {
848 # if the page isn't defined then we won't know where to find it
850 next unless defined $Pages{$libpod} && $Pages{$libpod};
852 # if there is a directory then use the .pod and .pm files within it.
853 # NOTE: Only finds the first so-named directory in the tree.
854 # if ($Pages{$libpod} =~ /([^:]*[^(\.pod|\.pm)]):/) {
855 if ($Pages{$libpod} =~ /([^:]*(?<!\.pod)(?<!\.pm)):/) {
856 # find all the .pod and .pm files within the directory
858 opendir(DIR, $dirname) ||
859 die "$0: error opening directory $dirname: $!\n";
860 @files = grep(/(\.pod|\.pm)\z/ && ! -d $_, readdir(DIR));
863 # scan each .pod and .pm file for =item directives
864 foreach $pod (@files) {
865 open(POD, "<$dirname/$pod") ||
866 die "$0: error opening $dirname/$pod for input: $!\n";
869 clean_data( \@poddata );
871 scan_items( \%Items, "$dirname/$pod", @poddata);
874 # use the names of files as =item directives too.
875 ### Don't think this should be done this way - confuses issues.(WL)
876 ### foreach $pod (@files) {
877 ### $pod =~ /^(.*)(\.pod|\.pm)$/;
878 ### $Items{$1} = "$dirname/$1.html" if $1;
880 } elsif ($Pages{$libpod} =~ /([^:]*\.pod):/ ||
881 $Pages{$libpod} =~ /([^:]*\.pm):/) {
882 # scan the .pod or .pm file for =item directives
884 open(POD, "<$pod") ||
885 die "$0: error opening $pod for input: $!\n";
888 clean_data( \@poddata );
890 scan_items( \%Items, "$pod", @poddata);
892 warn "$0: shouldn't be here (line ".__LINE__."\n";
895 @poddata = (); # clean-up a bit
898 || die "$0: error changing to directory $pwd: $!\n";
900 # cache the item list for later use
901 warn "caching items for later use\n" if $Verbose;
902 open(CACHE, ">$Itemcache") ||
903 die "$0: error open $Itemcache for writing: $!\n";
905 print CACHE join(":", @Podpath) . "\n$podroot\n";
906 foreach my $key (keys %Items) {
907 print CACHE "$key $Items{$key}\n";
912 # cache the directory list for later use
913 warn "caching directories for later use\n" if $Verbose;
914 open(CACHE, ">$Dircache") ||
915 die "$0: error open $Dircache for writing: $!\n";
917 print CACHE join(":", @Podpath) . "\n$podroot\n";
918 foreach my $key (keys %Pages) {
919 print CACHE "$key $Pages{$key}\n";
926 # scan_dir - scans the directory specified in $dir for subdirectories, .pod
927 # files, and .pm files. notes those that it finds. this information will
928 # be used later in order to figure out where the pages specified in L<>
929 # links are on the filesystem.
932 my($dir, $recurse) = @_;
933 my($t, @subdirs, @pods, $pod, $dirname, @dirs);
939 opendir(DIR, $dir) ||
940 die "$0: error opening directory $dir: $!\n";
941 while (defined($_ = readdir(DIR))) {
942 if (-d "$dir/$_" && $_ ne "." && $_ ne ".."
943 && ($HiddenDirs || !/^\./)
945 $Pages{$_} = "" unless defined $Pages{$_};
946 $Pages{$_} .= "$dir/$_:";
948 } elsif (/\.pod\z/) { # .pod
950 $Pages{$_} = "" unless defined $Pages{$_};
951 $Pages{$_} .= "$dir/$_.pod:";
952 push(@pods, "$dir/$_.pod");
953 } elsif (/\.html\z/) { # .html
955 $Pages{$_} = "" unless defined $Pages{$_};
956 $Pages{$_} .= "$dir/$_.pod:";
957 } elsif (/\.pm\z/) { # .pm
959 $Pages{$_} = "" unless defined $Pages{$_};
960 $Pages{$_} .= "$dir/$_.pm:";
961 push(@pods, "$dir/$_.pm");
966 # recurse on the subdirectories if necessary
968 foreach my $subdir (@subdirs) {
969 scan_dir("$dir/$subdir", $recurse);
975 # scan_headings - scan a pod file for head[1-6] tags, note the tags, and
979 my($sections, @data) = @_;
980 my($tag, $which_head, $otitle, $listdepth, $index);
987 # scan for =head directives, note their name, and build an index
988 # pointing to each of them.
989 foreach my $line (@data) {
990 if ($line =~ /^=(head)([1-6])\s+(.*)/) {
991 ($tag, $which_head, $otitle) = ($1,$2,$3);
993 my $title = depod( $otitle );
994 my $name = anchorify( $title );
995 $$sections{$name} = 1;
996 $title = process_text( \$otitle );
998 while ($which_head != $listdepth) {
999 if ($which_head > $listdepth) {
1000 $index .= "\n" . ("\t" x $listdepth) . "<ul>\n";
1002 } elsif ($which_head < $listdepth) {
1004 $index .= "\n" . ("\t" x $listdepth) . "</ul>\n";
1008 $index .= "\n" . ("\t" x $listdepth) . "<li>" .
1009 "<a href=\"#" . $name . "\">" .
1010 $title . "</a></li>";
1014 # finish off the lists
1015 while ($listdepth--) {
1016 $index .= "\n" . ("\t" x $listdepth) . "</ul>\n";
1019 # get rid of bogus lists
1020 $index =~ s,\t*<ul>\s*</ul>\n,,g;
1026 # scan_items - scans the pod specified by $pod for =item directives. we
1027 # will use this information later on in resolving C<> links.
1030 my( $itemref, $pod, @poddata ) = @_;
1034 $pod =~ s/\.pod\z//;
1035 $pod .= ".html" if $pod;
1037 foreach $i (0..$#poddata) {
1038 my $txt = depod( $poddata[$i] );
1040 # figure out what kind of item it is.
1041 # Build string for referencing this item.
1042 if ( $txt =~ /\A=item\s+\*\s*(.*)\Z/s ) { # bullet
1045 } elsif( $txt =~ /\A=item\s+(?>\d+\.?)\s*(.*)\Z/s ) { # numbered list
1047 } elsif( $txt =~ /\A=item\s+(.*)\Z/s ) { # plain item
1052 my $fid = fragment_id( $item );
1053 $$itemref{$fid} = "$pod" if $fid;
1058 # process_head - convert a pod head[1-6] tag and convert it to HTML format.
1061 my($tag, $heading, $hasindex) = @_;
1063 # figure out the level of the =head
1064 $tag =~ /head([1-6])/;
1068 warn "$0: $Podfile: unterminated list at =head in paragraph $Paragraph. ignoring.\n";
1069 while( $Listlevel ){
1075 if( $level == 1 && ! $Top ){
1076 print HTML "<a href=\"#__index__\"><small>$Backlink</small></a>\n"
1077 if $hasindex and $Backlink;
1078 print HTML "</p>\n<hr />\n"
1080 print HTML "</p>\n";
1083 my $name = anchorify( depod( $heading ) );
1084 my $convert = process_text( \$heading );
1085 print HTML "<h$level><a name=\"$name\">$convert</a></h$level>\n";
1090 # emit_item_tag - print an =item's text
1091 # Note: The global $EmittedItem is used for inhibiting self-references.
1095 sub emit_item_tag($$$){
1096 my( $otext, $text, $compact ) = @_;
1097 my $item = fragment_id( $text );
1099 $EmittedItem = $item;
1100 ### print STDERR "emit_item_tag=$item ($text)\n";
1102 print HTML '<strong>';
1103 if ($Items_Named{$item}++) {
1104 print HTML process_text( \$otext );
1106 my $name = 'item_' . $item;
1107 $name = anchorify($name);
1108 print HTML qq{<a name="$name">}, process_text( \$otext ), '</a>';
1110 print HTML "</strong><br />\n";
1111 undef( $EmittedItem );
1116 if( $Items_Seen[$Listlevel]++ == 0 ){
1117 push( @Listend, "</$tag>" );
1118 print HTML "<$tag>\n";
1120 my $emitted = $tag eq 'dl' ? 'dt' : 'li';
1121 print HTML "<$emitted>";
1126 # process_item - convert a pod item tag and convert it to HTML format.
1130 my $need_dd = 0; # set to 1 if we need a <dd></dd> after an item
1132 # lots of documents start a list without doing an =over. this is
1133 # bad! but, the proper thing to do seems to be to just assume
1134 # they did do an =over. so warn them once and then continue.
1135 if( $Listlevel == 0 ){
1136 warn "$0: $Podfile: unexpected =item directive in paragraph $Paragraph. ignoring.\n";
1140 # formatting: insert a paragraph if preceding item has >1 paragraph
1142 print HTML "<p></p>\n";
1146 # remove formatting instructions from the text
1147 my $text = depod( $otext );
1149 my $emitted; # the tag actually emitted, used for closing
1151 # all the list variants:
1152 if( $text =~ /\A\*/ ){ # bullet
1153 $emitted = emit_li( 'ul' );
1154 if ($text =~ /\A\*\s+(.+)\Z/s ) { # with additional text
1156 $otext =~ s/\A\*\s+//;
1157 emit_item_tag( $otext, $tag, 1 );
1160 } elsif( $text =~ /\A\d+/ ){ # numbered list
1161 $emitted = emit_li( 'ol' );
1162 if ($text =~ /\A(?>\d+\.?)\s*(.+)\Z/s ) { # with additional text
1164 $otext =~ s/\A\d+\.?\s*//;
1165 emit_item_tag( $otext, $tag, 1 );
1168 } else { # definition list
1169 $emitted = emit_li( 'dl' );
1170 if ($text =~ /\A(.+)\Z/s ){ # should have text
1171 emit_item_tag( $otext, $text, 1 );
1175 print HTML "</$emitted>" if $emitted;
1181 # process_over - process a pod over tag and start a corresponding HTML list.
1186 push( @Items_Seen, 0 );
1191 # process_back - process a pod back tag and convert it to HTML format.
1194 if( $Listlevel == 0 ){
1195 warn "$0: $Podfile: unexpected =back directive in paragraph $Paragraph. ignoring.\n";
1199 # close off the list. note, I check to see if $Listend[$Listlevel] is
1200 # defined because an =item directive may have never appeared and thus
1201 # $Listend[$Listlevel] may have never been initialized.
1203 if( defined $Listend[$Listlevel] ){
1204 print HTML '<p></p>' if $After_Lpar;
1205 print HTML $Listend[$Listlevel];
1211 # clean up item count
1216 # process_cut - process a pod cut tag, thus start ignoring pod directives.
1223 # process_pod - process a pod tag, thus stop ignoring pod directives
1224 # until we see a corresponding cut.
1227 # no need to set $Ignore to 0 cause the main loop did it
1231 # process_for - process a =for pod tag. if it's for html, spit
1232 # it out verbatim, if illustration, center it, otherwise ignore it.
1235 my($whom, $text) = @_;
1236 if ( $whom =~ /^(pod2)?html$/i) {
1238 } elsif ($whom =~ /^illustration$/i) {
1239 1 while chomp $text;
1240 for my $ext (qw[.png .gif .jpeg .jpg .tga .pcl .bmp]) {
1241 $text .= $ext, last if -r "$text$ext";
1243 print HTML qq{<p align="center"><img src="$text" alt="$text illustration" /></p>};
1248 # process_begin - process a =begin pod tag. this pushes
1249 # whom we're beginning on the begin stack. if there's a
1250 # begin stack, we only print if it us.
1253 my($whom, $text) = @_;
1255 push (@Begin_Stack, $whom);
1256 if ( $whom =~ /^(pod2)?html$/) {
1257 print HTML $text if $text;
1262 # process_end - process a =end pod tag. pop the
1263 # begin stack. die if we're mismatched.
1266 my($whom, $text) = @_;
1268 if ($Begin_Stack[-1] ne $whom ) {
1269 die "Unmatched begin/end at chunk $Paragraph\n"
1271 pop( @Begin_Stack );
1275 # process_pre - indented paragraph, made into <pre></pre>
1284 # insert spaces in place of tabs
1287 1 while $line =~ s/(\t+)/' ' x ((length($1) * 8) - $-[0] % 8)/e;
1291 # convert some special chars to HTML escapes
1292 $rest = html_escape($rest);
1294 # try and create links for all occurrences of perl.* within
1295 # the preformatted text.
1299 if ( defined $Pages{$2} ){ # is a link
1300 qq($1<a href="$Htmlroot/$Pages{$2}">$2</a>);
1301 } elsif (defined $Pages{dosify($2)}) { # is a link
1302 qq($1<a href="$Htmlroot/$Pages{dosify($2)}">$2</a>);
1308 (<a\ href="?) ([^>:]*:)? ([^>:]*) \.pod: ([^>:]*:)?
1311 if ( $Htmlfileurl ne '' ){
1312 # Here, we take advantage of the knowledge
1313 # that $Htmlfileurl ne '' implies $Htmlroot eq ''.
1314 # Since $Htmlroot eq '', we need to prepend $Htmldir
1315 # on the fron of the link to get the absolute path
1316 # of the link's target. We check for a leading '/'
1317 # to avoid corrupting links that are #, file:, etc.
1319 $old_url = "$Htmldir$old_url" if $old_url =~ m{^\/};
1320 $url = relativize_url( "$old_url.html", $Htmlfileurl );
1327 # Look for embedded URLs and make them into links. We don't
1328 # relativize them since they are best left as the author intended.
1330 my $urls = '(' . join ('|', qw{
1343 my $gunk = '/#~:.?+=&%@!\-';
1344 my $punc = '.:!?\-;';
1345 my $any = "${ltrs}${gunk}${punc}";
1348 \b # start at word boundary
1350 $urls : # need resource and a colon
1351 (?!:) # Ignore File::, among others.
1352 [$any] +? # followed by one or more of any valid
1353 # character, but be conservative and
1354 # take only what you need to....
1357 " > # maybe pre-quoted '<a href="...">'
1359 [$punc]* # 0 or more punctuation
1361 [^$any] # by a non-url char
1363 $ # end of the string
1366 $ # then end of the string
1368 }{<a href="$1">$1</a>}igox;
1370 # text should be as it is (verbatim)
1376 # pure text processing
1378 # pure_text/inIS_text: differ with respect to automatic C<> recognition.
1379 # we don't want this to happen within IS
1383 process_puretext( $text, \$PTQuote, 1 );
1388 process_puretext( $text, \$PTQuote, 0 );
1392 # process_puretext - process pure text (without pod-escapes) converting
1393 # double-quotes and handling implicit C<> links.
1395 sub process_puretext {
1396 my($text, $quote, $notinIS) = @_;
1398 ## Guessing at func() or [$@%&]*var references in plain text is destined
1399 ## to produce some strange looking ref's. uncomment to disable:
1402 my(@words, $lead, $trail);
1404 # convert double-quotes to single-quotes
1405 if( $$quote && $text =~ s/"/''/s ){
1408 while ($text =~ s/"([^"]*)"/``$1''/sg) {};
1409 $$quote = 1 if $text =~ s/"/``/s;
1411 # keep track of leading and trailing white-space
1412 $lead = ($text =~ s/\A(\s+)//s ? $1 : "");
1413 $trail = ($text =~ s/(\s+)\Z//s ? $1 : "");
1415 # split at space/non-space boundaries
1416 @words = split( /(?<=\s)(?=\S)|(?<=\S)(?=\s)/, $text );
1418 # process each word individually
1419 foreach my $word (@words) {
1421 next if $word =~ /^\s*$/;
1422 # see if we can infer a link
1423 if( $notinIS && $word =~ /^(\w+)\((.*)\)$/ ) {
1424 # has parenthesis so should have been a C<> ref
1425 ## try for a pagename (perlXXX(1))?
1426 my( $func, $args ) = ( $1, $2 );
1427 if( $args =~ /^\d+$/ ){
1428 my $url = page_sect( $word, '' );
1430 $word = "<a href=\"$url\">the $word manpage</a>";
1434 ## try function name for a link, append tt'ed argument list
1435 $word = emit_C( $func, '', "($args)");
1437 #### disabled. either all (including $\W, $\w+{.*} etc.) or nothing.
1438 ## } elsif( $notinIS && $word =~ /^[\$\@%&*]+\w+$/) {
1439 ## # perl variables, should be a C<> ref
1440 ## $word = emit_C( $word );
1442 } elsif ($word =~ m,^\w+://\w,) {
1444 # Don't relativize it: leave it as the author intended
1445 $word = qq(<a href="$word">$word</a>);
1446 } elsif ($word =~ /[\w.-]+\@[\w-]+\.\w/) {
1447 # looks like an e-mail address
1448 my ($w1, $w2, $w3) = ("", $word, "");
1449 ($w1, $w2, $w3) = ("(", $1, ")$2") if $word =~ /^\((.*?)\)(,?)/;
1450 ($w1, $w2, $w3) = ("<", $1, ">$2") if $word =~ /^<(.*?)>(,?)/;
1451 $word = qq($w1<a href="mailto:$w2">$w2</a>$w3);
1453 $word = html_escape($word) if $word =~ /["&<>]/;
1457 # put everything back together
1458 return $lead . join( '', @words ) . $trail;
1463 # process_text - handles plaintext that appears in the input pod file.
1464 # there may be pod commands embedded within the text so those must be
1465 # converted to html commands.
1468 sub process_text1($$;$$);
1469 sub pattern ($) { $_[0] ? '[^\S\n]+'.('>' x ($_[0] + 1)) : '>' }
1470 sub closing ($) { local($_) = shift; (defined && s/\s+$//) ? length : 0 }
1475 my $res = process_text1( 0, $tref );
1479 sub process_text1($$;$$){
1480 my( $lev, $rstr, $func, $closing ) = @_;
1483 unless (defined $func) {
1489 # B<text> - boldface
1490 $res = '<strong>' . process_text1( $lev, $rstr ) . '</strong>';
1492 } elsif( $func eq 'C' ){
1493 # C<code> - can be a ref or <code></code>
1494 # need to extract text
1495 my $par = go_ahead( $rstr, 'C', $closing );
1497 ## clean-up of the link target
1498 my $text = depod( $par );
1500 ### my $x = $par =~ /[BI]</ ? 'yes' : 'no' ;
1501 ### print STDERR "-->call emit_C($par) lev=$lev, par with BI=$x\n";
1503 $res = emit_C( $text, $lev > 1 || ($par =~ /[BI]</) );
1505 } elsif( $func eq 'E' ){
1506 # E<x> - convert to character
1507 $$rstr =~ s/^([^>]*)>//;
1509 $escape =~ s/^(\d+|X[\dA-F]+)$/#$1/i;
1512 } elsif( $func eq 'F' ){
1513 # F<filename> - italizice
1514 $res = '<em>' . process_text1( $lev, $rstr ) . '</em>';
1516 } elsif( $func eq 'I' ){
1517 # I<text> - italizice
1518 $res = '<em>' . process_text1( $lev, $rstr ) . '</em>';
1520 } elsif( $func eq 'L' ){
1522 ## L<text|cross-ref> => produce text, use cross-ref for linking
1523 ## L<cross-ref> => make text from cross-ref
1524 ## need to extract text
1525 my $par = go_ahead( $rstr, 'L', $closing );
1527 # some L<>'s that shouldn't be:
1528 # a) full-blown URL's are emitted as-is
1529 if( $par =~ m{^\w+://}s ){
1530 return make_URL_href( $par );
1532 # b) C<...> is stripped and treated as C<>
1533 if( $par =~ /^C<(.*)>$/ ){
1534 my $text = depod( $1 );
1535 return emit_C( $text, $lev > 1 || ($par =~ /[BI]</) );
1538 # analyze the contents
1539 $par =~ s/\n/ /g; # undo word-wrapped tags
1542 if( $par =~ s{^([^|]+)\|}{} ){
1546 # make sure sections start with a /
1549 my( $page, $section, $ident );
1551 # check for link patterns
1552 if( $par =~ m{^([^/]+?)/(?!")(.*?)$} ){ # name/ident
1553 # we've got a name/ident (no quotes)
1554 ( $page, $ident ) = ( $1, $2 );
1555 ### print STDERR "--> L<$par> to page $page, ident $ident\n";
1557 } elsif( $par =~ m{^(.*?)/"?(.*?)"?$} ){ # [name]/"section"
1558 # even though this should be a "section", we go for ident first
1559 ( $page, $ident ) = ( $1, $2 );
1560 ### print STDERR "--> L<$par> to page $page, section $section\n";
1562 } elsif( $par =~ /\s/ ){ # this must be a section with missing quotes
1563 ( $page, $section ) = ( '', $par );
1564 ### print STDERR "--> L<$par> to void page, section $section\n";
1567 ( $page, $section ) = ( $par, '' );
1568 ### print STDERR "--> L<$par> to page $par, void section\n";
1571 # now, either $section or $ident is defined. the convoluted logic
1572 # below tries to resolve L<> according to what the user specified.
1573 # failing this, we try to find the next best thing...
1574 my( $url, $ltext, $fid );
1577 if( defined $ident ){
1578 ## try to resolve $ident as an item
1579 ( $url, $fid ) = coderef( $page, $ident );
1581 if( ! defined( $linktext ) ){
1583 $linktext .= " in " if $ident && $page;
1584 $linktext .= "the $page manpage" if $page;
1586 ### print STDERR "got coderef url=$url\n";
1589 ## no luck: go for a section (auto-quoting!)
1592 ## now go for a section
1593 my $htmlsection = htmlify( $section );
1594 $url = page_sect( $page, $htmlsection );
1596 if( ! defined( $linktext ) ){
1597 $linktext = $section;
1598 $linktext .= " in " if $section && $page;
1599 $linktext .= "the $page manpage" if $page;
1601 ### print STDERR "got page/section url=$url\n";
1604 ## no luck: go for an ident
1611 ( $url, $fid ) = coderef( $page, $ident );
1613 if( ! defined( $linktext ) ){
1615 $linktext .= " in " if $ident && $page;
1616 $linktext .= "the $page manpage" if $page;
1618 ### print STDERR "got section=>coderef url=$url\n";
1622 # warning; show some text.
1623 $linktext = $opar unless defined $linktext;
1624 warn "$0: $Podfile: cannot resolve L<$opar> in paragraph $Paragraph.\n";
1627 # now we have a URL or just plain code
1628 $$rstr = $linktext . '>' . $$rstr;
1629 if( defined( $url ) ){
1630 $res = "<a href=\"$url\">" . process_text1( $lev, $rstr ) . '</a>';
1632 $res = '<em>' . process_text1( $lev, $rstr ) . '</em>';
1635 } elsif( $func eq 'S' ){
1636 # S<text> - non-breaking spaces
1637 $res = process_text1( $lev, $rstr );
1638 $res =~ s/ / /g;
1640 } elsif( $func eq 'X' ){
1642 $$rstr =~ s/^[^>]*>//;
1644 } elsif( $func eq 'Z' ){
1646 warn "$0: $Podfile: invalid X<> in paragraph $Paragraph.\n"
1647 unless $$rstr =~ s/^>//;
1650 my $term = pattern $closing;
1651 while( $$rstr =~ s/\A(.*?)(([BCEFILSXZ])<(<+[^\S\n]+)?|$term)//s ){
1652 # all others: either recurse into new function or
1653 # terminate at closing angle bracket(s)
1655 $pt .= $2 if !$3 && $lev == 1;
1656 $res .= $lev == 1 ? pure_text( $pt ) : inIS_text( $pt );
1657 return $res if !$3 && $lev > 1;
1659 $res .= process_text1( $lev, $rstr, $3, closing $4 );
1663 $res .= pure_text( $$rstr );
1665 warn "$0: $Podfile: undelimited $func<> in paragraph $Paragraph.\n";
1672 # go_ahead: extract text of an IS (can be nested)
1675 my( $rstr, $func, $closing ) = @_;
1677 my @closing = ($closing);
1679 s/\A(.*?)(([BCEFILSXZ])<(<+[^\S\n]+)?|@{[pattern $closing[0]]})//s ){
1683 return $res unless @closing;
1685 unshift @closing, closing $4;
1689 warn "$0: $Podfile: undelimited $func<> in paragraph $Paragraph.\n";
1694 # emit_C - output result of C<text>
1695 # $text is the depod-ed text
1698 my( $text, $nocode, $args ) = @_;
1699 $args = '' unless defined $args;
1701 my( $url, $fid ) = coderef( undef(), $text );
1703 # need HTML-safe text
1704 my $linktext = html_escape( "$text$args" );
1706 if( defined( $url ) &&
1707 (!defined( $EmittedItem ) || $EmittedItem ne $fid ) ){
1708 $res = "<a href=\"$url\"><code>$linktext</code></a>";
1709 } elsif( 0 && $nocode ){
1712 $res = "<code>$linktext</code>";
1718 # html_escape: make text safe for HTML
1722 $rest =~ s/&/&/g;
1723 $rest =~ s/</</g;
1724 $rest =~ s/>/>/g;
1725 $rest =~ s/"/"/g;
1726 # ' is only in XHTML, not HTML4. Be conservative
1727 #$rest =~ s/'/'/g;
1733 # dosify - convert filenames to 8.3
1737 return lc($str) if $^O eq 'VMS'; # VMS just needs casing
1740 $str =~ s/(\.\w+)/substr ($1,0,4)/ge;
1741 $str =~ s/(\w+)/substr ($1,0,8)/ge;
1747 # page_sect - make a URL from the text of a L<>
1750 my( $page, $section ) = @_;
1751 my( $linktext, $page83, $link); # work strings
1753 # check if we know that this is a section in this page
1754 if (!defined $Pages{$page} && defined $Sections{$page}) {
1757 ### print STDERR "reset page='', section=$section\n";
1760 $page83=dosify($page);
1761 $page=$page83 if (defined $Pages{$page83});
1763 $link = "#" . anchorify( $section );
1764 } elsif ( $page =~ /::/ ) {
1766 # Search page cache for an entry keyed under the html page name,
1767 # then look to see what directory that page might be in. NOTE:
1768 # this will only find one page. A better solution might be to produce
1769 # an intermediate page that is an index to all such pages.
1770 my $page_name = $page ;
1771 $page_name =~ s,^.*/,,s ;
1772 if ( defined( $Pages{ $page_name } ) &&
1773 $Pages{ $page_name } =~ /([^:]*$page)\.(?:pod|pm):/
1778 # NOTE: This branch assumes that all A::B pages are located in
1779 # $Htmlroot/A/B.html . This is often incorrect, since they are
1780 # often in $Htmlroot/lib/A/B.html or such like. Perhaps we could
1781 # analyze the contents of %Pages and figure out where any
1782 # cousins of A::B are, then assume that. So, if A::B isn't found,
1783 # but A::C is found in lib/A/C.pm, then A::B is assumed to be in
1784 # lib/A/B.pm. This is also limited, but it's an improvement.
1785 # Maybe a hints file so that the links point to the correct places
1789 $link = "$Htmlroot/$page.html";
1790 $link .= "#" . anchorify( $section ) if ($section);
1791 } elsif (!defined $Pages{$page}) {
1794 $section = anchorify( $section ) if $section ne "";
1795 ### print STDERR "...section=$section\n";
1797 # if there is a directory by the name of the page, then assume that an
1798 # appropriate section will exist in the subdirectory
1799 # if ($section ne "" && $Pages{$page} =~ /([^:]*[^(\.pod|\.pm)]):/) {
1800 if ($section ne "" && $Pages{$page} =~ /([^:]*(?<!\.pod)(?<!\.pm)):/) {
1801 $link = "$Htmlroot/$1/$section.html";
1802 ### print STDERR "...link=$link\n";
1804 # since there is no directory by the name of the page, the section will
1805 # have to exist within a .html of the same name. thus, make sure there
1806 # is a .pod or .pm that might become that .html
1808 $section = "#$section" if $section;
1809 ### print STDERR "...section=$section\n";
1811 # check if there is a .pod with the page name
1812 if ($Pages{$page} =~ /([^:]*)\.pod:/) {
1813 $link = "$Htmlroot/$1.html$section";
1814 } elsif ($Pages{$page} =~ /([^:]*)\.pm:/) {
1815 $link = "$Htmlroot/$1.html$section";
1823 # Here, we take advantage of the knowledge that $Htmlfileurl ne ''
1824 # implies $Htmlroot eq ''. This means that the link in question
1825 # needs a prefix of $Htmldir if it begins with '/'. The test for
1826 # the initial '/' is done to avoid '#'-only links, and to allow
1827 # for other kinds of links, like file:, ftp:, etc.
1829 if ( $Htmlfileurl ne '' ) {
1830 $link = "$Htmldir$link" if $link =~ m{^/}s;
1831 $url = relativize_url( $link, $Htmlfileurl );
1832 # print( " b: [$link,$Htmlfileurl,$url]\n" );
1845 # relativize_url - convert an absolute URL to one relative to a base URL.
1846 # Assumes both end in a filename.
1848 sub relativize_url {
1849 my ($dest,$source) = @_ ;
1851 my ($dest_volume,$dest_directory,$dest_file) =
1852 File::Spec::Unix->splitpath( $dest ) ;
1853 $dest = File::Spec::Unix->catpath( $dest_volume, $dest_directory, '' ) ;
1855 my ($source_volume,$source_directory,$source_file) =
1856 File::Spec::Unix->splitpath( $source ) ;
1857 $source = File::Spec::Unix->catpath( $source_volume, $source_directory, '' ) ;
1860 if ( $dest ne '' ) {
1861 $rel_path = File::Spec::Unix->abs2rel( $dest, $source ) ;
1864 if ( $rel_path ne '' &&
1865 substr( $rel_path, -1 ) ne '/' &&
1866 substr( $dest_file, 0, 1 ) ne '#'
1868 $rel_path .= "/$dest_file" ;
1871 $rel_path .= "$dest_file" ;
1879 # coderef - make URL from the text of a C<>
1882 my( $page, $item ) = @_;
1885 my $fid = fragment_id( $item );
1886 if( defined( $page ) ){
1887 # we have been given a $page...
1890 # Do we take it? Item could be a section!
1891 my $base = $Items{$fid} || "";
1892 $base =~ s{[^/]*/}{};
1893 if( $base ne "$page.html" ){
1894 ### print STDERR "coderef( $page, $item ): items{$fid} = $Items{$fid} = $base => discard page!\n";
1899 # no page - local items precede cached items
1900 if( defined( $fid ) ){
1901 if( exists $Local_Items{$fid} ){
1902 $page = $Local_Items{$fid};
1904 $page = $Items{$fid};
1909 # if there was a pod file that we found earlier with an appropriate
1910 # =item directive, then create a link to that page.
1911 if( defined $page ){
1913 if( exists $Pages{$page} and $Pages{$page} =~ /([^:.]*)\.[^:]*:/){
1914 $page = $1 . '.html';
1916 my $link = "$Htmlroot/$page#item_" . anchorify($fid);
1918 # Here, we take advantage of the knowledge that $Htmlfileurl
1919 # ne '' implies $Htmlroot eq ''.
1920 if ( $Htmlfileurl ne '' ) {
1921 $link = "$Htmldir$link" ;
1922 $url = relativize_url( $link, $Htmlfileurl ) ;
1927 $url = "#item_" . anchorify($fid);
1930 confess "url has space: $url" if $url =~ /"[^"]*\s[^"]*"/;
1932 return( $url, $fid );
1938 # Adapted from Nick Ing-Simmons' PodToHtml package.
1940 my $source_file = shift ;
1941 my $destination_file = shift;
1943 my $source = URI::file->new_abs($source_file);
1944 my $uo = URI::file->new($destination_file,$source)->abs;
1945 return $uo->rel->as_string;
1950 # finish_list - finish off any pending HTML lists. this should be called
1951 # after the entire pod file has been read and converted.
1954 while ($Listlevel > 0) {
1955 print HTML "</dl>\n";
1961 # htmlify - converts a pod section specification to a suitable section
1962 # specification for HTML. Note that we keep spaces and special characters
1963 # except ", ? (Netscape problem) and the hyphen (writer's problem...).
1967 $heading =~ s/(\s+)/ /g;
1968 $heading =~ s/\s+\Z//;
1969 $heading =~ s/\A\s+//;
1970 # The hyphen is a disgrace to the English language.
1971 $heading =~ s/[-"?]//g;
1972 $heading = lc( $heading );
1977 # similar to htmlify, but turns non-alphanumerics into underscores
1981 $anchor = htmlify($anchor);
1982 $anchor =~ s/\W/_/g;
1987 # depod - convert text by eliminating all interior sequences
1988 # Note: can be called with copy or modify semantics
1995 $E2c{amp} = '&'; # in Tk's pods
2003 ${$_[0]} = depod1( \$string );
2011 my( $rstr, $func, $closing ) = @_;
2013 return $res unless defined $$rstr;
2014 if( ! defined( $func ) ){
2015 # skip to next begin of an interior sequence
2016 while( $$rstr =~ s/\A(.*?)([BCEFILSXZ])<(<+[^\S\n]+)?// ){
2017 # recurse into its text
2018 $res .= $1 . depod1( $rstr, $2, closing $3);
2021 } elsif( $func eq 'E' ){
2022 # E<x> - convert to character
2023 $$rstr =~ s/^([^>]*)>//;
2024 $res .= $E2c{$1} || "";
2025 } elsif( $func eq 'X' ){
2027 $$rstr =~ s/^[^>]*>//;
2028 } elsif( $func eq 'Z' ){
2032 # all others: either recurse into new function or
2033 # terminate at closing angle bracket
2034 my $term = pattern $closing;
2035 while( $$rstr =~ s/\A(.*?)(([BCEFILSXZ])<(<+[^\S\n]+)?|$term)// ){
2038 $res .= depod1( $rstr, $3, closing $4 );
2040 ## If we're here and $2 ne '>': undelimited interior sequence.
2041 ## Ignored, as this is called without proper indication of where we are.
2042 ## Rely on process_text to produce diagnostics.
2048 # fragment_id - construct a fragment identifier from:
2050 # b) contents of C<...>
2055 $text =~ s/\s+\Z//s;
2057 # a method or function?
2058 return $1 if $text =~ /(\w+)\s*\(/;
2059 return $1 if $text =~ /->\s*(\w+)\s*\(?/;
2062 return $1 if $text =~ /^([$@%*]\S+)/;
2064 # some pattern matching operator?
2065 return $1 if $text =~ m|^(\w+/).*/\w*$|;
2067 # fancy stuff... like "do { }"
2068 return $1 if $text =~ m|^(\w+)\s*{.*}$|;
2070 # honour the perlfunc manpage: func [PAR[,[ ]PAR]...]
2071 # and some funnies with ... Module ...
2072 return $1 if $text =~ m{^([a-z\d]+)(\s+[A-Z\d,/& ]+)?$};
2073 return $1 if $text =~ m{^([a-z\d]+)\s+Module(\s+[A-Z\d,/& ]+)?$};
2076 $text =~ s/\s+/_/sg;
2078 defined( $HC[ord($1)] ) ? $HC[ord($1)]
2079 : ( $HC[ord($1)] = sprintf( "%%%02X", ord($1) ) ) }gxe;
2080 $text = substr( $text, 0, 50 );
2087 # make_URL_href - generate HTML href from URL
2088 # Special treatment for CGI queries.
2090 sub make_URL_href($){
2093 s{^(http:[-\w/#~:.+=&%@!]+)(\?.*)$}{<a href="$1$2">$1</a>}i ){
2094 $url = "<a href=\"$url\">$url</a>";