4 use Getopt::Long; # package for handling command-line parameters
10 @EXPORT = qw(pod2html htmlify);
15 use locale; # make \w work right in non-ASCII lands
23 Pod::Html - module to convert pod files to HTML
32 Converts files from pod format (see L<perlpod>) to HTML format. It
33 can automatically generate indexes and cross-references, and it keeps
34 a cache of things it knows how to cross-reference.
38 Pod::Html takes the following arguments:
46 Displays the usage message.
52 Sets the directory in which the resulting HTML file is placed. This
53 is used to generate relative links to other files. Not passing this
54 causes all links to be absolute, since this is the value that tells
55 Pod::Html the root of the documentation tree.
61 Sets the base URL for the HTML files. When cross-references are made,
62 the HTML root is prepended to the URL.
68 Specify the pod file to convert. Input is taken from STDIN if no
75 Specify the HTML file to create. Output goes to STDOUT if no outfile
82 Specify the base directory for finding library pods.
86 --podpath=name:...:name
88 Specify which subdirectories of the podroot contain pod files whose
89 HTML converted forms can be linked-to in cross-references.
93 --libpods=name:...:name
95 List of page names (eg, "perlfunc") which contain linkable C<=item>s.
101 Use Netscape HTML directives when applicable.
107 Do not use Netscape HTML directives (default).
113 Generate an index at the top of the HTML file (default behaviour).
119 Do not generate an index at the top of the HTML file.
126 Recurse into subdirectories specified in podpath (default behaviour).
132 Do not recurse into subdirectories specified in podpath.
138 Specify the title of the resulting HTML file.
144 Specify the URL of a cascading style sheet.
150 Display progress messages.
156 Don't display I<mostly harmless> warning messages.
163 "--podpath=lib:ext:pod:vms",
164 "--podroot=/usr/src/perl",
165 "--htmlroot=/perl/nmanual",
166 "--libpods=perlfunc:perlguts:perlvar:perlrun:perlop",
169 "--outfile=/perl/nmanual/foo.html");
173 Uses $Config{pod2html} to setup default options.
177 Tom Christiansen, E<lt>tchrist@perl.comE<gt>.
185 This program is distributed under the Artistic License.
189 my $cache_ext = $^O eq 'VMS' ? ".tmp" : ".x~~";
190 my $dircache = "pod2htmd$cache_ext";
191 my $itemcache = "pod2htmi$cache_ext";
193 my @begin_stack = (); # begin/end stack
195 my @libpods = (); # files to search for links from C<> directives
196 my $htmlroot = "/"; # http-server base directory from which all
197 # relative paths in $podpath stem.
198 my $htmldir = ""; # The directory to which the html pages
199 # will (eventually) be written.
200 my $htmlfile = ""; # write to stdout by default
201 my $htmlfileurl = "" ; # The url that other files would use to
202 # refer to this file. This is only used
203 # to make relative urls that point to
205 my $podfile = ""; # read from stdin by default
206 my @podpath = (); # list of directories containing library pods.
207 my $podroot = "."; # filesystem base directory from which all
208 # relative paths in $podpath stem.
209 my $css = ''; # Cascading style sheet
210 my $recurse = 1; # recurse on subdirectories in $podpath.
211 my $quiet = 0; # not quiet by default
212 my $verbose = 0; # not verbose by default
213 my $doindex = 1; # non-zero if we should generate an index
214 my $listlevel = 0; # current list depth
215 my @listend = (); # the text to use to end the list.
216 my $after_lpar = 0; # set to true after a par in an =item
217 my $ignore = 1; # whether or not to format text. we don't
218 # format text until we hit our first pod
221 my %items_named = (); # for the multiples of the same item in perlfunc
223 my $netscape = 0; # whether or not to use netscape directives.
224 my $title; # title to give the pod(s)
225 my $header = 0; # produce block header/footer
226 my $top = 1; # true if we are at the top of the doc. used
227 # to prevent the first <HR> directive.
228 my $paragraph; # which paragraph we're processing (used
229 # for error messages)
230 my $ptQuote = 0; # status of double-quote conversion
231 my %pages = (); # associative array used to find the location
232 # of pages referenced by L<> links.
233 my %sections = (); # sections within this page
234 my %items = (); # associative array used to find the location
235 # of =item directives referenced by C<> links
236 my %local_items = (); # local items - avoid destruction of %items
237 my $Is83; # is dos with short filenames (8.3)
240 $dircache = "pod2htmd$cache_ext";
241 $itemcache = "pod2htmi$cache_ext";
243 @begin_stack = (); # begin/end stack
245 @libpods = (); # files to search for links from C<> directives
246 $htmlroot = "/"; # http-server base directory from which all
247 # relative paths in $podpath stem.
248 $htmldir = ""; # The directory to which the html pages
249 # will (eventually) be written.
250 $htmlfile = ""; # write to stdout by default
251 $podfile = ""; # read from stdin by default
252 @podpath = (); # list of directories containing library pods.
253 $podroot = "."; # filesystem base directory from which all
254 # relative paths in $podpath stem.
255 $css = ''; # Cascading style sheet
256 $recurse = 1; # recurse on subdirectories in $podpath.
257 $quiet = 0; # not quiet by default
258 $verbose = 0; # not verbose by default
259 $doindex = 1; # non-zero if we should generate an index
260 $listlevel = 0; # current list depth
261 @listend = (); # the text to use to end the list.
262 $after_lpar = 0; # set to true after a par in an =item
263 $ignore = 1; # whether or not to format text. we don't
264 # format text until we hit our first pod
269 $netscape = 0; # whether or not to use netscape directives.
270 $header = 0; # produce block header/footer
271 $title = ''; # title to give the pod(s)
272 $top = 1; # true if we are at the top of the doc. used
273 # to prevent the first <HR> directive.
274 $paragraph = ''; # which paragraph we're processing (used
275 # for error messages)
276 %sections = (); # sections within this page
278 # These are not reinitialised here but are kept as a cache.
279 # See get_cache and related cache management code.
280 #%pages = (); # associative array used to find the location
281 # of pages referenced by L<> links.
282 #%items = (); # associative array used to find the location
283 # of =item directives referenced by C<> links
289 # clean_data: global clean-up of pod data
294 for( $i = 0; $i <= $#$dataref; $i++ ){
295 ${$dataref}[$i] =~ s/\s+\Z//;
297 # have a look for all-space lines
298 if( ${$dataref}[$i] =~ /^\s+$/m ){
299 my @chunks = split( /^\s+$/m, ${$dataref}[$i] );
300 splice( @$dataref, $i, 1, @chunks );
313 $Is83 = 0 if (defined (&Dos::UseLFN) && Dos::UseLFN());
315 # cache of %pages and %items from last time we ran pod2html
317 #undef $opt_help if defined $opt_help;
319 # parse the command-line parameters
320 parse_command_line();
322 # set some variables to their default values if necessary
324 unless (@ARGV && $ARGV[0]) {
325 $podfile = "-" unless $podfile; # stdin
326 open(POD, "<$podfile")
327 || die "$0: cannot open $podfile file for input: $!\n";
329 $podfile = $ARGV[0]; # XXX: might be more filenames
332 $htmlfile = "-" unless $htmlfile; # stdout
333 $htmlroot = "" if $htmlroot eq "/"; # so we don't get a //
334 $htmldir =~ s#/$## ; # so we don't get a //
336 && defined( $htmldir )
338 && substr( $htmlfile, 0, length( $htmldir ) ) eq $htmldir
341 # Set the 'base' url for this file, so that we can use it
342 # as the location from which to calculate relative links
343 # to other files. If this is '', then absolute links will
344 # be used throughout.
345 $htmlfileurl= "$htmldir/" . substr( $htmlfile, length( $htmldir ) + 1);
348 # read the pod a paragraph at a time
349 warn "Scanning for sections in input file(s)\n" if $verbose;
353 clean_data( \@poddata );
355 # scan the pod for =head[1-6] directives and build an index
356 my $index = scan_headings(\%sections, @poddata);
359 warn "No headings in $podfile\n" if $verbose;
362 # open the output file
363 open(HTML, ">$htmlfile")
364 || die "$0: cannot open $htmlfile file for output: $!\n";
366 # put a title in the HTML file if one wasn't specified
369 for (my $i = 0; $i < @poddata; $i++) {
370 if ($poddata[$i] =~ /^=head1\s*NAME\b/m) {
371 for my $para ( @poddata[$i, $i+1] ) {
373 if ($title) = $para =~ /(\S+\s+-+.*\S)/s;
380 if (!$title and $podfile =~ /\.pod$/) {
381 # probably a split pod so take first =head[12] as title
382 for (my $i = 0; $i < @poddata; $i++) {
383 last if ($title) = $poddata[$i] =~ /^=head[12]\s*(.*)/;
385 warn "adopted '$title' as title for $podfile\n"
386 if $verbose and $title;
389 $title =~ s/\s*\(.*\)//;
391 warn "$0: no title for $podfile" unless $quiet;
392 $podfile =~ /^(.*)(\.[^.\/]+)?$/;
393 $title = ($podfile eq "-" ? 'No Title' : $1);
394 warn "using $title" if $verbose;
396 my $csslink = $css ? qq(\n<LINK REL="stylesheet" HREF="$css" TYPE="text/css">) : '';
397 $csslink =~ s,\\,/,g;
398 $csslink =~ s,(/.):,$1|,;
400 my $block = $header ? <<END_OF_BLOCK : '';
401 <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
402 <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
403 <FONT SIZE=+1><STRONG><P CLASS=block> $title</P></STRONG></FONT>
408 print HTML <<END_OF_HEAD;
411 <TITLE>$title</TITLE>$csslink
412 <LINK REV="made" HREF="mailto:$Config{perladmin}">
419 # load/reload/validate/cache %pages and %items
420 get_cache($dircache, $itemcache, \@podpath, $podroot, $recurse);
422 # scan the pod for =item directives
423 scan_items( \%local_items, "", @poddata);
425 # put an index at the top of the file. note, if $doindex is 0 we
426 # still generate an index, but surround it with an html comment.
427 # that way some other program can extract it if desired.
429 print HTML "<A NAME=\"__index__\"></A>\n";
430 print HTML "<!-- INDEX BEGIN -->\n";
431 print HTML "<!--\n" unless $doindex;
433 print HTML "-->\n" unless $doindex;
434 print HTML "<!-- INDEX END -->\n\n";
435 print HTML "<HR>\n" if $doindex and $index;
437 # now convert this file
438 my $after_item; # set to true after an =item
439 warn "Converting input file $podfile\n" if $verbose;
440 foreach my $i (0..$#poddata){
441 $ptQuote = 0; # status of quote conversion
445 if (/^(=.*)/s) { # is it a pod directive?
449 if (/^=begin\s+(\S+)\s*(.*)/si) {# =begin
450 process_begin($1, $2);
451 } elsif (/^=end\s+(\S+)\s*(.*)/si) {# =end
453 } elsif (/^=cut/) { # =cut
455 } elsif (/^=pod/) { # =pod
458 next if @begin_stack && $begin_stack[-1] ne 'html';
460 if (/^=(head[1-6])\s+(.*\S)/s) { # =head[1-6] heading
461 process_head( $1, $2, $doindex && $index );
462 } elsif (/^=item\s*(.*\S)?/sm) { # =item text
463 warn "$0: $podfile: =item without bullet, number or text"
464 . " in paragraph $paragraph.\n" if !defined($1) or $1 eq '';
467 } elsif (/^=over\s*(.*)/) { # =over N
469 } elsif (/^=back/) { # =back
471 } elsif (/^=for\s+(\S+)\s*(.*)/si) {# =for
475 warn "$0: $podfile: unknown pod directive '$1' in "
476 . "paragraph $paragraph. ignoring.\n";
483 next if @begin_stack && $begin_stack[-1] ne 'html';
485 if( $text =~ /\A\s+/ ){
486 process_pre( \$text );
487 print HTML "<PRE>\n$text</PRE>\n";
490 process_text( \$text );
492 # experimental: check for a paragraph where all lines
493 # have some ...\t...\t...\n pattern
495 my @lines = split( "\n", $text );
498 foreach my $line ( @lines ){
499 if( $line =~ /\S/ && $line !~ /\t/ ){
505 $text =~ s/\t+/<TD>/g;
506 $text =~ s/^/<TR><TD>/gm;
507 $text = '<TABLE CELLSPACING=0 CELLPADDING=0>' .
512 ## end of experimental
515 print HTML "$text\n";
518 print HTML "<P>$text</P>\n";
525 # finish off any pending directives
529 print HTML "<P><A HREF=\"#__index__\"><SMALL>page index</SMALL></A></P>\n"
530 if $doindex and $index;
532 print HTML <<END_OF_TAIL;
539 # close the html file
542 warn "Finished\n" if $verbose;
545 ##############################################################################
547 my $usage; # see below
550 warn "$0: $podfile: @_\n" if @_;
554 $usage =<<END_OF_USAGE;
555 Usage: $0 --help --htmlroot=<name> --infile=<name> --outfile=<name>
556 --podpath=<name>:...:<name> --podroot=<name>
557 --libpods=<name>:...:<name> --recurse --verbose --index
558 --netscape --norecurse --noindex
560 --flush - flushes the item and directory caches.
561 --help - prints this message.
562 --htmlroot - http-server base directory from which all relative paths
563 in podpath stem (default is /).
564 --index - generate an index at the top of the resulting html
566 --infile - filename for the pod to convert (input taken from stdin
568 --libpods - colon-separated list of pages to search for =item pod
569 directives in as targets of C<> and implicit links (empty
570 by default). note, these are not filenames, but rather
571 page names like those that appear in L<> links.
572 --netscape - will use netscape html directives when applicable.
573 --nonetscape - will not use netscape directives (default).
574 --outfile - filename for the resulting html file (output sent to
576 --podpath - colon-separated list of directories containing library
577 pods. empty by default.
578 --podroot - filesystem base directory from which all relative paths
579 in podpath stem (default is .).
580 --noindex - don't generate an index at the top of the resulting html.
581 --norecurse - don't recurse on those subdirectories listed in podpath.
582 --recurse - recurse on those subdirectories listed in podpath
584 --title - title that will appear in resulting html file.
585 --header - produce block header/footer
586 --css - stylesheet URL
587 --verbose - self-explanatory
588 --quiet - supress some benign warning messages
592 sub parse_command_line {
593 my ($opt_flush,$opt_help,$opt_htmldir,$opt_htmlroot,$opt_index,$opt_infile,$opt_libpods,$opt_netscape,$opt_outfile,$opt_podpath,$opt_podroot,$opt_recurse,$opt_title,$opt_verbose,$opt_css,$opt_header,$opt_quiet);
594 unshift @ARGV, split ' ', $Config{pod2html} if $Config{pod2html};
595 my $result = GetOptions(
596 'flush' => \$opt_flush,
597 'help' => \$opt_help,
598 'htmldir=s' => \$opt_htmldir,
599 'htmlroot=s' => \$opt_htmlroot,
600 'index!' => \$opt_index,
601 'infile=s' => \$opt_infile,
602 'libpods=s' => \$opt_libpods,
603 'netscape!' => \$opt_netscape,
604 'outfile=s' => \$opt_outfile,
605 'podpath=s' => \$opt_podpath,
606 'podroot=s' => \$opt_podroot,
607 'recurse!' => \$opt_recurse,
608 'title=s' => \$opt_title,
609 'header' => \$opt_header,
610 'css=s' => \$opt_css,
611 'verbose' => \$opt_verbose,
612 'quiet' => \$opt_quiet,
614 usage("-", "invalid parameters") if not $result;
616 usage("-") if defined $opt_help; # see if the user asked for help
617 $opt_help = ""; # just to make -w shut-up.
619 $podfile = $opt_infile if defined $opt_infile;
620 $htmlfile = $opt_outfile if defined $opt_outfile;
621 $htmldir = $opt_htmldir if defined $opt_htmldir;
623 @podpath = split(":", $opt_podpath) if defined $opt_podpath;
624 @libpods = split(":", $opt_libpods) if defined $opt_libpods;
626 warn "Flushing item and directory caches\n"
627 if $opt_verbose && defined $opt_flush;
628 unlink($dircache, $itemcache) if defined $opt_flush;
630 $htmlroot = $opt_htmlroot if defined $opt_htmlroot;
631 $podroot = $opt_podroot if defined $opt_podroot;
633 $doindex = $opt_index if defined $opt_index;
634 $recurse = $opt_recurse if defined $opt_recurse;
635 $title = $opt_title if defined $opt_title;
636 $header = defined $opt_header ? 1 : 0;
637 $css = $opt_css if defined $opt_css;
638 $verbose = defined $opt_verbose ? 1 : 0;
639 $quiet = defined $opt_quiet ? 1 : 0;
640 $netscape = $opt_netscape if defined $opt_netscape;
647 my($dircache, $itemcache, $podpath, $podroot, $recurse) = @_;
648 my @cache_key_args = @_;
650 # A first-level cache:
651 # Don't bother reading the cache files if they still apply
652 # and haven't changed since we last read them.
654 my $this_cache_key = cache_key(@cache_key_args);
656 return if $saved_cache_key and $this_cache_key eq $saved_cache_key;
658 # load the cache of %pages and %items if possible. $tests will be
659 # non-zero if successful.
661 if (-f $dircache && -f $itemcache) {
662 warn "scanning for item cache\n" if $verbose;
663 $tests = load_cache($dircache, $itemcache, $podpath, $podroot);
666 # if we didn't succeed in loading the cache then we must (re)build
669 warn "scanning directories in pod-path\n" if $verbose;
670 scan_podpath($podroot, $recurse, 0);
672 $saved_cache_key = cache_key(@cache_key_args);
676 my($dircache, $itemcache, $podpath, $podroot, $recurse) = @_;
677 return join('!', $dircache, $itemcache, $recurse,
678 @$podpath, $podroot, stat($dircache), stat($itemcache));
682 # load_cache - tries to find if the caches stored in $dircache and $itemcache
683 # are valid caches of %pages and %items. if they are valid then it loads
684 # them and returns a non-zero value.
687 my($dircache, $itemcache, $podpath, $podroot) = @_;
693 open(CACHE, "<$itemcache") ||
694 die "$0: error opening $itemcache for reading: $!\n";
697 # is it the same podpath?
700 $tests++ if (join(":", @$podpath) eq $_);
702 # is it the same podroot?
705 $tests++ if ($podroot eq $_);
707 # load the cache if its good
713 warn "loading item cache\n" if $verbose;
720 warn "scanning for directory cache\n" if $verbose;
721 open(CACHE, "<$dircache") ||
722 die "$0: error opening $dircache for reading: $!\n";
726 # is it the same podpath?
729 $tests++ if (join(":", @$podpath) eq $_);
731 # is it the same podroot?
734 $tests++ if ($podroot eq $_);
736 # load the cache if its good
742 warn "loading directory cache\n" if $verbose;
754 # scan_podpath - scans the directories specified in @podpath for directories,
755 # .pod files, and .pm files. it also scans the pod files specified in
756 # @libpods for =item directives.
759 my($podroot, $recurse, $append) = @_;
761 my($libpod, $dirname, $pod, @files, @poddata);
768 # scan each directory listed in @podpath
771 || die "$0: error changing to directory $podroot: $!\n";
772 foreach $dir (@podpath) {
773 scan_dir($dir, $recurse);
776 # scan the pods listed in @libpods for =item directives
777 foreach $libpod (@libpods) {
778 # if the page isn't defined then we won't know where to find it
780 next unless defined $pages{$libpod} && $pages{$libpod};
782 # if there is a directory then use the .pod and .pm files within it.
783 # NOTE: Only finds the first so-named directory in the tree.
784 # if ($pages{$libpod} =~ /([^:]*[^(\.pod|\.pm)]):/) {
785 if ($pages{$libpod} =~ /([^:]*(?<!\.pod)(?<!\.pm)):/) {
786 # find all the .pod and .pm files within the directory
788 opendir(DIR, $dirname) ||
789 die "$0: error opening directory $dirname: $!\n";
790 @files = grep(/(\.pod|\.pm)$/ && ! -d $_, readdir(DIR));
793 # scan each .pod and .pm file for =item directives
794 foreach $pod (@files) {
795 open(POD, "<$dirname/$pod") ||
796 die "$0: error opening $dirname/$pod for input: $!\n";
799 clean_data( \@poddata );
801 scan_items( \%items, "$dirname/$pod", @poddata);
804 # use the names of files as =item directives too.
805 ### Don't think this should be done this way - confuses issues.(WL)
806 ### foreach $pod (@files) {
807 ### $pod =~ /^(.*)(\.pod|\.pm)$/;
808 ### $items{$1} = "$dirname/$1.html" if $1;
810 } elsif ($pages{$libpod} =~ /([^:]*\.pod):/ ||
811 $pages{$libpod} =~ /([^:]*\.pm):/) {
812 # scan the .pod or .pm file for =item directives
814 open(POD, "<$pod") ||
815 die "$0: error opening $pod for input: $!\n";
818 clean_data( \@poddata );
820 scan_items( \%items, "$pod", @poddata);
822 warn "$0: shouldn't be here (line ".__LINE__."\n";
825 @poddata = (); # clean-up a bit
828 || die "$0: error changing to directory $pwd: $!\n";
830 # cache the item list for later use
831 warn "caching items for later use\n" if $verbose;
832 open(CACHE, ">$itemcache") ||
833 die "$0: error open $itemcache for writing: $!\n";
835 print CACHE join(":", @podpath) . "\n$podroot\n";
836 foreach my $key (keys %items) {
837 print CACHE "$key $items{$key}\n";
842 # cache the directory list for later use
843 warn "caching directories for later use\n" if $verbose;
844 open(CACHE, ">$dircache") ||
845 die "$0: error open $dircache for writing: $!\n";
847 print CACHE join(":", @podpath) . "\n$podroot\n";
848 foreach my $key (keys %pages) {
849 print CACHE "$key $pages{$key}\n";
856 # scan_dir - scans the directory specified in $dir for subdirectories, .pod
857 # files, and .pm files. notes those that it finds. this information will
858 # be used later in order to figure out where the pages specified in L<>
859 # links are on the filesystem.
862 my($dir, $recurse) = @_;
863 my($t, @subdirs, @pods, $pod, $dirname, @dirs);
869 opendir(DIR, $dir) ||
870 die "$0: error opening directory $dir: $!\n";
871 while (defined($_ = readdir(DIR))) {
872 if (-d "$dir/$_" && $_ ne "." && $_ ne "..") { # directory
873 $pages{$_} = "" unless defined $pages{$_};
874 $pages{$_} .= "$dir/$_:";
876 } elsif (/\.pod$/) { # .pod
878 $pages{$_} = "" unless defined $pages{$_};
879 $pages{$_} .= "$dir/$_.pod:";
880 push(@pods, "$dir/$_.pod");
881 } elsif (/\.pm$/) { # .pm
883 $pages{$_} = "" unless defined $pages{$_};
884 $pages{$_} .= "$dir/$_.pm:";
885 push(@pods, "$dir/$_.pm");
890 # recurse on the subdirectories if necessary
892 foreach my $subdir (@subdirs) {
893 scan_dir("$dir/$subdir", $recurse);
899 # scan_headings - scan a pod file for head[1-6] tags, note the tags, and
903 my($sections, @data) = @_;
904 my($tag, $which_head, $otitle, $listdepth, $index);
906 # here we need local $ignore = 0;
907 # unfortunately, we can't have it, because $ignore is lexical
913 # scan for =head directives, note their name, and build an index
914 # pointing to each of them.
915 foreach my $line (@data) {
916 if ($line =~ /^=(head)([1-6])\s+(.*)/) {
917 ($tag, $which_head, $otitle) = ($1,$2,$3);
919 my $title = depod( $otitle );
920 my $name = htmlify( $title );
921 $$sections{$name} = 1;
922 $title = process_text( \$otitle );
924 while ($which_head != $listdepth) {
925 if ($which_head > $listdepth) {
926 $index .= "\n" . ("\t" x $listdepth) . "<UL>\n";
928 } elsif ($which_head < $listdepth) {
930 $index .= "\n" . ("\t" x $listdepth) . "</UL>\n";
934 $index .= "\n" . ("\t" x $listdepth) . "<LI>" .
935 "<A HREF=\"#" . $name . "\">" .
936 $title . "</A></LI>";
940 # finish off the lists
941 while ($listdepth--) {
942 $index .= "\n" . ("\t" x $listdepth) . "</UL>\n";
945 # get rid of bogus lists
946 $index =~ s,\t*<UL>\s*</UL>\n,,g;
948 $ignore = 1; # restore old value;
954 # scan_items - scans the pod specified by $pod for =item directives. we
955 # will use this information later on in resolving C<> links.
958 my( $itemref, $pod, @poddata ) = @_;
963 $pod .= ".html" if $pod;
965 foreach $i (0..$#poddata) {
966 my $txt = depod( $poddata[$i] );
968 # figure out what kind of item it is.
969 # Build string for referencing this item.
970 if ( $txt =~ /\A=item\s+\*\s*(.*)\Z/s ) { # bullet
973 } elsif( $txt =~ /\A=item\s+(?>\d+\.?)\s*(.*)\Z/s ) { # numbered list
975 } elsif( $txt =~ /\A=item\s+(.*)\Z/s ) { # plain item
980 my $fid = fragment_id( $item );
981 $$itemref{$fid} = "$pod" if $fid;
986 # process_head - convert a pod head[1-6] tag and convert it to HTML format.
989 my($tag, $heading, $hasindex) = @_;
991 # figure out the level of the =head
992 $tag =~ /head([1-6])/;
996 warn "$0: $podfile: unterminated list at =head in paragraph $paragraph. ignoring.\n";
1003 if( $level == 1 && ! $top ){
1004 print HTML "<A HREF=\"#__index__\"><SMALL>page index</SMALL></A>\n"
1009 my $name = htmlify( depod( $heading ) );
1010 my $convert = process_text( \$heading );
1011 print HTML "<H$level><A NAME=\"$name\">$convert</A></H$level>\n";
1016 # emit_item_tag - print an =item's text
1017 # Note: The global $EmittedItem is used for inhibiting self-references.
1021 sub emit_item_tag($$$){
1022 my( $otext, $text, $compact ) = @_;
1023 my $item = fragment_id( $text );
1025 $EmittedItem = $item;
1026 ### print STDERR "emit_item_tag=$item ($text)\n";
1028 print HTML '<STRONG>';
1029 if ($items_named{$item}++) {
1030 print HTML process_text( \$otext );
1032 my $name = 'item_' . $item;
1033 print HTML qq{<A NAME="$name">}, process_text( \$otext ), '</A>';
1035 print HTML "</STRONG><BR>\n";
1036 undef( $EmittedItem );
1041 if( $items_seen[$listlevel]++ == 0 ){
1042 push( @listend, "</$tag>" );
1043 print HTML "<$tag>\n";
1045 print HTML $tag eq 'DL' ? '<DT>' : '<LI>';
1049 # process_item - convert a pod item tag and convert it to HTML format.
1054 # lots of documents start a list without doing an =over. this is
1055 # bad! but, the proper thing to do seems to be to just assume
1056 # they did do an =over. so warn them once and then continue.
1057 if( $listlevel == 0 ){
1058 warn "$0: $podfile: unexpected =item directive in paragraph $paragraph. ignoring.\n";
1062 # formatting: insert a paragraph if preceding item has >1 paragraph
1064 print HTML "<P></P>\n";
1068 # remove formatting instructions from the text
1069 my $text = depod( $otext );
1071 # all the list variants:
1072 if( $text =~ /\A\*/ ){ # bullet
1074 if ($text =~ /\A\*\s+(.+)\Z/s ) { # with additional text
1076 $otext =~ s/\A\*\s+//;
1077 emit_item_tag( $otext, $tag, 1 );
1080 } elsif( $text =~ /\A\d+/ ){ # numbered list
1082 if ($text =~ /\A(?>\d+\.?)\s*(.+)\Z/s ) { # with additional text
1084 $otext =~ s/\A\d+\.?\s*//;
1085 emit_item_tag( $otext, $tag, 1 );
1088 } else { # definition list
1090 if ($text =~ /\A(.+)\Z/s ){ # should have text
1091 emit_item_tag( $otext, $text, 1 );
1099 # process_over - process a pod over tag and start a corresponding HTML list.
1104 push( @items_seen, 0 );
1109 # process_back - process a pod back tag and convert it to HTML format.
1112 if( $listlevel == 0 ){
1113 warn "$0: $podfile: unexpected =back directive in paragraph $paragraph. ignoring.\n";
1117 # close off the list. note, I check to see if $listend[$listlevel] is
1118 # defined because an =item directive may have never appeared and thus
1119 # $listend[$listlevel] may have never been initialized.
1121 if( defined $listend[$listlevel] ){
1122 print HTML '<P></P>' if $after_lpar;
1123 print HTML $listend[$listlevel];
1129 # clean up item count
1134 # process_cut - process a pod cut tag, thus start ignoring pod directives.
1141 # process_pod - process a pod pod tag, thus stop ignoring pod directives
1142 # until we see a corresponding cut.
1145 # no need to set $ignore to 0 cause the main loop did it
1149 # process_for - process a =for pod tag. if it's for html, spit
1150 # it out verbatim, if illustration, center it, otherwise ignore it.
1153 my($whom, $text) = @_;
1154 if ( $whom =~ /^(pod2)?html$/i) {
1156 } elsif ($whom =~ /^illustration$/i) {
1157 1 while chomp $text;
1158 for my $ext (qw[.png .gif .jpeg .jpg .tga .pcl .bmp]) {
1159 $text .= $ext, last if -r "$text$ext";
1161 print HTML qq{<p align = "center"><img src = "$text" alt = "$text illustration"></p>};
1166 # process_begin - process a =begin pod tag. this pushes
1167 # whom we're beginning on the begin stack. if there's a
1168 # begin stack, we only print if it us.
1171 my($whom, $text) = @_;
1173 push (@begin_stack, $whom);
1174 if ( $whom =~ /^(pod2)?html$/) {
1175 print HTML $text if $text;
1180 # process_end - process a =end pod tag. pop the
1181 # begin stack. die if we're mismatched.
1184 my($whom, $text) = @_;
1186 if ($begin_stack[-1] ne $whom ) {
1187 die "Unmatched begin/end at chunk $paragraph\n"
1189 pop( @begin_stack );
1193 # process_pre - indented paragraph, made into <PRE></PRE>
1202 # insert spaces in place of tabs
1205 1 while $line =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e;
1209 # convert some special chars to HTML escapes
1210 $rest =~ s/&/&/g;
1211 $rest =~ s/</</g;
1212 $rest =~ s/>/>/g;
1213 $rest =~ s/"/"/g;
1215 # try and create links for all occurrences of perl.* within
1216 # the preformatted text.
1220 if ( defined $pages{$2} ){ # is a link
1221 qq($1<A HREF="$htmlroot/$pages{$2}">$2</A>);
1222 } elsif (defined $pages{dosify($2)}) { # is a link
1223 qq($1<A HREF="$htmlroot/$pages{dosify($2)}">$2</A>);
1229 (<A\ HREF="?) ([^>:]*:)? ([^>:]*) \.pod: ([^>:]*:)?
1232 if ( $htmlfileurl ne '' ){
1233 # Here, we take advantage of the knowledge
1234 # that $htmlfileurl ne '' implies $htmlroot eq ''.
1235 # Since $htmlroot eq '', we need to prepend $htmldir
1236 # on the fron of the link to get the absolute path
1237 # of the link's target. We check for a leading '/'
1238 # to avoid corrupting links that are #, file:, etc.
1240 $old_url = "$htmldir$old_url" if $old_url =~ m{^\/};
1241 $url = relativize_url( "$old_url.html", $htmlfileurl );
1248 # Look for embedded URLs and make them into links. We don't
1249 # relativize them since they are best left as the author intended.
1251 my $urls = '(' . join ('|', qw{
1264 my $gunk = '/#~:.?+=&%@!\-';
1266 my $any = "${ltrs}${gunk}${punc}";
1269 \b # start at word boundary
1271 $urls : # need resource and a colon
1272 (?!:) # Ignore File::, among others.
1273 [$any] +? # followed by on or more
1274 # of any valid character, but
1275 # be conservative and take only
1276 # what you need to....
1278 (?= # look-ahead non-consumptive assertion
1279 [$punc]* # either 0 or more puntuation
1280 [^$any] # followed by a non-url char
1282 $ # then end of the string
1284 }{<A HREF="$1">$1</A>}igox;
1286 # text should be as it is (verbatim)
1292 # pure text processing
1294 # pure_text/inIS_text: differ with respect to automatic C<> recognition.
1295 # we don't want this to happen within IS
1299 process_puretext( $text, \$ptQuote, 1 );
1304 process_puretext( $text, \$ptQuote, 0 );
1308 # process_puretext - process pure text (without pod-escapes) converting
1309 # double-quotes and handling implicit C<> links.
1311 sub process_puretext {
1312 my($text, $quote, $notinIS) = @_;
1314 ## Guessing at func() or [$@%&]*var references in plain text is destined
1315 ## to produce some strange looking ref's. uncomment to disable:
1318 my(@words, $lead, $trail);
1320 # convert double-quotes to single-quotes
1321 if( $$quote && $text =~ s/"/''/s ){
1324 while ($text =~ s/"([^"]*)"/``$1''/sg) {};
1325 $$quote = 1 if $text =~ s/"/``/s;
1327 # keep track of leading and trailing white-space
1328 $lead = ($text =~ s/\A(\s+)//s ? $1 : "");
1329 $trail = ($text =~ s/(\s+)\Z//s ? $1 : "");
1331 # split at space/non-space boundaries
1332 @words = split( /(?<=\s)(?=\S)|(?<=\S)(?=\s)/, $text );
1334 # process each word individually
1335 foreach my $word (@words) {
1337 next if $word =~ /^\s*$/;
1338 # see if we can infer a link
1339 if( $notinIS && $word =~ /^(\w+)\((.*)\)\W*$/ ) {
1340 # has parenthesis so should have been a C<> ref
1341 ## try for a pagename (perlXXX(1))?
1342 if( $2 =~ /^\d+$/ ){
1343 my $url = page_sect( $word, '' );
1345 $word = "<A HREF=\"$url\">the $word manpage</A>";
1349 $word = emit_C( $word );
1351 #### disabled. either all (including $\W, $\w+{.*} etc.) or nothing.
1352 ## } elsif( $notinIS && $word =~ /^[\$\@%&*]+\w+$/) {
1353 ## # perl variables, should be a C<> ref
1354 ## $word = emit_C( $word );
1356 } elsif ($word =~ m,^\w+://\w,) {
1358 # Don't relativize it: leave it as the author intended
1359 $word = qq(<A HREF="$word">$word</A>);
1360 } elsif ($word =~ /[\w.-]+\@[\w-]+\.\w/) {
1361 # looks like an e-mail address
1362 my ($w1, $w2, $w3) = ("", $word, "");
1363 ($w1, $w2, $w3) = ("(", $1, ")$2") if $word =~ /^\((.*?)\)(,?)/;
1364 ($w1, $w2, $w3) = ("<", $1, ">$2") if $word =~ /^<(.*?)>(,?)/;
1365 $word = qq($w1<A HREF="mailto:$w2">$w2</A>$w3);
1366 } elsif ($word !~ /[a-z]/ && $word =~ /[A-Z]/) { # all uppercase?
1367 $word = html_escape($word) if $word =~ /["&<>]/;
1368 $word = "\n<FONT SIZE=-1>$word</FONT>" if $netscape;
1370 $word = html_escape($word) if $word =~ /["&<>]/;
1374 # put everything back together
1375 return $lead . join( '', @words ) . $trail;
1380 # process_text - handles plaintext that appears in the input pod file.
1381 # there may be pod commands embedded within the text so those must be
1382 # converted to html commands.
1385 sub process_text1($$;$$);
1386 sub pattern ($) { $_[0] ? '[^\S\n]+'.('>' x ($_[0] + 1)) : '>' }
1387 sub closing ($) { local($_) = shift; (defined && s/\s+$//) ? length : 0 }
1392 my $res = process_text1( 0, $tref );
1396 sub process_text1($$;$$){
1397 my( $lev, $rstr, $func, $closing ) = @_;
1398 $lev++ unless defined $func;
1403 # B<text> - boldface
1404 $res = '<STRONG>' . process_text1( $lev, $rstr ) . '</STRONG>';
1406 } elsif( $func eq 'C' ){
1407 # C<code> - can be a ref or <CODE></CODE>
1408 # need to extract text
1409 my $par = go_ahead( $rstr, 'C', $closing );
1411 ## clean-up of the link target
1412 my $text = depod( $par );
1414 ### my $x = $par =~ /[BI]</ ? 'yes' : 'no' ;
1415 ### print STDERR "-->call emit_C($par) lev=$lev, par with BI=$x\n";
1417 $res = emit_C( $text, $lev > 1 || ($par =~ /[BI]</) );
1419 } elsif( $func eq 'E' ){
1420 # E<x> - convert to character
1421 $$rstr =~ s/^(\w+)>//;
1424 } elsif( $func eq 'F' ){
1425 # F<filename> - italizice
1426 $res = '<EM>' . process_text1( $lev, $rstr ) . '</EM>';
1428 } elsif( $func eq 'I' ){
1429 # I<text> - italizice
1430 $res = '<EM>' . process_text1( $lev, $rstr ) . '</EM>';
1432 } elsif( $func eq 'L' ){
1434 ## L<text|cross-ref> => produce text, use cross-ref for linking
1435 ## L<cross-ref> => make text from cross-ref
1436 ## need to extract text
1437 my $par = go_ahead( $rstr, 'L', $closing );
1439 # some L<>'s that shouldn't be:
1440 # a) full-blown URL's are emitted as-is
1441 if( $par =~ m{^\w+://}s ){
1442 return make_URL_href( $par );
1444 # b) C<...> is stripped and treated as C<>
1445 if( $par =~ /^C<(.*)>$/ ){
1446 my $text = depod( $1 );
1447 return emit_C( $text, $lev > 1 || ($par =~ /[BI]</) );
1450 # analyze the contents
1451 $par =~ s/\n/ /g; # undo word-wrapped tags
1454 if( $par =~ s{^([^|]+)\|}{} ){
1458 # make sure sections start with a /
1461 my( $page, $section, $ident );
1463 # check for link patterns
1464 if( $par =~ m{^([^/]+?)/(?!")(.*?)$} ){ # name/ident
1465 # we've got a name/ident (no quotes)
1466 ( $page, $ident ) = ( $1, $2 );
1467 ### print STDERR "--> L<$par> to page $page, ident $ident\n";
1469 } elsif( $par =~ m{^(.*?)/"?(.*?)"?$} ){ # [name]/"section"
1470 # even though this should be a "section", we go for ident first
1471 ( $page, $ident ) = ( $1, $2 );
1472 ### print STDERR "--> L<$par> to page $page, section $section\n";
1474 } elsif( $par =~ /\s/ ){ # this must be a section with missing quotes
1475 ( $page, $section ) = ( '', $par );
1476 ### print STDERR "--> L<$par> to void page, section $section\n";
1479 ( $page, $section ) = ( $par, '' );
1480 ### print STDERR "--> L<$par> to page $par, void section\n";
1483 # now, either $section or $ident is defined. the convoluted logic
1484 # below tries to resolve L<> according to what the user specified.
1485 # failing this, we try to find the next best thing...
1486 my( $url, $ltext, $fid );
1489 if( defined $ident ){
1490 ## try to resolve $ident as an item
1491 ( $url, $fid ) = coderef( $page, $ident );
1493 if( ! defined( $linktext ) ){
1495 $linktext .= " in " if $ident && $page;
1496 $linktext .= "the $page manpage" if $page;
1498 ### print STDERR "got coderef url=$url\n";
1501 ## no luck: go for a section (auto-quoting!)
1504 ## now go for a section
1505 my $htmlsection = htmlify( $section );
1506 $url = page_sect( $page, $htmlsection );
1508 if( ! defined( $linktext ) ){
1509 $linktext = $section;
1510 $linktext .= " in " if $section && $page;
1511 $linktext .= "the $page manpage" if $page;
1513 ### print STDERR "got page/section url=$url\n";
1516 ## no luck: go for an ident
1523 ( $url, $fid ) = coderef( $page, $ident );
1525 if( ! defined( $linktext ) ){
1527 $linktext .= " in " if $ident && $page;
1528 $linktext .= "the $page manpage" if $page;
1530 ### print STDERR "got section=>coderef url=$url\n";
1534 # warning; show some text.
1535 $linktext = $opar unless defined $linktext;
1536 warn "$0: $podfile: cannot resolve L<$opar> in paragraph $paragraph.";
1539 # now we have an URL or just plain code
1540 $$rstr = $linktext . '>' . $$rstr;
1541 if( defined( $url ) ){
1542 $res = "<A HREF=\"$url\">" . process_text1( $lev, $rstr ) . '</A>';
1544 $res = '<EM>' . process_text1( $lev, $rstr ) . '</EM>';
1547 } elsif( $func eq 'S' ){
1548 # S<text> - non-breaking spaces
1549 $res = process_text1( $lev, $rstr );
1550 $res =~ s/ / /g;
1552 } elsif( $func eq 'X' ){
1554 $$rstr =~ s/^[^>]*>//;
1556 } elsif( $func eq 'Z' ){
1558 warn "$0: $podfile: invalid X<> in paragraph $paragraph."
1559 unless $$rstr =~ s/^>//;
1562 my $term = pattern $closing;
1563 while( $$rstr =~ s/\A(.*?)(([BCEFILSXZ])<(<+[^\S\n]+)?|$term)//s ){
1564 # all others: either recurse into new function or
1565 # terminate at closing angle bracket(s)
1567 $pt .= $2 if !$3 && $lev == 1;
1568 $res .= $lev == 1 ? pure_text( $pt ) : inIS_text( $pt );
1569 return $res if !$3 && $lev > 1;
1571 $res .= process_text1( $lev, $rstr, $3, closing $4 );
1576 $res .= pure_text( $$rstr );
1578 warn "$0: $podfile: undelimited $func<> in paragraph $paragraph.";
1585 # go_ahead: extract text of an IS (can be nested)
1588 my( $rstr, $func, $closing ) = @_;
1590 my @closing = ($closing);
1592 s/\A(.*?)(([BCEFILSXZ])<(<+[^\S\n]+)?|@{[pattern $closing[0]]})//s ){
1596 return $res unless @closing;
1598 unshift @closing, closing $4;
1602 warn "$0: $podfile: undelimited $func<> in paragraph $paragraph.";
1607 # emit_C - output result of C<text>
1608 # $text is the depod-ed text
1611 my( $text, $nocode ) = @_;
1613 my( $url, $fid ) = coderef( undef(), $text );
1615 # need HTML-safe text
1616 my $linktext = html_escape( $text );
1618 if( defined( $url ) &&
1619 (!defined( $EmittedItem ) || $EmittedItem ne $fid ) ){
1620 $res = "<A HREF=\"$url\"><CODE>$linktext</CODE></A>";
1621 } elsif( 0 && $nocode ){
1624 $res = "<CODE>$linktext</CODE>";
1630 # html_escape: make text safe for HTML
1634 $rest =~ s/&/&/g;
1635 $rest =~ s/</</g;
1636 $rest =~ s/>/>/g;
1637 $rest =~ s/"/"/g;
1643 # dosify - convert filenames to 8.3
1647 return lc($str) if $^O eq 'VMS'; # VMS just needs casing
1650 $str =~ s/(\.\w+)/substr ($1,0,4)/ge;
1651 $str =~ s/(\w+)/substr ($1,0,8)/ge;
1657 # page_sect - make an URL from the text of a L<>
1660 my( $page, $section ) = @_;
1661 my( $linktext, $page83, $link); # work strings
1663 # check if we know that this is a section in this page
1664 if (!defined $pages{$page} && defined $sections{$page}) {
1667 ### print STDERR "reset page='', section=$section\n";
1670 $page83=dosify($page);
1671 $page=$page83 if (defined $pages{$page83});
1673 $link = "#" . htmlify( $section );
1674 } elsif ( $page =~ /::/ ) {
1676 # Search page cache for an entry keyed under the html page name,
1677 # then look to see what directory that page might be in. NOTE:
1678 # this will only find one page. A better solution might be to produce
1679 # an intermediate page that is an index to all such pages.
1680 my $page_name = $page ;
1681 $page_name =~ s,^.*/,, ;
1682 if ( defined( $pages{ $page_name } ) &&
1683 $pages{ $page_name } =~ /([^:]*$page)\.(?:pod|pm):/
1688 # NOTE: This branch assumes that all A::B pages are located in
1689 # $htmlroot/A/B.html . This is often incorrect, since they are
1690 # often in $htmlroot/lib/A/B.html or such like. Perhaps we could
1691 # analyze the contents of %pages and figure out where any
1692 # cousins of A::B are, then assume that. So, if A::B isn't found,
1693 # but A::C is found in lib/A/C.pm, then A::B is assumed to be in
1694 # lib/A/B.pm. This is also limited, but it's an improvement.
1695 # Maybe a hints file so that the links point to the correct places
1699 $link = "$htmlroot/$page.html";
1700 $link .= "#" . htmlify( $section ) if ($section);
1701 } elsif (!defined $pages{$page}) {
1704 $section = htmlify( $section ) if $section ne "";
1705 ### print STDERR "...section=$section\n";
1707 # if there is a directory by the name of the page, then assume that an
1708 # appropriate section will exist in the subdirectory
1709 # if ($section ne "" && $pages{$page} =~ /([^:]*[^(\.pod|\.pm)]):/) {
1710 if ($section ne "" && $pages{$page} =~ /([^:]*(?<!\.pod)(?<!\.pm)):/) {
1711 $link = "$htmlroot/$1/$section.html";
1712 ### print STDERR "...link=$link\n";
1714 # since there is no directory by the name of the page, the section will
1715 # have to exist within a .html of the same name. thus, make sure there
1716 # is a .pod or .pm that might become that .html
1718 $section = "#$section" if $section;
1719 ### print STDERR "...section=$section\n";
1721 # check if there is a .pod with the page name
1722 if ($pages{$page} =~ /([^:]*)\.pod:/) {
1723 $link = "$htmlroot/$1.html$section";
1724 } elsif ($pages{$page} =~ /([^:]*)\.pm:/) {
1725 $link = "$htmlroot/$1.html$section";
1733 # Here, we take advantage of the knowledge that $htmlfileurl ne ''
1734 # implies $htmlroot eq ''. This means that the link in question
1735 # needs a prefix of $htmldir if it begins with '/'. The test for
1736 # the initial '/' is done to avoid '#'-only links, and to allow
1737 # for other kinds of links, like file:, ftp:, etc.
1739 if ( $htmlfileurl ne '' ) {
1740 $link = "$htmldir$link" if $link =~ m{^/};
1741 $url = relativize_url( $link, $htmlfileurl );
1742 # print( " b: [$link,$htmlfileurl,$url]\n" );
1755 # relativize_url - convert an absolute URL to one relative to a base URL.
1756 # Assumes both end in a filename.
1758 sub relativize_url {
1759 my ($dest,$source) = @_ ;
1761 my ($dest_volume,$dest_directory,$dest_file) =
1762 File::Spec::Unix->splitpath( $dest ) ;
1763 $dest = File::Spec::Unix->catpath( $dest_volume, $dest_directory, '' ) ;
1765 my ($source_volume,$source_directory,$source_file) =
1766 File::Spec::Unix->splitpath( $source ) ;
1767 $source = File::Spec::Unix->catpath( $source_volume, $source_directory, '' ) ;
1770 if ( $dest ne '' ) {
1771 $rel_path = File::Spec::Unix->abs2rel( $dest, $source ) ;
1774 if ( $rel_path ne '' &&
1775 substr( $rel_path, -1 ) ne '/' &&
1776 substr( $dest_file, 0, 1 ) ne '#'
1778 $rel_path .= "/$dest_file" ;
1781 $rel_path .= "$dest_file" ;
1789 # coderef - make URL from the text of a C<>
1792 my( $page, $item ) = @_;
1795 my $fid = fragment_id( $item );
1796 if( defined( $page ) ){
1797 # we have been given a $page...
1800 # Do we take it? Item could be a section!
1801 my $base = $items{$fid} || "";
1802 $base =~ s{[^/]*/}{};
1803 if( $base ne "$page.html" ){
1804 ### print STDERR "coderef( $page, $item ): items{$fid} = $items{$fid} = $base => discard page!\n";
1809 # no page - local items precede cached items
1810 if( defined( $fid ) ){
1811 if( exists $local_items{$fid} ){
1812 $page = $local_items{$fid};
1814 $page = $items{$fid};
1819 # if there was a pod file that we found earlier with an appropriate
1820 # =item directive, then create a link to that page.
1821 if( defined $page ){
1823 if( exists $pages{$page} and $pages{$page} =~ /([^:.]*)\.[^:]*:/){
1824 $page = $1 . '.html';
1826 my $link = "$htmlroot/$page#item_$fid";
1828 # Here, we take advantage of the knowledge that $htmlfileurl
1829 # ne '' implies $htmlroot eq ''.
1830 if ( $htmlfileurl ne '' ) {
1831 $link = "$htmldir$link" ;
1832 $url = relativize_url( $link, $htmlfileurl ) ;
1837 $url = "#item_" . $fid;
1840 confess "url has space: $url" if $url =~ /"[^"]*\s[^"]*"/;
1842 return( $url, $fid );
1848 # Adapted from Nick Ing-Simmons' PodToHtml package.
1850 my $source_file = shift ;
1851 my $destination_file = shift;
1853 my $source = URI::file->new_abs($source_file);
1854 my $uo = URI::file->new($destination_file,$source)->abs;
1855 return $uo->rel->as_string;
1860 # finish_list - finish off any pending HTML lists. this should be called
1861 # after the entire pod file has been read and converted.
1864 while ($listlevel > 0) {
1865 print HTML "</DL>\n";
1871 # htmlify - converts a pod section specification to a suitable section
1872 # specification for HTML. Note that we keep spaces and special characters
1873 # except ", ? (Netscape problem) and the hyphen (writer's problem...).
1877 $heading =~ s/(\s+)/ /g;
1878 $heading =~ s/\s+\Z//;
1879 $heading =~ s/\A\s+//;
1880 # The hyphen is a disgrace to the English language.
1881 $heading =~ s/[-"?]//g;
1882 $heading = lc( $heading );
1887 # depod - convert text by eliminating all interior sequences
1888 # Note: can be called with copy or modify semantics
1895 $E2c{amp} = '&'; # in Tk's pods
1903 ${$_[0]} = depod1( \$string );
1911 my( $rstr, $func, $closing ) = @_;
1913 return $res unless defined $$rstr;
1914 if( ! defined( $func ) ){
1915 # skip to next begin of an interior sequence
1916 while( $$rstr =~ s/\A(.*?)([BCEFILSXZ])<(<+[^\S\n]+)?// ){
1917 # recurse into its text
1918 $res .= $1 . depod1( $rstr, $2, closing $3);
1921 } elsif( $func eq 'E' ){
1922 # E<x> - convert to character
1923 $$rstr =~ s/^(\w+)>//;
1924 $res .= $E2c{$1} || "";
1925 } elsif( $func eq 'X' ){
1927 $$rstr =~ s/^[^>]*>//;
1928 } elsif( $func eq 'Z' ){
1932 # all others: either recurse into new function or
1933 # terminate at closing angle bracket
1934 my $term = pattern $closing;
1935 while( $$rstr =~ s/\A(.*?)(([BCEFILSXZ])<(<+[^\S\n]+)?|$term)// ){
1938 $res .= depod1( $rstr, $3, closing $4 );
1940 ## If we're here and $2 ne '>': undelimited interior sequence.
1941 ## Ignored, as this is called without proper indication of where we are.
1942 ## Rely on process_text to produce diagnostics.
1948 # fragment_id - construct a fragment identifier from:
1950 # b) contents of C<...>
1955 $text =~ s/\s+\Z//s;
1957 # a method or function?
1958 return $1 if $text =~ /(\w+)\s*\(/;
1959 return $1 if $text =~ /->\s*(\w+)\s*\(?/;
1962 return $1 if $text =~ /^([$@%*]\S+)/;
1964 # some pattern matching operator?
1965 return $1 if $text =~ m|^(\w+/).*/\w*$|;
1967 # fancy stuff... like "do { }"
1968 return $1 if $text =~ m|^(\w+)\s*{.*}$|;
1970 # honour the perlfunc manpage: func [PAR[,[ ]PAR]...]
1971 # and some funnies with ... Module ...
1972 return $1 if $text =~ m{^([a-z\d]+)(\s+[A-Z\d,/& ]+)?$};
1973 return $1 if $text =~ m{^([a-z\d]+)\s+Module(\s+[A-Z\d,/& ]+)?$};
1976 $text =~ s/\s+/_/sg;
1978 defined( $hc[ord($1)] ) ? $hc[ord($1)]
1979 : ( $hc[ord($1)] = sprintf( "%%%02X", ord($1) ) ) }gxe;
1980 $text = substr( $text, 0, 50 );
1987 # make_URL_href - generate HTML href from URL
1988 # Special treatment for CGI queries.
1990 sub make_URL_href($){
1993 s{^(http:[-\w/#~:.+=&%@!]+)(\?.*)$}{<A HREF="$1$2">$1</A>}i ){
1994 $url = "<A HREF=\"$url\">$url</A>";