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.
85 Sets the directory in which the resulting HTML file is placed. This
86 is used to generate relative links to other files. Not passing this
87 causes all links to be absolute, since this is the value that tells
88 Pod::Html the root of the documentation tree.
94 Sets the base URL for the HTML files. When cross-references are made,
95 the HTML root is prepended to the URL.
102 Generate an index at the top of the HTML file. This is the default
109 Specify the pod file to convert. Input is taken from STDIN if no
114 --libpods=name:...:name
116 List of page names (eg, "perlfunc") which contain linkable C<=item>s.
123 B<Deprecated>, has no effect. For backwards compatibility only.
129 Specify the HTML file to create. Output goes to STDOUT if no outfile
134 --podpath=name:...:name
136 Specify which subdirectories of the podroot contain pod files whose
137 HTML converted forms can be linked to in cross references.
143 Specify the base directory for finding library pods.
150 Don't display I<mostly harmless> warning messages. These messages
151 will be displayed by default. But this is not the same as C<verbose>
159 Recurse into subdirectories specified in podpath (default behaviour).
165 Specify the title of the resulting HTML file.
172 Display progress messages. By default, they won't be displayed.
179 "--podpath=lib:ext:pod:vms",
180 "--podroot=/usr/src/perl",
181 "--htmlroot=/perl/nmanual",
182 "--libpods=perlfunc:perlguts:perlvar:perlrun:perlop",
185 "--outfile=/perl/nmanual/foo.html");
189 Uses C<$Config{pod2html}> to setup default options.
193 Tom Christiansen, E<lt>tchrist@perl.comE<gt>.
201 This program is distributed under the Artistic License.
207 my($dircache, $itemcache);
210 my($htmlroot, $htmldir, $htmlfile, $htmlfileurl);
211 my($podfile, @podpath, $podroot);
220 my($listlevel, @listend);
224 my(%items_named, @items_seen);
233 my %pages = (); # associative array used to find the location
234 # of pages referenced by L<> links.
235 my %items = (); # associative array used to find the location
236 # of =item directives referenced by C<> links
242 my $Curdir = File::Spec->curdir;
247 $cachedir = "."; # The directory to which item and directory
248 # caches will be written.
250 $dircache = "pod2htmd.tmp";
251 $itemcache = "pod2htmi.tmp";
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 $htmlfileurl = "" ; # The url that other files would use to
262 # refer to this file. This is only used
263 # to make relative urls that point to
266 $podfile = ""; # read from stdin by default
267 @podpath = (); # list of directories containing library pods.
268 $podroot = $Curdir; # filesystem base directory from which all
269 # relative paths in $podpath stem.
270 $css = ''; # Cascading style sheet
271 $recurse = 1; # recurse on subdirectories in $podpath.
272 $quiet = 0; # not quiet by default
273 $verbose = 0; # not verbose by default
274 $doindex = 1; # non-zero if we should generate an index
275 $backlink = ''; # text for "back to top" links
276 $listlevel = 0; # current list depth
277 @listend = (); # the text to use to end the list.
278 $after_lpar = 0; # set to true after a par in an =item
279 $ignore = 1; # whether or not to format text. we don't
280 # format text until we hit our first pod
283 @items_seen = (); # for multiples of the same item in perlfunc
285 $header = 0; # produce block header/footer
286 $title = ''; # title to give the pod(s)
287 $top = 1; # true if we are at the top of the doc. used
288 # to prevent the first <hr /> directive.
289 $paragraph = ''; # which paragraph we're processing (used
290 # for error messages)
291 $ptQuote = 0; # status of double-quote conversion
292 %sections = (); # sections within this page
295 $Is83 = $^O eq 'dos'; # Is it an 8.3 filesystem?
299 # clean_data: global clean-up of pod data
303 for my $i ( 0..$#{$dataref} ) {
304 ${$dataref}[$i] =~ s/\s+\Z//;
306 # have a look for all-space lines
307 if( ${$dataref}[$i] =~ /^\s+$/m and $dataref->[$i] !~ /^\s/ ){
308 my @chunks = split( /^\s+$/m, ${$dataref}[$i] );
309 splice( @$dataref, $i, 1, @chunks );
322 $Is83 = 0 if (defined (&Dos::UseLFN) && Dos::UseLFN());
324 # cache of %pages and %items from last time we ran pod2html
326 #undef $opt_help if defined $opt_help;
328 # parse the command-line parameters
329 parse_command_line();
331 # escape the backlink argument (same goes for title but is done later...)
332 $backlink = html_escape($backlink) if defined $backlink;
334 # set some variables to their default values if necessary
336 unless (@ARGV && $ARGV[0]) {
337 $podfile = "-" unless $podfile; # stdin
338 open(POD, "<$podfile")
339 || die "$0: cannot open $podfile file for input: $!\n";
341 $podfile = $ARGV[0]; # XXX: might be more filenames
344 $htmlfile = "-" unless $htmlfile; # stdout
345 $htmlroot = "" if $htmlroot eq "/"; # so we don't get a //
346 $htmldir =~ s#/\z## ; # so we don't get a //
348 && defined( $htmldir )
350 && substr( $htmlfile, 0, length( $htmldir ) ) eq $htmldir
353 # Set the 'base' url for this file, so that we can use it
354 # as the location from which to calculate relative links
355 # to other files. If this is '', then absolute links will
356 # be used throughout.
357 $htmlfileurl= "$htmldir/" . substr( $htmlfile, length( $htmldir ) + 1);
360 # read the pod a paragraph at a time
361 warn "Scanning for sections in input file(s)\n" if $verbose;
370 @poddata = map { s/\r\n/\n/g;
372 map { "$_\n\n" } split /\n\n/ :
375 @poddata = map { s/\r/\n/g;
377 map { "$_\n\n" } split /\n\n/ :
384 clean_data( \@poddata );
386 # scan the pod for =head[1-6] directives and build an index
387 my $index = scan_headings(\%sections, @poddata);
390 warn "No headings in $podfile\n" if $verbose;
393 # open the output file
394 open(HTML, ">$htmlfile")
395 || die "$0: cannot open $htmlfile file for output: $!\n";
397 # put a title in the HTML file if one wasn't specified
400 for (my $i = 0; $i < @poddata; $i++) {
401 if ($poddata[$i] =~ /^=head1\s*NAME\b/m) {
402 for my $para ( @poddata[$i, $i+1] ) {
404 if ($title) = $para =~ /(\S+\s+-+.*\S)/s;
411 if (!$title and $podfile =~ /\.pod\z/) {
412 # probably a split pod so take first =head[12] as title
413 for (my $i = 0; $i < @poddata; $i++) {
414 last if ($title) = $poddata[$i] =~ /^=head[12]\s*(.*)/;
416 warn "adopted '$title' as title for $podfile\n"
417 if $verbose and $title;
420 $title =~ s/\s*\(.*\)//;
422 warn "$0: no title for $podfile.\n" unless $quiet;
423 $podfile =~ /^(.*)(\.[^.\/]+)?\z/s;
424 $title = ($podfile eq "-" ? 'No Title' : $1);
425 warn "using $title" if $verbose;
427 $title = html_escape($title);
430 my $bodystyle = ' style="background-color: white"';
431 my $tdstyle = ' style="background-color: #cccccc"';
434 $csslink = qq(\n<link rel="stylesheet" href="$css" type="text/css" />);
435 $csslink =~ s,\\,/,g;
436 $csslink =~ s,(/.):,$1|,;
441 my $block = $header ? <<END_OF_BLOCK : '';
442 <table border="0" width="100%" cellspacing="0" cellpadding="3">
443 <tr><td class="block"$tdstyle valign="middle">
444 <big><strong><span class="block"> $title</span></strong></big>
449 print HTML <<END_OF_HEAD;
450 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
451 <html xmlns="http://www.w3.org/1999/xhtml">
453 <title>$title</title>$csslink
454 <link rev="made" href="mailto:$Config{perladmin}" />
461 # load/reload/validate/cache %pages and %items
462 get_cache($dircache, $itemcache, \@podpath, $podroot, $recurse);
464 # scan the pod for =item directives
465 scan_items( \%local_items, "", @poddata);
467 # put an index at the top of the file. note, if $doindex is 0 we
468 # still generate an index, but surround it with an html comment.
469 # that way some other program can extract it if desired.
471 print HTML "<p><a name=\"__index__\"></a></p>\n";
472 print HTML "<!-- INDEX BEGIN -->\n";
473 print HTML "<!--\n" unless $doindex;
475 print HTML "-->\n" unless $doindex;
476 print HTML "<!-- INDEX END -->\n\n";
477 print HTML "<hr />\n" if $doindex and $index;
479 # now convert this file
480 my $after_item; # set to true after an =item
482 warn "Converting input file $podfile\n" if $verbose;
483 foreach my $i (0..$#poddata){
484 $ptQuote = 0; # status of quote conversion
488 if (/^(=.*)/s) { # is it a pod directive?
493 if (/^=begin\s+(\S+)\s*(.*)/si) {# =begin
494 process_begin($1, $2);
495 } elsif (/^=end\s+(\S+)\s*(.*)/si) {# =end
497 } elsif (/^=cut/) { # =cut
499 } elsif (/^=pod/) { # =pod
502 next if @begin_stack && $begin_stack[-1] ne 'html';
504 if (/^=(head[1-6])\s+(.*\S)/s) { # =head[1-6] heading
505 process_head( $1, $2, $doindex && $index );
506 } elsif (/^=item\s*(.*\S)?/sm) { # =item text
507 $need_dd = process_item( $1 );
509 } elsif (/^=over\s*(.*)/) { # =over N
511 } elsif (/^=back/) { # =back
513 } elsif (/^=for\s+(\S+)\s*(.*)/si) {# =for
517 warn "$0: $podfile: unknown pod directive '$1' in "
518 . "paragraph $paragraph. ignoring.\n";
525 next if @begin_stack && $begin_stack[-1] ne 'html';
526 print HTML and next if @begin_stack && $begin_stack[-1] eq 'html';
527 print HTML "<dd>\n" if $need_dd;
529 if( $text =~ /\A\s+/ ){
530 process_pre( \$text );
531 print HTML "<pre>\n$text</pre>\n";
534 process_text( \$text );
536 # experimental: check for a paragraph where all lines
537 # have some ...\t...\t...\n pattern
539 my @lines = split( "\n", $text );
542 foreach my $line ( @lines ){
543 if( $line =~ /\S/ && $line !~ /\t/ ){
549 $text =~ s/\t+/<td>/g;
550 $text =~ s/^/<tr><td>/gm;
551 $text = '<table cellspacing="0" cellpadding="0">' .
556 ## end of experimental
559 print HTML "$text\n";
562 print HTML "<p>$text</p>\n";
565 print HTML "</dd>\n" if $need_dd;
570 # finish off any pending directives
574 print HTML "<p><a href=\"#__index__\"><small>$backlink</small></a></p>\n"
575 if $doindex and $index and $backlink;
577 print HTML <<END_OF_TAIL;
584 # close the html file
587 warn "Finished\n" if $verbose;
590 ##############################################################################
592 my $usage; # see below
595 warn "$0: $podfile: @_\n" if @_;
599 $usage =<<END_OF_USAGE;
600 Usage: $0 --help --htmlroot=<name> --infile=<name> --outfile=<name>
601 --podpath=<name>:...:<name> --podroot=<name>
602 --libpods=<name>:...:<name> --recurse --verbose --index
603 --netscape --norecurse --noindex --cachedir=<name>
605 --backlink - set text for "back to top" links (default: none).
606 --cachedir - directory for the item and directory cache files.
607 --css - stylesheet URL
608 --flush - flushes the item and directory caches.
609 --[no]header - produce block header/footer (default is no headers).
610 --help - prints this message.
611 --htmldir - directory for resulting HTML files.
612 --htmlroot - http-server base directory from which all relative paths
613 in podpath stem (default is /).
614 --[no]index - generate an index at the top of the resulting html
616 --infile - filename for the pod to convert (input taken from stdin
618 --libpods - colon-separated list of pages to search for =item pod
619 directives in as targets of C<> and implicit links (empty
620 by default). note, these are not filenames, but rather
621 page names like those that appear in L<> links.
622 --outfile - filename for the resulting html file (output sent to
624 --podpath - colon-separated list of directories containing library
625 pods (empty by default).
626 --podroot - filesystem base directory from which all relative paths
627 in podpath stem (default is .).
628 --[no]quiet - supress some benign warning messages (default is off).
629 --[no]recurse - recurse on those subdirectories listed in podpath
631 --title - title that will appear in resulting html file.
632 --[no]verbose - self-explanatory (off by default).
633 --[no]netscape - deprecated, has no effect. for backwards compatibility only.
637 sub parse_command_line {
638 my ($opt_backlink,$opt_cachedir,$opt_css,$opt_flush,$opt_header,$opt_help,
639 $opt_htmldir,$opt_htmlroot,$opt_index,$opt_infile,$opt_libpods,
640 $opt_netscape,$opt_outfile,$opt_podpath,$opt_podroot,$opt_quiet,
641 $opt_recurse,$opt_title,$opt_verbose);
643 unshift @ARGV, split ' ', $Config{pod2html} if $Config{pod2html};
644 my $result = GetOptions(
645 'backlink=s' => \$opt_backlink,
646 'cachedir=s' => \$opt_cachedir,
647 'css=s' => \$opt_css,
648 'flush' => \$opt_flush,
649 'header!' => \$opt_header,
650 'help' => \$opt_help,
651 'htmldir=s' => \$opt_htmldir,
652 'htmlroot=s' => \$opt_htmlroot,
653 'index!' => \$opt_index,
654 'infile=s' => \$opt_infile,
655 'libpods=s' => \$opt_libpods,
656 'netscape!' => \$opt_netscape,
657 'outfile=s' => \$opt_outfile,
658 'podpath=s' => \$opt_podpath,
659 'podroot=s' => \$opt_podroot,
660 'quiet!' => \$opt_quiet,
661 'recurse!' => \$opt_recurse,
662 'title=s' => \$opt_title,
663 'verbose!' => \$opt_verbose,
665 usage("-", "invalid parameters") if not $result;
667 usage("-") if defined $opt_help; # see if the user asked for help
668 $opt_help = ""; # just to make -w shut-up.
670 @podpath = split(":", $opt_podpath) if defined $opt_podpath;
671 @libpods = split(":", $opt_libpods) if defined $opt_libpods;
673 $backlink = $opt_backlink if defined $opt_backlink;
674 $cachedir = $opt_cachedir if defined $opt_cachedir;
675 $css = $opt_css if defined $opt_css;
676 $header = $opt_header if defined $opt_header;
677 $htmldir = $opt_htmldir if defined $opt_htmldir;
678 $htmlroot = $opt_htmlroot if defined $opt_htmlroot;
679 $doindex = $opt_index if defined $opt_index;
680 $podfile = $opt_infile if defined $opt_infile;
681 $htmlfile = $opt_outfile if defined $opt_outfile;
682 $podroot = $opt_podroot if defined $opt_podroot;
683 $quiet = $opt_quiet if defined $opt_quiet;
684 $recurse = $opt_recurse if defined $opt_recurse;
685 $title = $opt_title if defined $opt_title;
686 $verbose = $opt_verbose if defined $opt_verbose;
688 warn "Flushing item and directory caches\n"
689 if $opt_verbose && defined $opt_flush;
690 $dircache = "$cachedir/pod2htmd.tmp";
691 $itemcache = "$cachedir/pod2htmi.tmp";
692 if (defined $opt_flush) {
693 1 while unlink($dircache, $itemcache);
701 my($dircache, $itemcache, $podpath, $podroot, $recurse) = @_;
702 my @cache_key_args = @_;
704 # A first-level cache:
705 # Don't bother reading the cache files if they still apply
706 # and haven't changed since we last read them.
708 my $this_cache_key = cache_key(@cache_key_args);
710 return if $saved_cache_key and $this_cache_key eq $saved_cache_key;
712 # load the cache of %pages and %items if possible. $tests will be
713 # non-zero if successful.
715 if (-f $dircache && -f $itemcache) {
716 warn "scanning for item cache\n" if $verbose;
717 $tests = load_cache($dircache, $itemcache, $podpath, $podroot);
720 # if we didn't succeed in loading the cache then we must (re)build
723 warn "scanning directories in pod-path\n" if $verbose;
724 scan_podpath($podroot, $recurse, 0);
726 $saved_cache_key = cache_key(@cache_key_args);
730 my($dircache, $itemcache, $podpath, $podroot, $recurse) = @_;
731 return join('!', $dircache, $itemcache, $recurse,
732 @$podpath, $podroot, stat($dircache), stat($itemcache));
736 # load_cache - tries to find if the caches stored in $dircache and $itemcache
737 # are valid caches of %pages and %items. if they are valid then it loads
738 # them and returns a non-zero value.
741 my($dircache, $itemcache, $podpath, $podroot) = @_;
747 open(CACHE, "<$itemcache") ||
748 die "$0: error opening $itemcache for reading: $!\n";
751 # is it the same podpath?
754 $tests++ if (join(":", @$podpath) eq $_);
756 # is it the same podroot?
759 $tests++ if ($podroot eq $_);
761 # load the cache if its good
767 warn "loading item cache\n" if $verbose;
774 warn "scanning for directory cache\n" if $verbose;
775 open(CACHE, "<$dircache") ||
776 die "$0: error opening $dircache for reading: $!\n";
780 # is it the same podpath?
783 $tests++ if (join(":", @$podpath) eq $_);
785 # is it the same podroot?
788 $tests++ if ($podroot eq $_);
790 # load the cache if its good
796 warn "loading directory cache\n" if $verbose;
808 # scan_podpath - scans the directories specified in @podpath for directories,
809 # .pod files, and .pm files. it also scans the pod files specified in
810 # @libpods for =item directives.
813 my($podroot, $recurse, $append) = @_;
815 my($libpod, $dirname, $pod, @files, @poddata);
822 # scan each directory listed in @podpath
825 || die "$0: error changing to directory $podroot: $!\n";
826 foreach $dir (@podpath) {
827 scan_dir($dir, $recurse);
830 # scan the pods listed in @libpods for =item directives
831 foreach $libpod (@libpods) {
832 # if the page isn't defined then we won't know where to find it
834 next unless defined $pages{$libpod} && $pages{$libpod};
836 # if there is a directory then use the .pod and .pm files within it.
837 # NOTE: Only finds the first so-named directory in the tree.
838 # if ($pages{$libpod} =~ /([^:]*[^(\.pod|\.pm)]):/) {
839 if ($pages{$libpod} =~ /([^:]*(?<!\.pod)(?<!\.pm)):/) {
840 # find all the .pod and .pm files within the directory
842 opendir(DIR, $dirname) ||
843 die "$0: error opening directory $dirname: $!\n";
844 @files = grep(/(\.pod|\.pm)\z/ && ! -d $_, readdir(DIR));
847 # scan each .pod and .pm file for =item directives
848 foreach $pod (@files) {
849 open(POD, "<$dirname/$pod") ||
850 die "$0: error opening $dirname/$pod for input: $!\n";
853 clean_data( \@poddata );
855 scan_items( \%items, "$dirname/$pod", @poddata);
858 # use the names of files as =item directives too.
859 ### Don't think this should be done this way - confuses issues.(WL)
860 ### foreach $pod (@files) {
861 ### $pod =~ /^(.*)(\.pod|\.pm)$/;
862 ### $items{$1} = "$dirname/$1.html" if $1;
864 } elsif ($pages{$libpod} =~ /([^:]*\.pod):/ ||
865 $pages{$libpod} =~ /([^:]*\.pm):/) {
866 # scan the .pod or .pm file for =item directives
868 open(POD, "<$pod") ||
869 die "$0: error opening $pod for input: $!\n";
872 clean_data( \@poddata );
874 scan_items( \%items, "$pod", @poddata);
876 warn "$0: shouldn't be here (line ".__LINE__."\n";
879 @poddata = (); # clean-up a bit
882 || die "$0: error changing to directory $pwd: $!\n";
884 # cache the item list for later use
885 warn "caching items for later use\n" if $verbose;
886 open(CACHE, ">$itemcache") ||
887 die "$0: error open $itemcache for writing: $!\n";
889 print CACHE join(":", @podpath) . "\n$podroot\n";
890 foreach my $key (keys %items) {
891 print CACHE "$key $items{$key}\n";
896 # cache the directory list for later use
897 warn "caching directories for later use\n" if $verbose;
898 open(CACHE, ">$dircache") ||
899 die "$0: error open $dircache for writing: $!\n";
901 print CACHE join(":", @podpath) . "\n$podroot\n";
902 foreach my $key (keys %pages) {
903 print CACHE "$key $pages{$key}\n";
910 # scan_dir - scans the directory specified in $dir for subdirectories, .pod
911 # files, and .pm files. notes those that it finds. this information will
912 # be used later in order to figure out where the pages specified in L<>
913 # links are on the filesystem.
916 my($dir, $recurse) = @_;
917 my($t, @subdirs, @pods, $pod, $dirname, @dirs);
923 opendir(DIR, $dir) ||
924 die "$0: error opening directory $dir: $!\n";
925 while (defined($_ = readdir(DIR))) {
926 if (-d "$dir/$_" && $_ ne "." && $_ ne "..") { # directory
927 $pages{$_} = "" unless defined $pages{$_};
928 $pages{$_} .= "$dir/$_:";
930 } elsif (/\.pod\z/) { # .pod
932 $pages{$_} = "" unless defined $pages{$_};
933 $pages{$_} .= "$dir/$_.pod:";
934 push(@pods, "$dir/$_.pod");
935 } elsif (/\.html\z/) { # .html
937 $pages{$_} = "" unless defined $pages{$_};
938 $pages{$_} .= "$dir/$_.pod:";
939 } elsif (/\.pm\z/) { # .pm
941 $pages{$_} = "" unless defined $pages{$_};
942 $pages{$_} .= "$dir/$_.pm:";
943 push(@pods, "$dir/$_.pm");
948 # recurse on the subdirectories if necessary
950 foreach my $subdir (@subdirs) {
951 scan_dir("$dir/$subdir", $recurse);
957 # scan_headings - scan a pod file for head[1-6] tags, note the tags, and
961 my($sections, @data) = @_;
962 my($tag, $which_head, $otitle, $listdepth, $index);
964 # here we need local $ignore = 0;
965 # unfortunately, we can't have it, because $ignore is lexical
971 # scan for =head directives, note their name, and build an index
972 # pointing to each of them.
973 foreach my $line (@data) {
974 if ($line =~ /^=(head)([1-6])\s+(.*)/) {
975 ($tag, $which_head, $otitle) = ($1,$2,$3);
977 my $title = depod( $otitle );
978 my $name = anchorify( $title );
979 $$sections{$name} = 1;
980 $title = process_text( \$otitle );
982 while ($which_head != $listdepth) {
983 if ($which_head > $listdepth) {
984 $index .= "\n" . ("\t" x $listdepth) . "<ul>\n";
986 } elsif ($which_head < $listdepth) {
988 $index .= "\n" . ("\t" x $listdepth) . "</ul>\n";
992 $index .= "\n" . ("\t" x $listdepth) . "<li>" .
993 "<a href=\"#" . $name . "\">" .
994 $title . "</a></li>";
998 # finish off the lists
999 while ($listdepth--) {
1000 $index .= "\n" . ("\t" x $listdepth) . "</ul>\n";
1003 # get rid of bogus lists
1004 $index =~ s,\t*<ul>\s*</ul>\n,,g;
1006 $ignore = 1; # restore old value;
1012 # scan_items - scans the pod specified by $pod for =item directives. we
1013 # will use this information later on in resolving C<> links.
1016 my( $itemref, $pod, @poddata ) = @_;
1020 $pod =~ s/\.pod\z//;
1021 $pod .= ".html" if $pod;
1023 foreach $i (0..$#poddata) {
1024 my $txt = depod( $poddata[$i] );
1026 # figure out what kind of item it is.
1027 # Build string for referencing this item.
1028 if ( $txt =~ /\A=item\s+\*\s*(.*)\Z/s ) { # bullet
1031 } elsif( $txt =~ /\A=item\s+(?>\d+\.?)\s*(.*)\Z/s ) { # numbered list
1033 } elsif( $txt =~ /\A=item\s+(.*)\Z/s ) { # plain item
1038 my $fid = fragment_id( $item );
1039 $$itemref{$fid} = "$pod" if $fid;
1044 # process_head - convert a pod head[1-6] tag and convert it to HTML format.
1047 my($tag, $heading, $hasindex) = @_;
1049 # figure out the level of the =head
1050 $tag =~ /head([1-6])/;
1054 warn "$0: $podfile: unterminated list at =head in paragraph $paragraph. ignoring.\n";
1055 while( $listlevel ){
1061 if( $level == 1 && ! $top ){
1062 print HTML "<a href=\"#__index__\"><small>$backlink</small></a>\n"
1063 if $hasindex and $backlink;
1064 print HTML "</p>\n<hr />\n"
1066 print HTML "</p>\n";
1069 my $name = anchorify( depod( $heading ) );
1070 my $convert = process_text( \$heading );
1071 print HTML "<h$level><a name=\"$name\">$convert</a></h$level>\n";
1076 # emit_item_tag - print an =item's text
1077 # Note: The global $EmittedItem is used for inhibiting self-references.
1081 sub emit_item_tag($$$){
1082 my( $otext, $text, $compact ) = @_;
1083 my $item = fragment_id( $text );
1085 $EmittedItem = $item;
1086 ### print STDERR "emit_item_tag=$item ($text)\n";
1088 print HTML '<strong>';
1089 if ($items_named{$item}++) {
1090 print HTML process_text( \$otext );
1092 my $name = 'item_' . $item;
1093 $name = anchorify($name);
1094 print HTML qq{<a name="$name">}, process_text( \$otext ), '</a>';
1096 print HTML "</strong><br />\n";
1097 undef( $EmittedItem );
1102 if( $items_seen[$listlevel]++ == 0 ){
1103 push( @listend, "</$tag>" );
1104 print HTML "<$tag>\n";
1106 my $emitted = $tag eq 'dl' ? 'dt' : 'li';
1107 print HTML "<$emitted>";
1112 # process_item - convert a pod item tag and convert it to HTML format.
1116 my $need_dd = 0; # set to 1 if we need a <dd></dd> after an item
1118 # lots of documents start a list without doing an =over. this is
1119 # bad! but, the proper thing to do seems to be to just assume
1120 # they did do an =over. so warn them once and then continue.
1121 if( $listlevel == 0 ){
1122 warn "$0: $podfile: unexpected =item directive in paragraph $paragraph. ignoring.\n";
1126 # formatting: insert a paragraph if preceding item has >1 paragraph
1128 print HTML "<p></p>\n";
1132 # remove formatting instructions from the text
1133 my $text = depod( $otext );
1135 my $emitted; # the tag actually emitted, used for closing
1137 # all the list variants:
1138 if( $text =~ /\A\*/ ){ # bullet
1139 $emitted = emit_li( 'ul' );
1140 if ($text =~ /\A\*\s+(.+)\Z/s ) { # with additional text
1142 $otext =~ s/\A\*\s+//;
1143 emit_item_tag( $otext, $tag, 1 );
1146 } elsif( $text =~ /\A\d+/ ){ # numbered list
1147 $emitted = emit_li( 'ol' );
1148 if ($text =~ /\A(?>\d+\.?)\s*(.+)\Z/s ) { # with additional text
1150 $otext =~ s/\A\d+\.?\s*//;
1151 emit_item_tag( $otext, $tag, 1 );
1154 } else { # definition list
1155 $emitted = emit_li( 'dl' );
1156 if ($text =~ /\A(.+)\Z/s ){ # should have text
1157 emit_item_tag( $otext, $text, 1 );
1161 print HTML "</$emitted>" if $emitted;
1167 # process_over - process a pod over tag and start a corresponding HTML list.
1172 push( @items_seen, 0 );
1177 # process_back - process a pod back tag and convert it to HTML format.
1180 if( $listlevel == 0 ){
1181 warn "$0: $podfile: unexpected =back directive in paragraph $paragraph. ignoring.\n";
1185 # close off the list. note, I check to see if $listend[$listlevel] is
1186 # defined because an =item directive may have never appeared and thus
1187 # $listend[$listlevel] may have never been initialized.
1189 if( defined $listend[$listlevel] ){
1190 print HTML '<p></p>' if $after_lpar;
1191 print HTML $listend[$listlevel];
1197 # clean up item count
1202 # process_cut - process a pod cut tag, thus start ignoring pod directives.
1209 # process_pod - process a pod tag, thus stop ignoring pod directives
1210 # until we see a corresponding cut.
1213 # no need to set $ignore to 0 cause the main loop did it
1217 # process_for - process a =for pod tag. if it's for html, spit
1218 # it out verbatim, if illustration, center it, otherwise ignore it.
1221 my($whom, $text) = @_;
1222 if ( $whom =~ /^(pod2)?html$/i) {
1224 } elsif ($whom =~ /^illustration$/i) {
1225 1 while chomp $text;
1226 for my $ext (qw[.png .gif .jpeg .jpg .tga .pcl .bmp]) {
1227 $text .= $ext, last if -r "$text$ext";
1229 print HTML qq{<p align="center"><img src="$text" alt="$text illustration" /></p>};
1234 # process_begin - process a =begin pod tag. this pushes
1235 # whom we're beginning on the begin stack. if there's a
1236 # begin stack, we only print if it us.
1239 my($whom, $text) = @_;
1241 push (@begin_stack, $whom);
1242 if ( $whom =~ /^(pod2)?html$/) {
1243 print HTML $text if $text;
1248 # process_end - process a =end pod tag. pop the
1249 # begin stack. die if we're mismatched.
1252 my($whom, $text) = @_;
1254 if ($begin_stack[-1] ne $whom ) {
1255 die "Unmatched begin/end at chunk $paragraph\n"
1257 pop( @begin_stack );
1261 # process_pre - indented paragraph, made into <pre></pre>
1270 # insert spaces in place of tabs
1273 1 while $line =~ s/(\t+)/' ' x ((length($1) * 8) - $-[0] % 8)/e;
1277 # convert some special chars to HTML escapes
1278 $rest = html_escape($rest);
1280 # try and create links for all occurrences of perl.* within
1281 # the preformatted text.
1285 if ( defined $pages{$2} ){ # is a link
1286 qq($1<a href="$htmlroot/$pages{$2}">$2</a>);
1287 } elsif (defined $pages{dosify($2)}) { # is a link
1288 qq($1<a href="$htmlroot/$pages{dosify($2)}">$2</a>);
1294 (<a\ href="?) ([^>:]*:)? ([^>:]*) \.pod: ([^>:]*:)?
1297 if ( $htmlfileurl ne '' ){
1298 # Here, we take advantage of the knowledge
1299 # that $htmlfileurl ne '' implies $htmlroot eq ''.
1300 # Since $htmlroot eq '', we need to prepend $htmldir
1301 # on the fron of the link to get the absolute path
1302 # of the link's target. We check for a leading '/'
1303 # to avoid corrupting links that are #, file:, etc.
1305 $old_url = "$htmldir$old_url" if $old_url =~ m{^\/};
1306 $url = relativize_url( "$old_url.html", $htmlfileurl );
1313 # Look for embedded URLs and make them into links. We don't
1314 # relativize them since they are best left as the author intended.
1316 my $urls = '(' . join ('|', qw{
1329 my $gunk = '/#~:.?+=&%@!\-';
1330 my $punc = '.:!?\-;';
1331 my $any = "${ltrs}${gunk}${punc}";
1334 \b # start at word boundary
1336 $urls : # need resource and a colon
1337 (?!:) # Ignore File::, among others.
1338 [$any] +? # followed by one or more of any valid
1339 # character, but be conservative and
1340 # take only what you need to....
1343 " > # maybe pre-quoted '<a href="...">'
1345 [$punc]* # 0 or more punctuation
1347 [^$any] # by a non-url char
1349 $ # end of the string
1352 $ # then end of the string
1354 }{<a href="$1">$1</a>}igox;
1356 # text should be as it is (verbatim)
1362 # pure text processing
1364 # pure_text/inIS_text: differ with respect to automatic C<> recognition.
1365 # we don't want this to happen within IS
1369 process_puretext( $text, \$ptQuote, 1 );
1374 process_puretext( $text, \$ptQuote, 0 );
1378 # process_puretext - process pure text (without pod-escapes) converting
1379 # double-quotes and handling implicit C<> links.
1381 sub process_puretext {
1382 my($text, $quote, $notinIS) = @_;
1384 ## Guessing at func() or [$@%&]*var references in plain text is destined
1385 ## to produce some strange looking ref's. uncomment to disable:
1388 my(@words, $lead, $trail);
1390 # convert double-quotes to single-quotes
1391 if( $$quote && $text =~ s/"/''/s ){
1394 while ($text =~ s/"([^"]*)"/``$1''/sg) {};
1395 $$quote = 1 if $text =~ s/"/``/s;
1397 # keep track of leading and trailing white-space
1398 $lead = ($text =~ s/\A(\s+)//s ? $1 : "");
1399 $trail = ($text =~ s/(\s+)\Z//s ? $1 : "");
1401 # split at space/non-space boundaries
1402 @words = split( /(?<=\s)(?=\S)|(?<=\S)(?=\s)/, $text );
1404 # process each word individually
1405 foreach my $word (@words) {
1407 next if $word =~ /^\s*$/;
1408 # see if we can infer a link
1409 if( $notinIS && $word =~ /^(\w+)\((.*)\)$/ ) {
1410 # has parenthesis so should have been a C<> ref
1411 ## try for a pagename (perlXXX(1))?
1412 my( $func, $args ) = ( $1, $2 );
1413 if( $args =~ /^\d+$/ ){
1414 my $url = page_sect( $word, '' );
1416 $word = "<a href=\"$url\">the $word manpage</a>";
1420 ## try function name for a link, append tt'ed argument list
1421 $word = emit_C( $func, '', "($args)");
1423 #### disabled. either all (including $\W, $\w+{.*} etc.) or nothing.
1424 ## } elsif( $notinIS && $word =~ /^[\$\@%&*]+\w+$/) {
1425 ## # perl variables, should be a C<> ref
1426 ## $word = emit_C( $word );
1428 } elsif ($word =~ m,^\w+://\w,) {
1430 # Don't relativize it: leave it as the author intended
1431 $word = qq(<a href="$word">$word</a>);
1432 } elsif ($word =~ /[\w.-]+\@[\w-]+\.\w/) {
1433 # looks like an e-mail address
1434 my ($w1, $w2, $w3) = ("", $word, "");
1435 ($w1, $w2, $w3) = ("(", $1, ")$2") if $word =~ /^\((.*?)\)(,?)/;
1436 ($w1, $w2, $w3) = ("<", $1, ">$2") if $word =~ /^<(.*?)>(,?)/;
1437 $word = qq($w1<a href="mailto:$w2">$w2</a>$w3);
1439 $word = html_escape($word) if $word =~ /["&<>]/;
1443 # put everything back together
1444 return $lead . join( '', @words ) . $trail;
1449 # process_text - handles plaintext that appears in the input pod file.
1450 # there may be pod commands embedded within the text so those must be
1451 # converted to html commands.
1454 sub process_text1($$;$$);
1455 sub pattern ($) { $_[0] ? '[^\S\n]+'.('>' x ($_[0] + 1)) : '>' }
1456 sub closing ($) { local($_) = shift; (defined && s/\s+$//) ? length : 0 }
1461 my $res = process_text1( 0, $tref );
1465 sub process_text1($$;$$){
1466 my( $lev, $rstr, $func, $closing ) = @_;
1469 unless (defined $func) {
1475 # B<text> - boldface
1476 $res = '<strong>' . process_text1( $lev, $rstr ) . '</strong>';
1478 } elsif( $func eq 'C' ){
1479 # C<code> - can be a ref or <code></code>
1480 # need to extract text
1481 my $par = go_ahead( $rstr, 'C', $closing );
1483 ## clean-up of the link target
1484 my $text = depod( $par );
1486 ### my $x = $par =~ /[BI]</ ? 'yes' : 'no' ;
1487 ### print STDERR "-->call emit_C($par) lev=$lev, par with BI=$x\n";
1489 $res = emit_C( $text, $lev > 1 || ($par =~ /[BI]</) );
1491 } elsif( $func eq 'E' ){
1492 # E<x> - convert to character
1493 $$rstr =~ s/^([^>]*)>//;
1495 $escape =~ s/^(\d+|X[\dA-F]+)$/#$1/i;
1498 } elsif( $func eq 'F' ){
1499 # F<filename> - italizice
1500 $res = '<em>' . process_text1( $lev, $rstr ) . '</em>';
1502 } elsif( $func eq 'I' ){
1503 # I<text> - italizice
1504 $res = '<em>' . process_text1( $lev, $rstr ) . '</em>';
1506 } elsif( $func eq 'L' ){
1508 ## L<text|cross-ref> => produce text, use cross-ref for linking
1509 ## L<cross-ref> => make text from cross-ref
1510 ## need to extract text
1511 my $par = go_ahead( $rstr, 'L', $closing );
1513 # some L<>'s that shouldn't be:
1514 # a) full-blown URL's are emitted as-is
1515 if( $par =~ m{^\w+://}s ){
1516 return make_URL_href( $par );
1518 # b) C<...> is stripped and treated as C<>
1519 if( $par =~ /^C<(.*)>$/ ){
1520 my $text = depod( $1 );
1521 return emit_C( $text, $lev > 1 || ($par =~ /[BI]</) );
1524 # analyze the contents
1525 $par =~ s/\n/ /g; # undo word-wrapped tags
1528 if( $par =~ s{^([^|]+)\|}{} ){
1532 # make sure sections start with a /
1535 my( $page, $section, $ident );
1537 # check for link patterns
1538 if( $par =~ m{^([^/]+?)/(?!")(.*?)$} ){ # name/ident
1539 # we've got a name/ident (no quotes)
1540 ( $page, $ident ) = ( $1, $2 );
1541 ### print STDERR "--> L<$par> to page $page, ident $ident\n";
1543 } elsif( $par =~ m{^(.*?)/"?(.*?)"?$} ){ # [name]/"section"
1544 # even though this should be a "section", we go for ident first
1545 ( $page, $ident ) = ( $1, $2 );
1546 ### print STDERR "--> L<$par> to page $page, section $section\n";
1548 } elsif( $par =~ /\s/ ){ # this must be a section with missing quotes
1549 ( $page, $section ) = ( '', $par );
1550 ### print STDERR "--> L<$par> to void page, section $section\n";
1553 ( $page, $section ) = ( $par, '' );
1554 ### print STDERR "--> L<$par> to page $par, void section\n";
1557 # now, either $section or $ident is defined. the convoluted logic
1558 # below tries to resolve L<> according to what the user specified.
1559 # failing this, we try to find the next best thing...
1560 my( $url, $ltext, $fid );
1563 if( defined $ident ){
1564 ## try to resolve $ident as an item
1565 ( $url, $fid ) = coderef( $page, $ident );
1567 if( ! defined( $linktext ) ){
1569 $linktext .= " in " if $ident && $page;
1570 $linktext .= "the $page manpage" if $page;
1572 ### print STDERR "got coderef url=$url\n";
1575 ## no luck: go for a section (auto-quoting!)
1578 ## now go for a section
1579 my $htmlsection = htmlify( $section );
1580 $url = page_sect( $page, $htmlsection );
1582 if( ! defined( $linktext ) ){
1583 $linktext = $section;
1584 $linktext .= " in " if $section && $page;
1585 $linktext .= "the $page manpage" if $page;
1587 ### print STDERR "got page/section url=$url\n";
1590 ## no luck: go for an ident
1597 ( $url, $fid ) = coderef( $page, $ident );
1599 if( ! defined( $linktext ) ){
1601 $linktext .= " in " if $ident && $page;
1602 $linktext .= "the $page manpage" if $page;
1604 ### print STDERR "got section=>coderef url=$url\n";
1608 # warning; show some text.
1609 $linktext = $opar unless defined $linktext;
1610 warn "$0: $podfile: cannot resolve L<$opar> in paragraph $paragraph.\n";
1613 # now we have a URL or just plain code
1614 $$rstr = $linktext . '>' . $$rstr;
1615 if( defined( $url ) ){
1616 $res = "<a href=\"$url\">" . process_text1( $lev, $rstr ) . '</a>';
1618 $res = '<em>' . process_text1( $lev, $rstr ) . '</em>';
1621 } elsif( $func eq 'S' ){
1622 # S<text> - non-breaking spaces
1623 $res = process_text1( $lev, $rstr );
1624 $res =~ s/ / /g;
1626 } elsif( $func eq 'X' ){
1628 $$rstr =~ s/^[^>]*>//;
1630 } elsif( $func eq 'Z' ){
1632 warn "$0: $podfile: invalid X<> in paragraph $paragraph.\n"
1633 unless $$rstr =~ s/^>//;
1636 my $term = pattern $closing;
1637 while( $$rstr =~ s/\A(.*?)(([BCEFILSXZ])<(<+[^\S\n]+)?|$term)//s ){
1638 # all others: either recurse into new function or
1639 # terminate at closing angle bracket(s)
1641 $pt .= $2 if !$3 && $lev == 1;
1642 $res .= $lev == 1 ? pure_text( $pt ) : inIS_text( $pt );
1643 return $res if !$3 && $lev > 1;
1645 $res .= process_text1( $lev, $rstr, $3, closing $4 );
1649 $res .= pure_text( $$rstr );
1651 warn "$0: $podfile: undelimited $func<> in paragraph $paragraph.\n";
1658 # go_ahead: extract text of an IS (can be nested)
1661 my( $rstr, $func, $closing ) = @_;
1663 my @closing = ($closing);
1665 s/\A(.*?)(([BCEFILSXZ])<(<+[^\S\n]+)?|@{[pattern $closing[0]]})//s ){
1669 return $res unless @closing;
1671 unshift @closing, closing $4;
1675 warn "$0: $podfile: undelimited $func<> in paragraph $paragraph.\n";
1680 # emit_C - output result of C<text>
1681 # $text is the depod-ed text
1684 my( $text, $nocode, $args ) = @_;
1685 $args = '' unless defined $args;
1687 my( $url, $fid ) = coderef( undef(), $text );
1689 # need HTML-safe text
1690 my $linktext = html_escape( "$text$args" );
1692 if( defined( $url ) &&
1693 (!defined( $EmittedItem ) || $EmittedItem ne $fid ) ){
1694 $res = "<a href=\"$url\"><code>$linktext</code></a>";
1695 } elsif( 0 && $nocode ){
1698 $res = "<code>$linktext</code>";
1704 # html_escape: make text safe for HTML
1708 $rest =~ s/&/&/g;
1709 $rest =~ s/</</g;
1710 $rest =~ s/>/>/g;
1711 $rest =~ s/"/"/g;
1712 # ' is only in XHTML, not HTML4. Be conservative
1713 #$rest =~ s/'/'/g;
1719 # dosify - convert filenames to 8.3
1723 return lc($str) if $^O eq 'VMS'; # VMS just needs casing
1726 $str =~ s/(\.\w+)/substr ($1,0,4)/ge;
1727 $str =~ s/(\w+)/substr ($1,0,8)/ge;
1733 # page_sect - make a URL from the text of a L<>
1736 my( $page, $section ) = @_;
1737 my( $linktext, $page83, $link); # work strings
1739 # check if we know that this is a section in this page
1740 if (!defined $pages{$page} && defined $sections{$page}) {
1743 ### print STDERR "reset page='', section=$section\n";
1746 $page83=dosify($page);
1747 $page=$page83 if (defined $pages{$page83});
1749 $link = "#" . anchorify( $section );
1750 } elsif ( $page =~ /::/ ) {
1752 # Search page cache for an entry keyed under the html page name,
1753 # then look to see what directory that page might be in. NOTE:
1754 # this will only find one page. A better solution might be to produce
1755 # an intermediate page that is an index to all such pages.
1756 my $page_name = $page ;
1757 $page_name =~ s,^.*/,,s ;
1758 if ( defined( $pages{ $page_name } ) &&
1759 $pages{ $page_name } =~ /([^:]*$page)\.(?:pod|pm):/
1764 # NOTE: This branch assumes that all A::B pages are located in
1765 # $htmlroot/A/B.html . This is often incorrect, since they are
1766 # often in $htmlroot/lib/A/B.html or such like. Perhaps we could
1767 # analyze the contents of %pages and figure out where any
1768 # cousins of A::B are, then assume that. So, if A::B isn't found,
1769 # but A::C is found in lib/A/C.pm, then A::B is assumed to be in
1770 # lib/A/B.pm. This is also limited, but it's an improvement.
1771 # Maybe a hints file so that the links point to the correct places
1775 $link = "$htmlroot/$page.html";
1776 $link .= "#" . anchorify( $section ) if ($section);
1777 } elsif (!defined $pages{$page}) {
1780 $section = anchorify( $section ) if $section ne "";
1781 ### print STDERR "...section=$section\n";
1783 # if there is a directory by the name of the page, then assume that an
1784 # appropriate section will exist in the subdirectory
1785 # if ($section ne "" && $pages{$page} =~ /([^:]*[^(\.pod|\.pm)]):/) {
1786 if ($section ne "" && $pages{$page} =~ /([^:]*(?<!\.pod)(?<!\.pm)):/) {
1787 $link = "$htmlroot/$1/$section.html";
1788 ### print STDERR "...link=$link\n";
1790 # since there is no directory by the name of the page, the section will
1791 # have to exist within a .html of the same name. thus, make sure there
1792 # is a .pod or .pm that might become that .html
1794 $section = "#$section" if $section;
1795 ### print STDERR "...section=$section\n";
1797 # check if there is a .pod with the page name
1798 if ($pages{$page} =~ /([^:]*)\.pod:/) {
1799 $link = "$htmlroot/$1.html$section";
1800 } elsif ($pages{$page} =~ /([^:]*)\.pm:/) {
1801 $link = "$htmlroot/$1.html$section";
1809 # Here, we take advantage of the knowledge that $htmlfileurl ne ''
1810 # implies $htmlroot eq ''. This means that the link in question
1811 # needs a prefix of $htmldir if it begins with '/'. The test for
1812 # the initial '/' is done to avoid '#'-only links, and to allow
1813 # for other kinds of links, like file:, ftp:, etc.
1815 if ( $htmlfileurl ne '' ) {
1816 $link = "$htmldir$link" if $link =~ m{^/}s;
1817 $url = relativize_url( $link, $htmlfileurl );
1818 # print( " b: [$link,$htmlfileurl,$url]\n" );
1831 # relativize_url - convert an absolute URL to one relative to a base URL.
1832 # Assumes both end in a filename.
1834 sub relativize_url {
1835 my ($dest,$source) = @_ ;
1837 my ($dest_volume,$dest_directory,$dest_file) =
1838 File::Spec::Unix->splitpath( $dest ) ;
1839 $dest = File::Spec::Unix->catpath( $dest_volume, $dest_directory, '' ) ;
1841 my ($source_volume,$source_directory,$source_file) =
1842 File::Spec::Unix->splitpath( $source ) ;
1843 $source = File::Spec::Unix->catpath( $source_volume, $source_directory, '' ) ;
1846 if ( $dest ne '' ) {
1847 $rel_path = File::Spec::Unix->abs2rel( $dest, $source ) ;
1850 if ( $rel_path ne '' &&
1851 substr( $rel_path, -1 ) ne '/' &&
1852 substr( $dest_file, 0, 1 ) ne '#'
1854 $rel_path .= "/$dest_file" ;
1857 $rel_path .= "$dest_file" ;
1865 # coderef - make URL from the text of a C<>
1868 my( $page, $item ) = @_;
1871 my $fid = fragment_id( $item );
1872 if( defined( $page ) ){
1873 # we have been given a $page...
1876 # Do we take it? Item could be a section!
1877 my $base = $items{$fid} || "";
1878 $base =~ s{[^/]*/}{};
1879 if( $base ne "$page.html" ){
1880 ### print STDERR "coderef( $page, $item ): items{$fid} = $items{$fid} = $base => discard page!\n";
1885 # no page - local items precede cached items
1886 if( defined( $fid ) ){
1887 if( exists $local_items{$fid} ){
1888 $page = $local_items{$fid};
1890 $page = $items{$fid};
1895 # if there was a pod file that we found earlier with an appropriate
1896 # =item directive, then create a link to that page.
1897 if( defined $page ){
1899 if( exists $pages{$page} and $pages{$page} =~ /([^:.]*)\.[^:]*:/){
1900 $page = $1 . '.html';
1902 my $link = "$htmlroot/$page#item_" . anchorify($fid);
1904 # Here, we take advantage of the knowledge that $htmlfileurl
1905 # ne '' implies $htmlroot eq ''.
1906 if ( $htmlfileurl ne '' ) {
1907 $link = "$htmldir$link" ;
1908 $url = relativize_url( $link, $htmlfileurl ) ;
1913 $url = "#item_" . anchorify($fid);
1916 confess "url has space: $url" if $url =~ /"[^"]*\s[^"]*"/;
1918 return( $url, $fid );
1924 # Adapted from Nick Ing-Simmons' PodToHtml package.
1926 my $source_file = shift ;
1927 my $destination_file = shift;
1929 my $source = URI::file->new_abs($source_file);
1930 my $uo = URI::file->new($destination_file,$source)->abs;
1931 return $uo->rel->as_string;
1936 # finish_list - finish off any pending HTML lists. this should be called
1937 # after the entire pod file has been read and converted.
1940 while ($listlevel > 0) {
1941 print HTML "</dl>\n";
1947 # htmlify - converts a pod section specification to a suitable section
1948 # specification for HTML. Note that we keep spaces and special characters
1949 # except ", ? (Netscape problem) and the hyphen (writer's problem...).
1953 $heading =~ s/(\s+)/ /g;
1954 $heading =~ s/\s+\Z//;
1955 $heading =~ s/\A\s+//;
1956 # The hyphen is a disgrace to the English language.
1957 $heading =~ s/[-"?]//g;
1958 $heading = lc( $heading );
1963 # similar to htmlify, but turns non-alphanumerics into underscores
1967 $anchor = htmlify($anchor);
1968 $anchor =~ s/\W/_/g;
1973 # depod - convert text by eliminating all interior sequences
1974 # Note: can be called with copy or modify semantics
1981 $E2c{amp} = '&'; # in Tk's pods
1989 ${$_[0]} = depod1( \$string );
1997 my( $rstr, $func, $closing ) = @_;
1999 return $res unless defined $$rstr;
2000 if( ! defined( $func ) ){
2001 # skip to next begin of an interior sequence
2002 while( $$rstr =~ s/\A(.*?)([BCEFILSXZ])<(<+[^\S\n]+)?// ){
2003 # recurse into its text
2004 $res .= $1 . depod1( $rstr, $2, closing $3);
2007 } elsif( $func eq 'E' ){
2008 # E<x> - convert to character
2009 $$rstr =~ s/^([^>]*)>//;
2010 $res .= $E2c{$1} || "";
2011 } elsif( $func eq 'X' ){
2013 $$rstr =~ s/^[^>]*>//;
2014 } elsif( $func eq 'Z' ){
2018 # all others: either recurse into new function or
2019 # terminate at closing angle bracket
2020 my $term = pattern $closing;
2021 while( $$rstr =~ s/\A(.*?)(([BCEFILSXZ])<(<+[^\S\n]+)?|$term)// ){
2024 $res .= depod1( $rstr, $3, closing $4 );
2026 ## If we're here and $2 ne '>': undelimited interior sequence.
2027 ## Ignored, as this is called without proper indication of where we are.
2028 ## Rely on process_text to produce diagnostics.
2034 # fragment_id - construct a fragment identifier from:
2036 # b) contents of C<...>
2041 $text =~ s/\s+\Z//s;
2043 # a method or function?
2044 return $1 if $text =~ /(\w+)\s*\(/;
2045 return $1 if $text =~ /->\s*(\w+)\s*\(?/;
2048 return $1 if $text =~ /^([$@%*]\S+)/;
2050 # some pattern matching operator?
2051 return $1 if $text =~ m|^(\w+/).*/\w*$|;
2053 # fancy stuff... like "do { }"
2054 return $1 if $text =~ m|^(\w+)\s*{.*}$|;
2056 # honour the perlfunc manpage: func [PAR[,[ ]PAR]...]
2057 # and some funnies with ... Module ...
2058 return $1 if $text =~ m{^([a-z\d]+)(\s+[A-Z\d,/& ]+)?$};
2059 return $1 if $text =~ m{^([a-z\d]+)\s+Module(\s+[A-Z\d,/& ]+)?$};
2062 $text =~ s/\s+/_/sg;
2064 defined( $hc[ord($1)] ) ? $hc[ord($1)]
2065 : ( $hc[ord($1)] = sprintf( "%%%02X", ord($1) ) ) }gxe;
2066 $text = substr( $text, 0, 50 );
2073 # make_URL_href - generate HTML href from URL
2074 # Special treatment for CGI queries.
2076 sub make_URL_href($){
2079 s{^(http:[-\w/#~:.+=&%@!]+)(\?.*)$}{<a href="$1$2">$1</a>}i ){
2080 $url = "<a href=\"$url\">$url</a>";