5 use vars qw($VERSION @ISA @EXPORT);
8 @EXPORT = qw(pod2html htmlify);
16 use locale; # make \w work right in non-ASCII lands
20 Pod::Html - module to convert pod files to HTML
29 Converts files from pod format (see L<perlpod>) to HTML format. It
30 can automatically generate indexes and cross-references, and it keeps
31 a cache of things it knows how to cross-reference.
35 Pod::Html takes the following arguments:
41 --backlink="Back to Top"
43 Adds "Back to Top" links in front of every HEAD1 heading (except for
44 the first). By default, no backlink are being generated.
50 Creates the item and directory caches in the given directory.
56 Specify the URL of a cascading style sheet.
62 Flushes the item and directory caches.
69 Creates header and footer blocks containing the text of the NAME
70 section. By default, no headers are being generated.
76 Displays the usage message.
82 Sets the directory in which the resulting HTML file is placed. This
83 is used to generate relative links to other files. Not passing this
84 causes all links to be absolute, since this is the value that tells
85 Pod::Html the root of the documentation tree.
91 Sets the base URL for the HTML files. When cross-references are made,
92 the HTML root is prepended to the URL.
99 Generate an index at the top of the HTML file. This is the default
106 Specify the pod file to convert. Input is taken from STDIN if no
111 --libpods=name:...:name
113 List of page names (eg, "perlfunc") which contain linkable C<=item>s.
120 Use Netscape HTML directives when applicable. By default, they will
127 Specify the HTML file to create. Output goes to STDOUT if no outfile
132 --podpath=name:...:name
134 Specify which subdirectories of the podroot contain pod files whose
135 HTML converted forms can be linked-to in cross-references.
141 Specify the base directory for finding library pods.
148 Don't display I<mostly harmless> warning messages. These messages
149 will be displayed by default. But this is not the same as C<verbose>
157 Recurse into subdirectories specified in podpath (default behaviour).
163 Specify the title of the resulting HTML file.
170 Display progress messages. By default, they won't be displayed.
177 "--podpath=lib:ext:pod:vms",
178 "--podroot=/usr/src/perl",
179 "--htmlroot=/perl/nmanual",
180 "--libpods=perlfunc:perlguts:perlvar:perlrun:perlop",
183 "--outfile=/perl/nmanual/foo.html");
187 Uses $Config{pod2html} to setup default options.
191 Tom Christiansen, E<lt>tchrist@perl.comE<gt>.
199 This program is distributed under the Artistic License.
203 my $cachedir = "."; # The directory to which item and directory
204 # caches will be written.
205 my $cache_ext = $^O eq 'VMS' ? ".tmp" : ".x~~";
206 my $dircache = "pod2htmd$cache_ext";
207 my $itemcache = "pod2htmi$cache_ext";
209 my @begin_stack = (); # begin/end stack
211 my @libpods = (); # files to search for links from C<> directives
212 my $htmlroot = "/"; # http-server base directory from which all
213 # relative paths in $podpath stem.
214 my $htmldir = ""; # The directory to which the html pages
215 # will (eventually) be written.
216 my $htmlfile = ""; # write to stdout by default
217 my $htmlfileurl = "" ; # The url that other files would use to
218 # refer to this file. This is only used
219 # to make relative urls that point to
221 my $podfile = ""; # read from stdin by default
222 my @podpath = (); # list of directories containing library pods.
223 my $podroot = "."; # filesystem base directory from which all
224 # relative paths in $podpath stem.
225 my $css = ''; # Cascading style sheet
226 my $recurse = 1; # recurse on subdirectories in $podpath.
227 my $quiet = 0; # not quiet by default
228 my $verbose = 0; # not verbose by default
229 my $doindex = 1; # non-zero if we should generate an index
230 my $backlink = ''; # text for "back to top" links
231 my $listlevel = 0; # current list depth
232 my @listend = (); # the text to use to end the list.
233 my $after_lpar = 0; # set to true after a par in an =item
234 my $ignore = 1; # whether or not to format text. we don't
235 # format text until we hit our first pod
238 my %items_named = (); # for the multiples of the same item in perlfunc
240 my $netscape = 0; # whether or not to use netscape directives.
241 my $title; # title to give the pod(s)
242 my $header = 0; # produce block header/footer
243 my $top = 1; # true if we are at the top of the doc. used
244 # to prevent the first <HR> directive.
245 my $paragraph; # which paragraph we're processing (used
246 # for error messages)
247 my $ptQuote = 0; # status of double-quote conversion
248 my %pages = (); # associative array used to find the location
249 # of pages referenced by L<> links.
250 my %sections = (); # sections within this page
251 my %items = (); # associative array used to find the location
252 # of =item directives referenced by C<> links
253 my %local_items = (); # local items - avoid destruction of %items
254 my $Is83; # is dos with short filenames (8.3)
257 $dircache = "pod2htmd$cache_ext";
258 $itemcache = "pod2htmi$cache_ext";
260 @begin_stack = (); # begin/end stack
262 @libpods = (); # files to search for links from C<> directives
263 $htmlroot = "/"; # http-server base directory from which all
264 # relative paths in $podpath stem.
265 $htmldir = ""; # The directory to which the html pages
266 # will (eventually) be written.
267 $htmlfile = ""; # write to stdout by default
268 $podfile = ""; # read from stdin by default
269 @podpath = (); # list of directories containing library pods.
270 $podroot = "."; # filesystem base directory from which all
271 # relative paths in $podpath stem.
272 $css = ''; # Cascading style sheet
273 $recurse = 1; # recurse on subdirectories in $podpath.
274 $quiet = 0; # not quiet by default
275 $verbose = 0; # not verbose by default
276 $doindex = 1; # non-zero if we should generate an index
277 $backlink = ''; # text for "back to top" links
278 $listlevel = 0; # current list depth
279 @listend = (); # the text to use to end the list.
280 $after_lpar = 0; # set to true after a par in an =item
281 $ignore = 1; # whether or not to format text. we don't
282 # format text until we hit our first pod
287 $netscape = 0; # whether or not to use netscape directives.
288 $header = 0; # produce block header/footer
289 $title = ''; # title to give the pod(s)
290 $top = 1; # true if we are at the top of the doc. used
291 # to prevent the first <HR> directive.
292 $paragraph = ''; # which paragraph we're processing (used
293 # for error messages)
294 %sections = (); # sections within this page
296 # These are not reinitialised here but are kept as a cache.
297 # See get_cache and related cache management code.
298 #%pages = (); # associative array used to find the location
299 # of pages referenced by L<> links.
300 #%items = (); # associative array used to find the location
301 # of =item directives referenced by C<> links
307 # clean_data: global clean-up of pod data
312 for( $i = 0; $i <= $#$dataref; $i++ ){
313 ${$dataref}[$i] =~ s/\s+\Z//;
315 # have a look for all-space lines
316 if( ${$dataref}[$i] =~ /^\s+$/m and $dataref->[$i] !~ /^\s/ ){
317 my @chunks = split( /^\s+$/m, ${$dataref}[$i] );
318 splice( @$dataref, $i, 1, @chunks );
331 $Is83 = 0 if (defined (&Dos::UseLFN) && Dos::UseLFN());
333 # cache of %pages and %items from last time we ran pod2html
335 #undef $opt_help if defined $opt_help;
337 # parse the command-line parameters
338 parse_command_line();
340 # set some variables to their default values if necessary
342 unless (@ARGV && $ARGV[0]) {
343 $podfile = "-" unless $podfile; # stdin
344 open(POD, "<$podfile")
345 || die "$0: cannot open $podfile file for input: $!\n";
347 $podfile = $ARGV[0]; # XXX: might be more filenames
350 $htmlfile = "-" unless $htmlfile; # stdout
351 $htmlroot = "" if $htmlroot eq "/"; # so we don't get a //
352 $htmldir =~ s#/\z## ; # so we don't get a //
354 && defined( $htmldir )
356 && substr( $htmlfile, 0, length( $htmldir ) ) eq $htmldir
359 # Set the 'base' url for this file, so that we can use it
360 # as the location from which to calculate relative links
361 # to other files. If this is '', then absolute links will
362 # be used throughout.
363 $htmlfileurl= "$htmldir/" . substr( $htmlfile, length( $htmldir ) + 1);
366 # read the pod a paragraph at a time
367 warn "Scanning for sections in input file(s)\n" if $verbose;
371 clean_data( \@poddata );
373 # scan the pod for =head[1-6] directives and build an index
374 my $index = scan_headings(\%sections, @poddata);
377 warn "No headings in $podfile\n" if $verbose;
380 # open the output file
381 open(HTML, ">$htmlfile")
382 || die "$0: cannot open $htmlfile file for output: $!\n";
384 # put a title in the HTML file if one wasn't specified
387 for (my $i = 0; $i < @poddata; $i++) {
388 if ($poddata[$i] =~ /^=head1\s*NAME\b/m) {
389 for my $para ( @poddata[$i, $i+1] ) {
391 if ($title) = $para =~ /(\S+\s+-+.*\S)/s;
398 if (!$title and $podfile =~ /\.pod\z/) {
399 # probably a split pod so take first =head[12] as title
400 for (my $i = 0; $i < @poddata; $i++) {
401 last if ($title) = $poddata[$i] =~ /^=head[12]\s*(.*)/;
403 warn "adopted '$title' as title for $podfile\n"
404 if $verbose and $title;
407 $title =~ s/\s*\(.*\)//;
409 warn "$0: no title for $podfile" unless $quiet;
410 $podfile =~ /^(.*)(\.[^.\/]+)?\z/s;
411 $title = ($podfile eq "-" ? 'No Title' : $1);
412 warn "using $title" if $verbose;
414 my $csslink = $css ? qq(\n<LINK REL="stylesheet" HREF="$css" TYPE="text/css">) : '';
415 $csslink =~ s,\\,/,g;
416 $csslink =~ s,(/.):,$1|,;
418 my $block = $header ? <<END_OF_BLOCK : '';
419 <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
420 <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
421 <FONT SIZE=+1><STRONG><P CLASS=block> $title</P></STRONG></FONT>
426 print HTML <<END_OF_HEAD;
429 <TITLE>$title</TITLE>$csslink
436 # load/reload/validate/cache %pages and %items
437 get_cache($dircache, $itemcache, \@podpath, $podroot, $recurse);
439 # scan the pod for =item directives
440 scan_items( \%local_items, "", @poddata);
442 # put an index at the top of the file. note, if $doindex is 0 we
443 # still generate an index, but surround it with an html comment.
444 # that way some other program can extract it if desired.
446 print HTML "<A NAME=\"__index__\"></A>\n";
447 print HTML "<!-- INDEX BEGIN -->\n";
448 print HTML "<!--\n" unless $doindex;
450 print HTML "-->\n" unless $doindex;
451 print HTML "<!-- INDEX END -->\n\n";
452 print HTML "<HR>\n" if $doindex and $index;
454 # now convert this file
455 my $after_item; # set to true after an =item
456 warn "Converting input file $podfile\n" if $verbose;
457 foreach my $i (0..$#poddata){
458 $ptQuote = 0; # status of quote conversion
462 if (/^(=.*)/s) { # is it a pod directive?
466 if (/^=begin\s+(\S+)\s*(.*)/si) {# =begin
467 process_begin($1, $2);
468 } elsif (/^=end\s+(\S+)\s*(.*)/si) {# =end
470 } elsif (/^=cut/) { # =cut
472 } elsif (/^=pod/) { # =pod
475 next if @begin_stack && $begin_stack[-1] ne 'html';
477 if (/^=(head[1-6])\s+(.*\S)/s) { # =head[1-6] heading
478 process_head( $1, $2, $doindex && $index );
479 } elsif (/^=item\s*(.*\S)?/sm) { # =item text
480 warn "$0: $podfile: =item without bullet, number or text"
481 . " in paragraph $paragraph.\n" if !defined($1) or $1 eq '';
484 } elsif (/^=over\s*(.*)/) { # =over N
486 } elsif (/^=back/) { # =back
488 } elsif (/^=for\s+(\S+)\s*(.*)/si) {# =for
492 warn "$0: $podfile: unknown pod directive '$1' in "
493 . "paragraph $paragraph. ignoring.\n";
500 next if @begin_stack && $begin_stack[-1] ne 'html';
501 print HTML and next if @begin_stack && $begin_stack[-1] eq 'html';
503 if( $text =~ /\A\s+/ ){
504 process_pre( \$text );
505 print HTML "<PRE>\n$text</PRE>\n";
508 process_text( \$text );
510 # experimental: check for a paragraph where all lines
511 # have some ...\t...\t...\n pattern
513 my @lines = split( "\n", $text );
516 foreach my $line ( @lines ){
517 if( $line =~ /\S/ && $line !~ /\t/ ){
523 $text =~ s/\t+/<TD>/g;
524 $text =~ s/^/<TR><TD>/gm;
525 $text = '<TABLE CELLSPACING=0 CELLPADDING=0>' .
530 ## end of experimental
533 print HTML "$text\n";
536 print HTML "<P>$text</P>\n";
543 # finish off any pending directives
547 print HTML "<P><A HREF=\"#__index__\"><SMALL>$backlink</SMALL></A></P>\n"
548 if $doindex and $index and $backlink;
550 print HTML <<END_OF_TAIL;
557 # close the html file
560 warn "Finished\n" if $verbose;
563 ##############################################################################
565 my $usage; # see below
568 warn "$0: $podfile: @_\n" if @_;
572 $usage =<<END_OF_USAGE;
573 Usage: $0 --help --htmlroot=<name> --infile=<name> --outfile=<name>
574 --podpath=<name>:...:<name> --podroot=<name>
575 --libpods=<name>:...:<name> --recurse --verbose --index
576 --netscape --norecurse --noindex --cachedir=<name>
578 --backlink - set text for "back to top" links (default: none).
579 --cachedir - directory for the item and directory cache files.
580 --css - stylesheet URL
581 --flush - flushes the item and directory caches.
582 --[no]header - produce block header/footer (default is no headers).
583 --help - prints this message.
584 --htmldir - directory for resulting HTML files.
585 --htmlroot - http-server base directory from which all relative paths
586 in podpath stem (default is /).
587 --[no]index - generate an index at the top of the resulting html
589 --infile - filename for the pod to convert (input taken from stdin
591 --libpods - colon-separated list of pages to search for =item pod
592 directives in as targets of C<> and implicit links (empty
593 by default). note, these are not filenames, but rather
594 page names like those that appear in L<> links.
595 --[no]netscape - will use netscape html directives when applicable.
596 (default is not to use them).
597 --outfile - filename for the resulting html file (output sent to
599 --podpath - colon-separated list of directories containing library
600 pods (empty by default).
601 --podroot - filesystem base directory from which all relative paths
602 in podpath stem (default is .).
603 --[no]quiet - supress some benign warning messages (default is off).
604 --[no]recurse - recurse on those subdirectories listed in podpath
606 --title - title that will appear in resulting html file.
607 --[no]verbose - self-explanatory (off by default).
611 sub parse_command_line {
612 my ($opt_backlink,$opt_cachedir,$opt_css,$opt_flush,$opt_header,$opt_help,
613 $opt_htmldir,$opt_htmlroot,$opt_index,$opt_infile,$opt_libpods,
614 $opt_netscape,$opt_outfile,$opt_podpath,$opt_podroot,$opt_quiet,
615 $opt_recurse,$opt_title,$opt_verbose);
617 unshift @ARGV, split ' ', $Config{pod2html} if $Config{pod2html};
618 my $result = GetOptions(
619 'backlink=s' => \$opt_backlink,
620 'cachedir=s' => \$opt_cachedir,
621 'css=s' => \$opt_css,
622 'flush' => \$opt_flush,
623 'header!' => \$opt_header,
624 'help' => \$opt_help,
625 'htmldir=s' => \$opt_htmldir,
626 'htmlroot=s' => \$opt_htmlroot,
627 'index!' => \$opt_index,
628 'infile=s' => \$opt_infile,
629 'libpods=s' => \$opt_libpods,
630 'netscape!' => \$opt_netscape,
631 'outfile=s' => \$opt_outfile,
632 'podpath=s' => \$opt_podpath,
633 'podroot=s' => \$opt_podroot,
634 'quiet!' => \$opt_quiet,
635 'recurse!' => \$opt_recurse,
636 'title=s' => \$opt_title,
637 'verbose!' => \$opt_verbose,
639 usage("-", "invalid parameters") if not $result;
641 usage("-") if defined $opt_help; # see if the user asked for help
642 $opt_help = ""; # just to make -w shut-up.
644 @podpath = split(":", $opt_podpath) if defined $opt_podpath;
645 @libpods = split(":", $opt_libpods) if defined $opt_libpods;
647 $backlink = $opt_backlink if defined $opt_backlink;
648 $cachedir = $opt_cachedir if defined $opt_cachedir;
649 $css = $opt_css if defined $opt_css;
650 $header = $opt_header if defined $opt_header;
651 $htmldir = $opt_htmldir if defined $opt_htmldir;
652 $htmlroot = $opt_htmlroot if defined $opt_htmlroot;
653 $doindex = $opt_index if defined $opt_index;
654 $podfile = $opt_infile if defined $opt_infile;
655 $netscape = $opt_netscape if defined $opt_netscape;
656 $htmlfile = $opt_outfile if defined $opt_outfile;
657 $podroot = $opt_podroot if defined $opt_podroot;
658 $quiet = $opt_quiet if defined $opt_quiet;
659 $recurse = $opt_recurse if defined $opt_recurse;
660 $title = $opt_title if defined $opt_title;
661 $verbose = $opt_verbose if defined $opt_verbose;
663 warn "Flushing item and directory caches\n"
664 if $opt_verbose && defined $opt_flush;
665 $dircache = "$cachedir/pod2htmd$cache_ext";
666 $itemcache = "$cachedir/pod2htmi$cache_ext";
667 unlink($dircache, $itemcache) if defined $opt_flush;
674 my($dircache, $itemcache, $podpath, $podroot, $recurse) = @_;
675 my @cache_key_args = @_;
677 # A first-level cache:
678 # Don't bother reading the cache files if they still apply
679 # and haven't changed since we last read them.
681 my $this_cache_key = cache_key(@cache_key_args);
683 return if $saved_cache_key and $this_cache_key eq $saved_cache_key;
685 # load the cache of %pages and %items if possible. $tests will be
686 # non-zero if successful.
688 if (-f $dircache && -f $itemcache) {
689 warn "scanning for item cache\n" if $verbose;
690 $tests = load_cache($dircache, $itemcache, $podpath, $podroot);
693 # if we didn't succeed in loading the cache then we must (re)build
696 warn "scanning directories in pod-path\n" if $verbose;
697 scan_podpath($podroot, $recurse, 0);
699 $saved_cache_key = cache_key(@cache_key_args);
703 my($dircache, $itemcache, $podpath, $podroot, $recurse) = @_;
704 return join('!', $dircache, $itemcache, $recurse,
705 @$podpath, $podroot, stat($dircache), stat($itemcache));
709 # load_cache - tries to find if the caches stored in $dircache and $itemcache
710 # are valid caches of %pages and %items. if they are valid then it loads
711 # them and returns a non-zero value.
714 my($dircache, $itemcache, $podpath, $podroot) = @_;
720 open(CACHE, "<$itemcache") ||
721 die "$0: error opening $itemcache for reading: $!\n";
724 # is it the same podpath?
727 $tests++ if (join(":", @$podpath) eq $_);
729 # is it the same podroot?
732 $tests++ if ($podroot eq $_);
734 # load the cache if its good
740 warn "loading item cache\n" if $verbose;
747 warn "scanning for directory cache\n" if $verbose;
748 open(CACHE, "<$dircache") ||
749 die "$0: error opening $dircache for reading: $!\n";
753 # is it the same podpath?
756 $tests++ if (join(":", @$podpath) eq $_);
758 # is it the same podroot?
761 $tests++ if ($podroot eq $_);
763 # load the cache if its good
769 warn "loading directory cache\n" if $verbose;
781 # scan_podpath - scans the directories specified in @podpath for directories,
782 # .pod files, and .pm files. it also scans the pod files specified in
783 # @libpods for =item directives.
786 my($podroot, $recurse, $append) = @_;
788 my($libpod, $dirname, $pod, @files, @poddata);
795 # scan each directory listed in @podpath
798 || die "$0: error changing to directory $podroot: $!\n";
799 foreach $dir (@podpath) {
800 scan_dir($dir, $recurse);
803 # scan the pods listed in @libpods for =item directives
804 foreach $libpod (@libpods) {
805 # if the page isn't defined then we won't know where to find it
807 next unless defined $pages{$libpod} && $pages{$libpod};
809 # if there is a directory then use the .pod and .pm files within it.
810 # NOTE: Only finds the first so-named directory in the tree.
811 # if ($pages{$libpod} =~ /([^:]*[^(\.pod|\.pm)]):/) {
812 if ($pages{$libpod} =~ /([^:]*(?<!\.pod)(?<!\.pm)):/) {
813 # find all the .pod and .pm files within the directory
815 opendir(DIR, $dirname) ||
816 die "$0: error opening directory $dirname: $!\n";
817 @files = grep(/(\.pod|\.pm)\z/ && ! -d $_, readdir(DIR));
820 # scan each .pod and .pm file for =item directives
821 foreach $pod (@files) {
822 open(POD, "<$dirname/$pod") ||
823 die "$0: error opening $dirname/$pod for input: $!\n";
826 clean_data( \@poddata );
828 scan_items( \%items, "$dirname/$pod", @poddata);
831 # use the names of files as =item directives too.
832 ### Don't think this should be done this way - confuses issues.(WL)
833 ### foreach $pod (@files) {
834 ### $pod =~ /^(.*)(\.pod|\.pm)$/;
835 ### $items{$1} = "$dirname/$1.html" if $1;
837 } elsif ($pages{$libpod} =~ /([^:]*\.pod):/ ||
838 $pages{$libpod} =~ /([^:]*\.pm):/) {
839 # scan the .pod or .pm file for =item directives
841 open(POD, "<$pod") ||
842 die "$0: error opening $pod for input: $!\n";
845 clean_data( \@poddata );
847 scan_items( \%items, "$pod", @poddata);
849 warn "$0: shouldn't be here (line ".__LINE__."\n";
852 @poddata = (); # clean-up a bit
855 || die "$0: error changing to directory $pwd: $!\n";
857 # cache the item list for later use
858 warn "caching items for later use\n" if $verbose;
859 open(CACHE, ">$itemcache") ||
860 die "$0: error open $itemcache for writing: $!\n";
862 print CACHE join(":", @podpath) . "\n$podroot\n";
863 foreach my $key (keys %items) {
864 print CACHE "$key $items{$key}\n";
869 # cache the directory list for later use
870 warn "caching directories for later use\n" if $verbose;
871 open(CACHE, ">$dircache") ||
872 die "$0: error open $dircache for writing: $!\n";
874 print CACHE join(":", @podpath) . "\n$podroot\n";
875 foreach my $key (keys %pages) {
876 print CACHE "$key $pages{$key}\n";
883 # scan_dir - scans the directory specified in $dir for subdirectories, .pod
884 # files, and .pm files. notes those that it finds. this information will
885 # be used later in order to figure out where the pages specified in L<>
886 # links are on the filesystem.
889 my($dir, $recurse) = @_;
890 my($t, @subdirs, @pods, $pod, $dirname, @dirs);
896 opendir(DIR, $dir) ||
897 die "$0: error opening directory $dir: $!\n";
898 while (defined($_ = readdir(DIR))) {
899 if (-d "$dir/$_" && $_ ne "." && $_ ne "..") { # directory
900 $pages{$_} = "" unless defined $pages{$_};
901 $pages{$_} .= "$dir/$_:";
903 } elsif (/\.pod\z/) { # .pod
905 $pages{$_} = "" unless defined $pages{$_};
906 $pages{$_} .= "$dir/$_.pod:";
907 push(@pods, "$dir/$_.pod");
908 } elsif (/\.html\z/) { # .html
910 $pages{$_} = "" unless defined $pages{$_};
911 $pages{$_} .= "$dir/$_.pod:";
912 } elsif (/\.pm\z/) { # .pm
914 $pages{$_} = "" unless defined $pages{$_};
915 $pages{$_} .= "$dir/$_.pm:";
916 push(@pods, "$dir/$_.pm");
921 # recurse on the subdirectories if necessary
923 foreach my $subdir (@subdirs) {
924 scan_dir("$dir/$subdir", $recurse);
930 # scan_headings - scan a pod file for head[1-6] tags, note the tags, and
934 my($sections, @data) = @_;
935 my($tag, $which_head, $otitle, $listdepth, $index);
937 # here we need local $ignore = 0;
938 # unfortunately, we can't have it, because $ignore is lexical
944 # scan for =head directives, note their name, and build an index
945 # pointing to each of them.
946 foreach my $line (@data) {
947 if ($line =~ /^=(head)([1-6])\s+(.*)/) {
948 ($tag, $which_head, $otitle) = ($1,$2,$3);
950 my $title = depod( $otitle );
951 my $name = htmlify( $title );
952 $$sections{$name} = 1;
953 $title = process_text( \$otitle );
955 while ($which_head != $listdepth) {
956 if ($which_head > $listdepth) {
957 $index .= "\n" . ("\t" x $listdepth) . "<UL>\n";
959 } elsif ($which_head < $listdepth) {
961 $index .= "\n" . ("\t" x $listdepth) . "</UL>\n";
965 $index .= "\n" . ("\t" x $listdepth) . "<LI>" .
966 "<A HREF=\"#" . $name . "\">" .
967 $title . "</A></LI>";
971 # finish off the lists
972 while ($listdepth--) {
973 $index .= "\n" . ("\t" x $listdepth) . "</UL>\n";
976 # get rid of bogus lists
977 $index =~ s,\t*<UL>\s*</UL>\n,,g;
979 $ignore = 1; # restore old value;
985 # scan_items - scans the pod specified by $pod for =item directives. we
986 # will use this information later on in resolving C<> links.
989 my( $itemref, $pod, @poddata ) = @_;
994 $pod .= ".html" if $pod;
996 foreach $i (0..$#poddata) {
997 my $txt = depod( $poddata[$i] );
999 # figure out what kind of item it is.
1000 # Build string for referencing this item.
1001 if ( $txt =~ /\A=item\s+\*\s*(.*)\Z/s ) { # bullet
1004 } elsif( $txt =~ /\A=item\s+(?>\d+\.?)\s*(.*)\Z/s ) { # numbered list
1006 } elsif( $txt =~ /\A=item\s+(.*)\Z/s ) { # plain item
1011 my $fid = fragment_id( $item );
1012 $$itemref{$fid} = "$pod" if $fid;
1017 # process_head - convert a pod head[1-6] tag and convert it to HTML format.
1020 my($tag, $heading, $hasindex) = @_;
1022 # figure out the level of the =head
1023 $tag =~ /head([1-6])/;
1027 warn "$0: $podfile: unterminated list at =head in paragraph $paragraph. ignoring.\n";
1028 while( $listlevel ){
1034 if( $level == 1 && ! $top ){
1035 print HTML "<A HREF=\"#__index__\"><SMALL>$backlink</SMALL></A>\n"
1036 if $hasindex and $backlink;
1040 my $name = htmlify( depod( $heading ) );
1041 my $convert = process_text( \$heading );
1042 print HTML "<H$level><A NAME=\"$name\">$convert</A></H$level>\n";
1047 # emit_item_tag - print an =item's text
1048 # Note: The global $EmittedItem is used for inhibiting self-references.
1052 sub emit_item_tag($$$){
1053 my( $otext, $text, $compact ) = @_;
1054 my $item = fragment_id( $text );
1056 $EmittedItem = $item;
1057 ### print STDERR "emit_item_tag=$item ($text)\n";
1059 print HTML '<STRONG>';
1060 if ($items_named{$item}++) {
1061 print HTML process_text( \$otext );
1063 my $name = 'item_' . $item;
1064 print HTML qq{<A NAME="$name">}, process_text( \$otext ), '</A>';
1066 print HTML "</STRONG><BR>\n";
1067 undef( $EmittedItem );
1072 if( $items_seen[$listlevel]++ == 0 ){
1073 push( @listend, "</$tag>" );
1074 print HTML "<$tag>\n";
1076 print HTML $tag eq 'DL' ? '<DT>' : '<LI>';
1080 # process_item - convert a pod item tag and convert it to HTML format.
1085 # lots of documents start a list without doing an =over. this is
1086 # bad! but, the proper thing to do seems to be to just assume
1087 # they did do an =over. so warn them once and then continue.
1088 if( $listlevel == 0 ){
1089 warn "$0: $podfile: unexpected =item directive in paragraph $paragraph. ignoring.\n";
1093 # formatting: insert a paragraph if preceding item has >1 paragraph
1095 print HTML "<P></P>\n";
1099 # remove formatting instructions from the text
1100 my $text = depod( $otext );
1102 # all the list variants:
1103 if( $text =~ /\A\*/ ){ # bullet
1105 if ($text =~ /\A\*\s+(.+)\Z/s ) { # with additional text
1107 $otext =~ s/\A\*\s+//;
1108 emit_item_tag( $otext, $tag, 1 );
1111 } elsif( $text =~ /\A\d+/ ){ # numbered list
1113 if ($text =~ /\A(?>\d+\.?)\s*(.+)\Z/s ) { # with additional text
1115 $otext =~ s/\A\d+\.?\s*//;
1116 emit_item_tag( $otext, $tag, 1 );
1119 } else { # definition list
1121 if ($text =~ /\A(.+)\Z/s ){ # should have text
1122 emit_item_tag( $otext, $text, 1 );
1130 # process_over - process a pod over tag and start a corresponding HTML list.
1135 push( @items_seen, 0 );
1140 # process_back - process a pod back tag and convert it to HTML format.
1143 if( $listlevel == 0 ){
1144 warn "$0: $podfile: unexpected =back directive in paragraph $paragraph. ignoring.\n";
1148 # close off the list. note, I check to see if $listend[$listlevel] is
1149 # defined because an =item directive may have never appeared and thus
1150 # $listend[$listlevel] may have never been initialized.
1152 if( defined $listend[$listlevel] ){
1153 print HTML '<P></P>' if $after_lpar;
1154 print HTML $listend[$listlevel];
1160 # clean up item count
1165 # process_cut - process a pod cut tag, thus start ignoring pod directives.
1172 # process_pod - process a pod pod tag, thus stop ignoring pod directives
1173 # until we see a corresponding cut.
1176 # no need to set $ignore to 0 cause the main loop did it
1180 # process_for - process a =for pod tag. if it's for html, spit
1181 # it out verbatim, if illustration, center it, otherwise ignore it.
1184 my($whom, $text) = @_;
1185 if ( $whom =~ /^(pod2)?html$/i) {
1187 } elsif ($whom =~ /^illustration$/i) {
1188 1 while chomp $text;
1189 for my $ext (qw[.png .gif .jpeg .jpg .tga .pcl .bmp]) {
1190 $text .= $ext, last if -r "$text$ext";
1192 print HTML qq{<p align = "center"><img src = "$text" alt = "$text illustration"></p>};
1197 # process_begin - process a =begin pod tag. this pushes
1198 # whom we're beginning on the begin stack. if there's a
1199 # begin stack, we only print if it us.
1202 my($whom, $text) = @_;
1204 push (@begin_stack, $whom);
1205 if ( $whom =~ /^(pod2)?html$/) {
1206 print HTML $text if $text;
1211 # process_end - process a =end pod tag. pop the
1212 # begin stack. die if we're mismatched.
1215 my($whom, $text) = @_;
1217 if ($begin_stack[-1] ne $whom ) {
1218 die "Unmatched begin/end at chunk $paragraph\n"
1220 pop( @begin_stack );
1224 # process_pre - indented paragraph, made into <PRE></PRE>
1233 # insert spaces in place of tabs
1236 1 while $line =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e;
1240 # convert some special chars to HTML escapes
1241 $rest =~ s/&/&/g;
1242 $rest =~ s/</</g;
1243 $rest =~ s/>/>/g;
1244 $rest =~ s/"/"/g;
1246 # try and create links for all occurrences of perl.* within
1247 # the preformatted text.
1251 if ( defined $pages{$2} ){ # is a link
1252 qq($1<A HREF="$htmlroot/$pages{$2}">$2</A>);
1253 } elsif (defined $pages{dosify($2)}) { # is a link
1254 qq($1<A HREF="$htmlroot/$pages{dosify($2)}">$2</A>);
1260 (<A\ HREF="?) ([^>:]*:)? ([^>:]*) \.pod: ([^>:]*:)?
1263 if ( $htmlfileurl ne '' ){
1264 # Here, we take advantage of the knowledge
1265 # that $htmlfileurl ne '' implies $htmlroot eq ''.
1266 # Since $htmlroot eq '', we need to prepend $htmldir
1267 # on the fron of the link to get the absolute path
1268 # of the link's target. We check for a leading '/'
1269 # to avoid corrupting links that are #, file:, etc.
1271 $old_url = "$htmldir$old_url" if $old_url =~ m{^\/};
1272 $url = relativize_url( "$old_url.html", $htmlfileurl );
1279 # Look for embedded URLs and make them into links. We don't
1280 # relativize them since they are best left as the author intended.
1282 my $urls = '(' . join ('|', qw{
1295 my $gunk = '/#~:.?+=&%@!\-';
1297 my $any = "${ltrs}${gunk}${punc}";
1300 \b # start at word boundary
1302 $urls : # need resource and a colon
1303 (?!:) # Ignore File::, among others.
1304 [$any] +? # followed by on or more
1305 # of any valid character, but
1306 # be conservative and take only
1307 # what you need to....
1309 (?= # look-ahead non-consumptive assertion
1310 [$punc]* # either 0 or more puntuation
1311 [^$any] # followed by a non-url char
1313 $ # then end of the string
1315 }{<A HREF="$1">$1</A>}igox;
1317 # text should be as it is (verbatim)
1323 # pure text processing
1325 # pure_text/inIS_text: differ with respect to automatic C<> recognition.
1326 # we don't want this to happen within IS
1330 process_puretext( $text, \$ptQuote, 1 );
1335 process_puretext( $text, \$ptQuote, 0 );
1339 # process_puretext - process pure text (without pod-escapes) converting
1340 # double-quotes and handling implicit C<> links.
1342 sub process_puretext {
1343 my($text, $quote, $notinIS) = @_;
1345 ## Guessing at func() or [$@%&]*var references in plain text is destined
1346 ## to produce some strange looking ref's. uncomment to disable:
1349 my(@words, $lead, $trail);
1351 # convert double-quotes to single-quotes
1352 if( $$quote && $text =~ s/"/''/s ){
1355 while ($text =~ s/"([^"]*)"/``$1''/sg) {};
1356 $$quote = 1 if $text =~ s/"/``/s;
1358 # keep track of leading and trailing white-space
1359 $lead = ($text =~ s/\A(\s+)//s ? $1 : "");
1360 $trail = ($text =~ s/(\s+)\Z//s ? $1 : "");
1362 # split at space/non-space boundaries
1363 @words = split( /(?<=\s)(?=\S)|(?<=\S)(?=\s)/, $text );
1365 # process each word individually
1366 foreach my $word (@words) {
1368 next if $word =~ /^\s*$/;
1369 # see if we can infer a link
1370 if( $notinIS && $word =~ /^(\w+)\((.*)\)$/ ) {
1371 # has parenthesis so should have been a C<> ref
1372 ## try for a pagename (perlXXX(1))?
1373 my( $func, $args ) = ( $1, $2 );
1374 if( $args =~ /^\d+$/ ){
1375 my $url = page_sect( $word, '' );
1377 $word = "<A HREF=\"$url\">the $word manpage</A>";
1381 ## try function name for a link, append tt'ed argument list
1382 $word = emit_C( $func, '', "($args)");
1384 #### disabled. either all (including $\W, $\w+{.*} etc.) or nothing.
1385 ## } elsif( $notinIS && $word =~ /^[\$\@%&*]+\w+$/) {
1386 ## # perl variables, should be a C<> ref
1387 ## $word = emit_C( $word );
1389 } elsif ($word =~ m,^\w+://\w,) {
1391 # Don't relativize it: leave it as the author intended
1392 $word = qq(<A HREF="$word">$word</A>);
1393 } elsif ($word =~ /[\w.-]+\@[\w-]+\.\w/) {
1394 # looks like an e-mail address
1395 my ($w1, $w2, $w3) = ("", $word, "");
1396 ($w1, $w2, $w3) = ("(", $1, ")$2") if $word =~ /^\((.*?)\)(,?)/;
1397 ($w1, $w2, $w3) = ("<", $1, ">$2") if $word =~ /^<(.*?)>(,?)/;
1398 $word = qq($w1<A HREF="mailto:$w2">$w2</A>$w3);
1399 } elsif ($word !~ /[a-z]/ && $word =~ /[A-Z]/) { # all uppercase?
1400 $word = html_escape($word) if $word =~ /["&<>]/;
1401 $word = "\n<FONT SIZE=-1>$word</FONT>" if $netscape;
1403 $word = html_escape($word) if $word =~ /["&<>]/;
1407 # put everything back together
1408 return $lead . join( '', @words ) . $trail;
1413 # process_text - handles plaintext that appears in the input pod file.
1414 # there may be pod commands embedded within the text so those must be
1415 # converted to html commands.
1418 sub process_text1($$;$$);
1419 sub pattern ($) { $_[0] ? '[^\S\n]+'.('>' x ($_[0] + 1)) : '>' }
1420 sub closing ($) { local($_) = shift; (defined && s/\s+$//) ? length : 0 }
1425 my $res = process_text1( 0, $tref );
1429 sub process_text1($$;$$){
1430 my( $lev, $rstr, $func, $closing ) = @_;
1433 unless (defined $func) {
1439 # B<text> - boldface
1440 $res = '<STRONG>' . process_text1( $lev, $rstr ) . '</STRONG>';
1442 } elsif( $func eq 'C' ){
1443 # C<code> - can be a ref or <CODE></CODE>
1444 # need to extract text
1445 my $par = go_ahead( $rstr, 'C', $closing );
1447 ## clean-up of the link target
1448 my $text = depod( $par );
1450 ### my $x = $par =~ /[BI]</ ? 'yes' : 'no' ;
1451 ### print STDERR "-->call emit_C($par) lev=$lev, par with BI=$x\n";
1453 $res = emit_C( $text, $lev > 1 || ($par =~ /[BI]</) );
1455 } elsif( $func eq 'E' ){
1456 # E<x> - convert to character
1457 $$rstr =~ s/^([^>]*)>//;
1459 $escape =~ s/^(\d+|X[\dA-F]+)$/#$1/i;
1462 } elsif( $func eq 'F' ){
1463 # F<filename> - italizice
1464 $res = '<EM>' . process_text1( $lev, $rstr ) . '</EM>';
1466 } elsif( $func eq 'I' ){
1467 # I<text> - italizice
1468 $res = '<EM>' . process_text1( $lev, $rstr ) . '</EM>';
1470 } elsif( $func eq 'L' ){
1472 ## L<text|cross-ref> => produce text, use cross-ref for linking
1473 ## L<cross-ref> => make text from cross-ref
1474 ## need to extract text
1475 my $par = go_ahead( $rstr, 'L', $closing );
1477 # some L<>'s that shouldn't be:
1478 # a) full-blown URL's are emitted as-is
1479 if( $par =~ m{^\w+://}s ){
1480 return make_URL_href( $par );
1482 # b) C<...> is stripped and treated as C<>
1483 if( $par =~ /^C<(.*)>$/ ){
1484 my $text = depod( $1 );
1485 return emit_C( $text, $lev > 1 || ($par =~ /[BI]</) );
1488 # analyze the contents
1489 $par =~ s/\n/ /g; # undo word-wrapped tags
1492 if( $par =~ s{^([^|]+)\|}{} ){
1496 # make sure sections start with a /
1499 my( $page, $section, $ident );
1501 # check for link patterns
1502 if( $par =~ m{^([^/]+?)/(?!")(.*?)$} ){ # name/ident
1503 # we've got a name/ident (no quotes)
1504 ( $page, $ident ) = ( $1, $2 );
1505 ### print STDERR "--> L<$par> to page $page, ident $ident\n";
1507 } elsif( $par =~ m{^(.*?)/"?(.*?)"?$} ){ # [name]/"section"
1508 # even though this should be a "section", we go for ident first
1509 ( $page, $ident ) = ( $1, $2 );
1510 ### print STDERR "--> L<$par> to page $page, section $section\n";
1512 } elsif( $par =~ /\s/ ){ # this must be a section with missing quotes
1513 ( $page, $section ) = ( '', $par );
1514 ### print STDERR "--> L<$par> to void page, section $section\n";
1517 ( $page, $section ) = ( $par, '' );
1518 ### print STDERR "--> L<$par> to page $par, void section\n";
1521 # now, either $section or $ident is defined. the convoluted logic
1522 # below tries to resolve L<> according to what the user specified.
1523 # failing this, we try to find the next best thing...
1524 my( $url, $ltext, $fid );
1527 if( defined $ident ){
1528 ## try to resolve $ident as an item
1529 ( $url, $fid ) = coderef( $page, $ident );
1531 if( ! defined( $linktext ) ){
1533 $linktext .= " in " if $ident && $page;
1534 $linktext .= "the $page manpage" if $page;
1536 ### print STDERR "got coderef url=$url\n";
1539 ## no luck: go for a section (auto-quoting!)
1542 ## now go for a section
1543 my $htmlsection = htmlify( $section );
1544 $url = page_sect( $page, $htmlsection );
1546 if( ! defined( $linktext ) ){
1547 $linktext = $section;
1548 $linktext .= " in " if $section && $page;
1549 $linktext .= "the $page manpage" if $page;
1551 ### print STDERR "got page/section url=$url\n";
1554 ## no luck: go for an ident
1561 ( $url, $fid ) = coderef( $page, $ident );
1563 if( ! defined( $linktext ) ){
1565 $linktext .= " in " if $ident && $page;
1566 $linktext .= "the $page manpage" if $page;
1568 ### print STDERR "got section=>coderef url=$url\n";
1572 # warning; show some text.
1573 $linktext = $opar unless defined $linktext;
1574 warn "$0: $podfile: cannot resolve L<$opar> in paragraph $paragraph.";
1577 # now we have an URL or just plain code
1578 $$rstr = $linktext . '>' . $$rstr;
1579 if( defined( $url ) ){
1580 $res = "<A HREF=\"$url\">" . process_text1( $lev, $rstr ) . '</A>';
1582 $res = '<EM>' . process_text1( $lev, $rstr ) . '</EM>';
1585 } elsif( $func eq 'S' ){
1586 # S<text> - non-breaking spaces
1587 $res = process_text1( $lev, $rstr );
1588 $res =~ s/ / /g;
1590 } elsif( $func eq 'X' ){
1592 $$rstr =~ s/^[^>]*>//;
1594 } elsif( $func eq 'Z' ){
1596 warn "$0: $podfile: invalid X<> in paragraph $paragraph."
1597 unless $$rstr =~ s/^>//;
1600 my $term = pattern $closing;
1601 while( $$rstr =~ s/\A(.*?)(([BCEFILSXZ])<(<+[^\S\n]+)?|$term)//s ){
1602 # all others: either recurse into new function or
1603 # terminate at closing angle bracket(s)
1605 $pt .= $2 if !$3 && $lev == 1;
1606 $res .= $lev == 1 ? pure_text( $pt ) : inIS_text( $pt );
1607 return $res if !$3 && $lev > 1;
1609 $res .= process_text1( $lev, $rstr, $3, closing $4 );
1613 $res .= pure_text( $$rstr );
1615 warn "$0: $podfile: undelimited $func<> in paragraph $paragraph.";
1622 # go_ahead: extract text of an IS (can be nested)
1625 my( $rstr, $func, $closing ) = @_;
1627 my @closing = ($closing);
1629 s/\A(.*?)(([BCEFILSXZ])<(<+[^\S\n]+)?|@{[pattern $closing[0]]})//s ){
1633 return $res unless @closing;
1635 unshift @closing, closing $4;
1639 warn "$0: $podfile: undelimited $func<> in paragraph $paragraph.";
1644 # emit_C - output result of C<text>
1645 # $text is the depod-ed text
1648 my( $text, $nocode, $args ) = @_;
1649 $args = '' unless defined $args;
1651 my( $url, $fid ) = coderef( undef(), $text );
1653 # need HTML-safe text
1654 my $linktext = html_escape( "$text$args" );
1656 if( defined( $url ) &&
1657 (!defined( $EmittedItem ) || $EmittedItem ne $fid ) ){
1658 $res = "<A HREF=\"$url\"><CODE>$linktext</CODE></A>";
1659 } elsif( 0 && $nocode ){
1662 $res = "<CODE>$linktext</CODE>";
1668 # html_escape: make text safe for HTML
1672 $rest =~ s/&/&/g;
1673 $rest =~ s/</</g;
1674 $rest =~ s/>/>/g;
1675 $rest =~ s/"/"/g;
1681 # dosify - convert filenames to 8.3
1685 return lc($str) if $^O eq 'VMS'; # VMS just needs casing
1688 $str =~ s/(\.\w+)/substr ($1,0,4)/ge;
1689 $str =~ s/(\w+)/substr ($1,0,8)/ge;
1695 # page_sect - make an URL from the text of a L<>
1698 my( $page, $section ) = @_;
1699 my( $linktext, $page83, $link); # work strings
1701 # check if we know that this is a section in this page
1702 if (!defined $pages{$page} && defined $sections{$page}) {
1705 ### print STDERR "reset page='', section=$section\n";
1708 $page83=dosify($page);
1709 $page=$page83 if (defined $pages{$page83});
1711 $link = "#" . htmlify( $section );
1712 } elsif ( $page =~ /::/ ) {
1714 # Search page cache for an entry keyed under the html page name,
1715 # then look to see what directory that page might be in. NOTE:
1716 # this will only find one page. A better solution might be to produce
1717 # an intermediate page that is an index to all such pages.
1718 my $page_name = $page ;
1719 $page_name =~ s,^.*/,,s ;
1720 if ( defined( $pages{ $page_name } ) &&
1721 $pages{ $page_name } =~ /([^:]*$page)\.(?:pod|pm):/
1726 # NOTE: This branch assumes that all A::B pages are located in
1727 # $htmlroot/A/B.html . This is often incorrect, since they are
1728 # often in $htmlroot/lib/A/B.html or such like. Perhaps we could
1729 # analyze the contents of %pages and figure out where any
1730 # cousins of A::B are, then assume that. So, if A::B isn't found,
1731 # but A::C is found in lib/A/C.pm, then A::B is assumed to be in
1732 # lib/A/B.pm. This is also limited, but it's an improvement.
1733 # Maybe a hints file so that the links point to the correct places
1737 $link = "$htmlroot/$page.html";
1738 $link .= "#" . htmlify( $section ) if ($section);
1739 } elsif (!defined $pages{$page}) {
1742 $section = htmlify( $section ) if $section ne "";
1743 ### print STDERR "...section=$section\n";
1745 # if there is a directory by the name of the page, then assume that an
1746 # appropriate section will exist in the subdirectory
1747 # if ($section ne "" && $pages{$page} =~ /([^:]*[^(\.pod|\.pm)]):/) {
1748 if ($section ne "" && $pages{$page} =~ /([^:]*(?<!\.pod)(?<!\.pm)):/) {
1749 $link = "$htmlroot/$1/$section.html";
1750 ### print STDERR "...link=$link\n";
1752 # since there is no directory by the name of the page, the section will
1753 # have to exist within a .html of the same name. thus, make sure there
1754 # is a .pod or .pm that might become that .html
1756 $section = "#$section" if $section;
1757 ### print STDERR "...section=$section\n";
1759 # check if there is a .pod with the page name
1760 if ($pages{$page} =~ /([^:]*)\.pod:/) {
1761 $link = "$htmlroot/$1.html$section";
1762 } elsif ($pages{$page} =~ /([^:]*)\.pm:/) {
1763 $link = "$htmlroot/$1.html$section";
1771 # Here, we take advantage of the knowledge that $htmlfileurl ne ''
1772 # implies $htmlroot eq ''. This means that the link in question
1773 # needs a prefix of $htmldir if it begins with '/'. The test for
1774 # the initial '/' is done to avoid '#'-only links, and to allow
1775 # for other kinds of links, like file:, ftp:, etc.
1777 if ( $htmlfileurl ne '' ) {
1778 $link = "$htmldir$link" if $link =~ m{^/}s;
1779 $url = relativize_url( $link, $htmlfileurl );
1780 # print( " b: [$link,$htmlfileurl,$url]\n" );
1793 # relativize_url - convert an absolute URL to one relative to a base URL.
1794 # Assumes both end in a filename.
1796 sub relativize_url {
1797 my ($dest,$source) = @_ ;
1799 my ($dest_volume,$dest_directory,$dest_file) =
1800 File::Spec::Unix->splitpath( $dest ) ;
1801 $dest = File::Spec::Unix->catpath( $dest_volume, $dest_directory, '' ) ;
1803 my ($source_volume,$source_directory,$source_file) =
1804 File::Spec::Unix->splitpath( $source ) ;
1805 $source = File::Spec::Unix->catpath( $source_volume, $source_directory, '' ) ;
1808 if ( $dest ne '' ) {
1809 $rel_path = File::Spec::Unix->abs2rel( $dest, $source ) ;
1812 if ( $rel_path ne '' &&
1813 substr( $rel_path, -1 ) ne '/' &&
1814 substr( $dest_file, 0, 1 ) ne '#'
1816 $rel_path .= "/$dest_file" ;
1819 $rel_path .= "$dest_file" ;
1827 # coderef - make URL from the text of a C<>
1830 my( $page, $item ) = @_;
1833 my $fid = fragment_id( $item );
1834 if( defined( $page ) ){
1835 # we have been given a $page...
1838 # Do we take it? Item could be a section!
1839 my $base = $items{$fid} || "";
1840 $base =~ s{[^/]*/}{};
1841 if( $base ne "$page.html" ){
1842 ### print STDERR "coderef( $page, $item ): items{$fid} = $items{$fid} = $base => discard page!\n";
1847 # no page - local items precede cached items
1848 if( defined( $fid ) ){
1849 if( exists $local_items{$fid} ){
1850 $page = $local_items{$fid};
1852 $page = $items{$fid};
1857 # if there was a pod file that we found earlier with an appropriate
1858 # =item directive, then create a link to that page.
1859 if( defined $page ){
1861 if( exists $pages{$page} and $pages{$page} =~ /([^:.]*)\.[^:]*:/){
1862 $page = $1 . '.html';
1864 my $link = "$htmlroot/$page#item_$fid";
1866 # Here, we take advantage of the knowledge that $htmlfileurl
1867 # ne '' implies $htmlroot eq ''.
1868 if ( $htmlfileurl ne '' ) {
1869 $link = "$htmldir$link" ;
1870 $url = relativize_url( $link, $htmlfileurl ) ;
1875 $url = "#item_" . $fid;
1878 confess "url has space: $url" if $url =~ /"[^"]*\s[^"]*"/;
1880 return( $url, $fid );
1886 # Adapted from Nick Ing-Simmons' PodToHtml package.
1888 my $source_file = shift ;
1889 my $destination_file = shift;
1891 my $source = URI::file->new_abs($source_file);
1892 my $uo = URI::file->new($destination_file,$source)->abs;
1893 return $uo->rel->as_string;
1898 # finish_list - finish off any pending HTML lists. this should be called
1899 # after the entire pod file has been read and converted.
1902 while ($listlevel > 0) {
1903 print HTML "</DL>\n";
1909 # htmlify - converts a pod section specification to a suitable section
1910 # specification for HTML. Note that we keep spaces and special characters
1911 # except ", ? (Netscape problem) and the hyphen (writer's problem...).
1915 $heading =~ s/(\s+)/ /g;
1916 $heading =~ s/\s+\Z//;
1917 $heading =~ s/\A\s+//;
1918 # The hyphen is a disgrace to the English language.
1919 $heading =~ s/[-"?]//g;
1920 $heading = lc( $heading );
1925 # depod - convert text by eliminating all interior sequences
1926 # Note: can be called with copy or modify semantics
1933 $E2c{amp} = '&'; # in Tk's pods
1941 ${$_[0]} = depod1( \$string );
1949 my( $rstr, $func, $closing ) = @_;
1951 return $res unless defined $$rstr;
1952 if( ! defined( $func ) ){
1953 # skip to next begin of an interior sequence
1954 while( $$rstr =~ s/\A(.*?)([BCEFILSXZ])<(<+[^\S\n]+)?// ){
1955 # recurse into its text
1956 $res .= $1 . depod1( $rstr, $2, closing $3);
1959 } elsif( $func eq 'E' ){
1960 # E<x> - convert to character
1961 $$rstr =~ s/^([^>]*)>//;
1962 $res .= $E2c{$1} || "";
1963 } elsif( $func eq 'X' ){
1965 $$rstr =~ s/^[^>]*>//;
1966 } elsif( $func eq 'Z' ){
1970 # all others: either recurse into new function or
1971 # terminate at closing angle bracket
1972 my $term = pattern $closing;
1973 while( $$rstr =~ s/\A(.*?)(([BCEFILSXZ])<(<+[^\S\n]+)?|$term)// ){
1976 $res .= depod1( $rstr, $3, closing $4 );
1978 ## If we're here and $2 ne '>': undelimited interior sequence.
1979 ## Ignored, as this is called without proper indication of where we are.
1980 ## Rely on process_text to produce diagnostics.
1986 # fragment_id - construct a fragment identifier from:
1988 # b) contents of C<...>
1993 $text =~ s/\s+\Z//s;
1995 # a method or function?
1996 return $1 if $text =~ /(\w+)\s*\(/;
1997 return $1 if $text =~ /->\s*(\w+)\s*\(?/;
2000 return $1 if $text =~ /^([$@%*]\S+)/;
2002 # some pattern matching operator?
2003 return $1 if $text =~ m|^(\w+/).*/\w*$|;
2005 # fancy stuff... like "do { }"
2006 return $1 if $text =~ m|^(\w+)\s*{.*}$|;
2008 # honour the perlfunc manpage: func [PAR[,[ ]PAR]...]
2009 # and some funnies with ... Module ...
2010 return $1 if $text =~ m{^([a-z\d]+)(\s+[A-Z\d,/& ]+)?$};
2011 return $1 if $text =~ m{^([a-z\d]+)\s+Module(\s+[A-Z\d,/& ]+)?$};
2014 $text =~ s/\s+/_/sg;
2016 defined( $hc[ord($1)] ) ? $hc[ord($1)]
2017 : ( $hc[ord($1)] = sprintf( "%%%02X", ord($1) ) ) }gxe;
2018 $text = substr( $text, 0, 50 );
2025 # make_URL_href - generate HTML href from URL
2026 # Special treatment for CGI queries.
2028 sub make_URL_href($){
2031 s{^(http:[-\w/#~:.+=&%@!]+)(\?.*)$}{<A HREF="$1$2">$1</A>}i ){
2032 $url = "<A HREF=\"$url\">$url</A>";