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
430 <LINK REV="made" HREF="mailto:$Config{perladmin}">
437 # load/reload/validate/cache %pages and %items
438 get_cache($dircache, $itemcache, \@podpath, $podroot, $recurse);
440 # scan the pod for =item directives
441 scan_items( \%local_items, "", @poddata);
443 # put an index at the top of the file. note, if $doindex is 0 we
444 # still generate an index, but surround it with an html comment.
445 # that way some other program can extract it if desired.
447 print HTML "<A NAME=\"__index__\"></A>\n";
448 print HTML "<!-- INDEX BEGIN -->\n";
449 print HTML "<!--\n" unless $doindex;
451 print HTML "-->\n" unless $doindex;
452 print HTML "<!-- INDEX END -->\n\n";
453 print HTML "<HR>\n" if $doindex and $index;
455 # now convert this file
456 my $after_item; # set to true after an =item
457 warn "Converting input file $podfile\n" if $verbose;
458 foreach my $i (0..$#poddata){
459 $ptQuote = 0; # status of quote conversion
463 if (/^(=.*)/s) { # is it a pod directive?
467 if (/^=begin\s+(\S+)\s*(.*)/si) {# =begin
468 process_begin($1, $2);
469 } elsif (/^=end\s+(\S+)\s*(.*)/si) {# =end
471 } elsif (/^=cut/) { # =cut
473 } elsif (/^=pod/) { # =pod
476 next if @begin_stack && $begin_stack[-1] ne 'html';
478 if (/^=(head[1-6])\s+(.*\S)/s) { # =head[1-6] heading
479 process_head( $1, $2, $doindex && $index );
480 } elsif (/^=item\s*(.*\S)?/sm) { # =item text
481 warn "$0: $podfile: =item without bullet, number or text"
482 . " in paragraph $paragraph.\n" if !defined($1) or $1 eq '';
485 } elsif (/^=over\s*(.*)/) { # =over N
487 } elsif (/^=back/) { # =back
489 } elsif (/^=for\s+(\S+)\s*(.*)/si) {# =for
493 warn "$0: $podfile: unknown pod directive '$1' in "
494 . "paragraph $paragraph. ignoring.\n";
501 next if @begin_stack && $begin_stack[-1] ne 'html';
502 print HTML and next if @begin_stack && $begin_stack[-1] eq 'html';
504 if( $text =~ /\A\s+/ ){
505 process_pre( \$text );
506 print HTML "<PRE>\n$text</PRE>\n";
509 process_text( \$text );
511 # experimental: check for a paragraph where all lines
512 # have some ...\t...\t...\n pattern
514 my @lines = split( "\n", $text );
517 foreach my $line ( @lines ){
518 if( $line =~ /\S/ && $line !~ /\t/ ){
524 $text =~ s/\t+/<TD>/g;
525 $text =~ s/^/<TR><TD>/gm;
526 $text = '<TABLE CELLSPACING=0 CELLPADDING=0>' .
531 ## end of experimental
534 print HTML "$text\n";
537 print HTML "<P>$text</P>\n";
544 # finish off any pending directives
548 print HTML "<P><A HREF=\"#__index__\"><SMALL>$backlink</SMALL></A></P>\n"
549 if $doindex and $index and $backlink;
551 print HTML <<END_OF_TAIL;
558 # close the html file
561 warn "Finished\n" if $verbose;
564 ##############################################################################
566 my $usage; # see below
569 warn "$0: $podfile: @_\n" if @_;
573 $usage =<<END_OF_USAGE;
574 Usage: $0 --help --htmlroot=<name> --infile=<name> --outfile=<name>
575 --podpath=<name>:...:<name> --podroot=<name>
576 --libpods=<name>:...:<name> --recurse --verbose --index
577 --netscape --norecurse --noindex --cachedir=<name>
579 --backlink - set text for "back to top" links (default: none).
580 --cachedir - directory for the item and directory cache files.
581 --css - stylesheet URL
582 --flush - flushes the item and directory caches.
583 --[no]header - produce block header/footer (default is no headers).
584 --help - prints this message.
585 --htmldir - directory for resulting HTML files.
586 --htmlroot - http-server base directory from which all relative paths
587 in podpath stem (default is /).
588 --[no]index - generate an index at the top of the resulting html
590 --infile - filename for the pod to convert (input taken from stdin
592 --libpods - colon-separated list of pages to search for =item pod
593 directives in as targets of C<> and implicit links (empty
594 by default). note, these are not filenames, but rather
595 page names like those that appear in L<> links.
596 --[no]netscape - will use netscape html directives when applicable.
597 (default is not to use them).
598 --outfile - filename for the resulting html file (output sent to
600 --podpath - colon-separated list of directories containing library
601 pods (empty by default).
602 --podroot - filesystem base directory from which all relative paths
603 in podpath stem (default is .).
604 --[no]quiet - supress some benign warning messages (default is off).
605 --[no]recurse - recurse on those subdirectories listed in podpath
607 --title - title that will appear in resulting html file.
608 --[no]verbose - self-explanatory (off by default).
612 sub parse_command_line {
613 my ($opt_backlink,$opt_cachedir,$opt_css,$opt_flush,$opt_header,$opt_help,
614 $opt_htmldir,$opt_htmlroot,$opt_index,$opt_infile,$opt_libpods,
615 $opt_netscape,$opt_outfile,$opt_podpath,$opt_podroot,$opt_quiet,
616 $opt_recurse,$opt_title,$opt_verbose);
618 unshift @ARGV, split ' ', $Config{pod2html} if $Config{pod2html};
619 my $result = GetOptions(
620 'backlink=s' => \$opt_backlink,
621 'cachedir=s' => \$opt_cachedir,
622 'css=s' => \$opt_css,
623 'flush' => \$opt_flush,
624 'header!' => \$opt_header,
625 'help' => \$opt_help,
626 'htmldir=s' => \$opt_htmldir,
627 'htmlroot=s' => \$opt_htmlroot,
628 'index!' => \$opt_index,
629 'infile=s' => \$opt_infile,
630 'libpods=s' => \$opt_libpods,
631 'netscape!' => \$opt_netscape,
632 'outfile=s' => \$opt_outfile,
633 'podpath=s' => \$opt_podpath,
634 'podroot=s' => \$opt_podroot,
635 'quiet!' => \$opt_quiet,
636 'recurse!' => \$opt_recurse,
637 'title=s' => \$opt_title,
638 'verbose!' => \$opt_verbose,
640 usage("-", "invalid parameters") if not $result;
642 usage("-") if defined $opt_help; # see if the user asked for help
643 $opt_help = ""; # just to make -w shut-up.
645 @podpath = split(":", $opt_podpath) if defined $opt_podpath;
646 @libpods = split(":", $opt_libpods) if defined $opt_libpods;
648 $backlink = $opt_backlink if defined $opt_backlink;
649 $cachedir = $opt_cachedir if defined $opt_cachedir;
650 $css = $opt_css if defined $opt_css;
651 $header = $opt_header if defined $opt_header;
652 $htmldir = $opt_htmldir if defined $opt_htmldir;
653 $htmlroot = $opt_htmlroot if defined $opt_htmlroot;
654 $doindex = $opt_index if defined $opt_index;
655 $podfile = $opt_infile if defined $opt_infile;
656 $netscape = $opt_netscape if defined $opt_netscape;
657 $htmlfile = $opt_outfile if defined $opt_outfile;
658 $podroot = $opt_podroot if defined $opt_podroot;
659 $quiet = $opt_quiet if defined $opt_quiet;
660 $recurse = $opt_recurse if defined $opt_recurse;
661 $title = $opt_title if defined $opt_title;
662 $verbose = $opt_verbose if defined $opt_verbose;
664 warn "Flushing item and directory caches\n"
665 if $opt_verbose && defined $opt_flush;
666 $dircache = "$cachedir/pod2htmd$cache_ext";
667 $itemcache = "$cachedir/pod2htmi$cache_ext";
668 unlink($dircache, $itemcache) if defined $opt_flush;
675 my($dircache, $itemcache, $podpath, $podroot, $recurse) = @_;
676 my @cache_key_args = @_;
678 # A first-level cache:
679 # Don't bother reading the cache files if they still apply
680 # and haven't changed since we last read them.
682 my $this_cache_key = cache_key(@cache_key_args);
684 return if $saved_cache_key and $this_cache_key eq $saved_cache_key;
686 # load the cache of %pages and %items if possible. $tests will be
687 # non-zero if successful.
689 if (-f $dircache && -f $itemcache) {
690 warn "scanning for item cache\n" if $verbose;
691 $tests = load_cache($dircache, $itemcache, $podpath, $podroot);
694 # if we didn't succeed in loading the cache then we must (re)build
697 warn "scanning directories in pod-path\n" if $verbose;
698 scan_podpath($podroot, $recurse, 0);
700 $saved_cache_key = cache_key(@cache_key_args);
704 my($dircache, $itemcache, $podpath, $podroot, $recurse) = @_;
705 return join('!', $dircache, $itemcache, $recurse,
706 @$podpath, $podroot, stat($dircache), stat($itemcache));
710 # load_cache - tries to find if the caches stored in $dircache and $itemcache
711 # are valid caches of %pages and %items. if they are valid then it loads
712 # them and returns a non-zero value.
715 my($dircache, $itemcache, $podpath, $podroot) = @_;
721 open(CACHE, "<$itemcache") ||
722 die "$0: error opening $itemcache for reading: $!\n";
725 # is it the same podpath?
728 $tests++ if (join(":", @$podpath) eq $_);
730 # is it the same podroot?
733 $tests++ if ($podroot eq $_);
735 # load the cache if its good
741 warn "loading item cache\n" if $verbose;
748 warn "scanning for directory cache\n" if $verbose;
749 open(CACHE, "<$dircache") ||
750 die "$0: error opening $dircache for reading: $!\n";
754 # is it the same podpath?
757 $tests++ if (join(":", @$podpath) eq $_);
759 # is it the same podroot?
762 $tests++ if ($podroot eq $_);
764 # load the cache if its good
770 warn "loading directory cache\n" if $verbose;
782 # scan_podpath - scans the directories specified in @podpath for directories,
783 # .pod files, and .pm files. it also scans the pod files specified in
784 # @libpods for =item directives.
787 my($podroot, $recurse, $append) = @_;
789 my($libpod, $dirname, $pod, @files, @poddata);
796 # scan each directory listed in @podpath
799 || die "$0: error changing to directory $podroot: $!\n";
800 foreach $dir (@podpath) {
801 scan_dir($dir, $recurse);
804 # scan the pods listed in @libpods for =item directives
805 foreach $libpod (@libpods) {
806 # if the page isn't defined then we won't know where to find it
808 next unless defined $pages{$libpod} && $pages{$libpod};
810 # if there is a directory then use the .pod and .pm files within it.
811 # NOTE: Only finds the first so-named directory in the tree.
812 # if ($pages{$libpod} =~ /([^:]*[^(\.pod|\.pm)]):/) {
813 if ($pages{$libpod} =~ /([^:]*(?<!\.pod)(?<!\.pm)):/) {
814 # find all the .pod and .pm files within the directory
816 opendir(DIR, $dirname) ||
817 die "$0: error opening directory $dirname: $!\n";
818 @files = grep(/(\.pod|\.pm)\z/ && ! -d $_, readdir(DIR));
821 # scan each .pod and .pm file for =item directives
822 foreach $pod (@files) {
823 open(POD, "<$dirname/$pod") ||
824 die "$0: error opening $dirname/$pod for input: $!\n";
827 clean_data( \@poddata );
829 scan_items( \%items, "$dirname/$pod", @poddata);
832 # use the names of files as =item directives too.
833 ### Don't think this should be done this way - confuses issues.(WL)
834 ### foreach $pod (@files) {
835 ### $pod =~ /^(.*)(\.pod|\.pm)$/;
836 ### $items{$1} = "$dirname/$1.html" if $1;
838 } elsif ($pages{$libpod} =~ /([^:]*\.pod):/ ||
839 $pages{$libpod} =~ /([^:]*\.pm):/) {
840 # scan the .pod or .pm file for =item directives
842 open(POD, "<$pod") ||
843 die "$0: error opening $pod for input: $!\n";
846 clean_data( \@poddata );
848 scan_items( \%items, "$pod", @poddata);
850 warn "$0: shouldn't be here (line ".__LINE__."\n";
853 @poddata = (); # clean-up a bit
856 || die "$0: error changing to directory $pwd: $!\n";
858 # cache the item list for later use
859 warn "caching items for later use\n" if $verbose;
860 open(CACHE, ">$itemcache") ||
861 die "$0: error open $itemcache for writing: $!\n";
863 print CACHE join(":", @podpath) . "\n$podroot\n";
864 foreach my $key (keys %items) {
865 print CACHE "$key $items{$key}\n";
870 # cache the directory list for later use
871 warn "caching directories for later use\n" if $verbose;
872 open(CACHE, ">$dircache") ||
873 die "$0: error open $dircache for writing: $!\n";
875 print CACHE join(":", @podpath) . "\n$podroot\n";
876 foreach my $key (keys %pages) {
877 print CACHE "$key $pages{$key}\n";
884 # scan_dir - scans the directory specified in $dir for subdirectories, .pod
885 # files, and .pm files. notes those that it finds. this information will
886 # be used later in order to figure out where the pages specified in L<>
887 # links are on the filesystem.
890 my($dir, $recurse) = @_;
891 my($t, @subdirs, @pods, $pod, $dirname, @dirs);
897 opendir(DIR, $dir) ||
898 die "$0: error opening directory $dir: $!\n";
899 while (defined($_ = readdir(DIR))) {
900 if (-d "$dir/$_" && $_ ne "." && $_ ne "..") { # directory
901 $pages{$_} = "" unless defined $pages{$_};
902 $pages{$_} .= "$dir/$_:";
904 } elsif (/\.pod\z/) { # .pod
906 $pages{$_} = "" unless defined $pages{$_};
907 $pages{$_} .= "$dir/$_.pod:";
908 push(@pods, "$dir/$_.pod");
909 } elsif (/\.html\z/) { # .html
911 $pages{$_} = "" unless defined $pages{$_};
912 $pages{$_} .= "$dir/$_.pod:";
913 } elsif (/\.pm\z/) { # .pm
915 $pages{$_} = "" unless defined $pages{$_};
916 $pages{$_} .= "$dir/$_.pm:";
917 push(@pods, "$dir/$_.pm");
922 # recurse on the subdirectories if necessary
924 foreach my $subdir (@subdirs) {
925 scan_dir("$dir/$subdir", $recurse);
931 # scan_headings - scan a pod file for head[1-6] tags, note the tags, and
935 my($sections, @data) = @_;
936 my($tag, $which_head, $otitle, $listdepth, $index);
938 # here we need local $ignore = 0;
939 # unfortunately, we can't have it, because $ignore is lexical
945 # scan for =head directives, note their name, and build an index
946 # pointing to each of them.
947 foreach my $line (@data) {
948 if ($line =~ /^=(head)([1-6])\s+(.*)/) {
949 ($tag, $which_head, $otitle) = ($1,$2,$3);
951 my $title = depod( $otitle );
952 my $name = htmlify( $title );
953 $$sections{$name} = 1;
954 $title = process_text( \$otitle );
956 while ($which_head != $listdepth) {
957 if ($which_head > $listdepth) {
958 $index .= "\n" . ("\t" x $listdepth) . "<UL>\n";
960 } elsif ($which_head < $listdepth) {
962 $index .= "\n" . ("\t" x $listdepth) . "</UL>\n";
966 $index .= "\n" . ("\t" x $listdepth) . "<LI>" .
967 "<A HREF=\"#" . $name . "\">" .
968 $title . "</A></LI>";
972 # finish off the lists
973 while ($listdepth--) {
974 $index .= "\n" . ("\t" x $listdepth) . "</UL>\n";
977 # get rid of bogus lists
978 $index =~ s,\t*<UL>\s*</UL>\n,,g;
980 $ignore = 1; # restore old value;
986 # scan_items - scans the pod specified by $pod for =item directives. we
987 # will use this information later on in resolving C<> links.
990 my( $itemref, $pod, @poddata ) = @_;
995 $pod .= ".html" if $pod;
997 foreach $i (0..$#poddata) {
998 my $txt = depod( $poddata[$i] );
1000 # figure out what kind of item it is.
1001 # Build string for referencing this item.
1002 if ( $txt =~ /\A=item\s+\*\s*(.*)\Z/s ) { # bullet
1005 } elsif( $txt =~ /\A=item\s+(?>\d+\.?)\s*(.*)\Z/s ) { # numbered list
1007 } elsif( $txt =~ /\A=item\s+(.*)\Z/s ) { # plain item
1012 my $fid = fragment_id( $item );
1013 $$itemref{$fid} = "$pod" if $fid;
1018 # process_head - convert a pod head[1-6] tag and convert it to HTML format.
1021 my($tag, $heading, $hasindex) = @_;
1023 # figure out the level of the =head
1024 $tag =~ /head([1-6])/;
1028 warn "$0: $podfile: unterminated list at =head in paragraph $paragraph. ignoring.\n";
1029 while( $listlevel ){
1035 if( $level == 1 && ! $top ){
1036 print HTML "<A HREF=\"#__index__\"><SMALL>$backlink</SMALL></A>\n"
1037 if $hasindex and $backlink;
1041 my $name = htmlify( depod( $heading ) );
1042 my $convert = process_text( \$heading );
1043 print HTML "<H$level><A NAME=\"$name\">$convert</A></H$level>\n";
1048 # emit_item_tag - print an =item's text
1049 # Note: The global $EmittedItem is used for inhibiting self-references.
1053 sub emit_item_tag($$$){
1054 my( $otext, $text, $compact ) = @_;
1055 my $item = fragment_id( $text );
1057 $EmittedItem = $item;
1058 ### print STDERR "emit_item_tag=$item ($text)\n";
1060 print HTML '<STRONG>';
1061 if ($items_named{$item}++) {
1062 print HTML process_text( \$otext );
1064 my $name = 'item_' . $item;
1065 print HTML qq{<A NAME="$name">}, process_text( \$otext ), '</A>';
1067 print HTML "</STRONG><BR>\n";
1068 undef( $EmittedItem );
1073 if( $items_seen[$listlevel]++ == 0 ){
1074 push( @listend, "</$tag>" );
1075 print HTML "<$tag>\n";
1077 print HTML $tag eq 'DL' ? '<DT>' : '<LI>';
1081 # process_item - convert a pod item tag and convert it to HTML format.
1086 # lots of documents start a list without doing an =over. this is
1087 # bad! but, the proper thing to do seems to be to just assume
1088 # they did do an =over. so warn them once and then continue.
1089 if( $listlevel == 0 ){
1090 warn "$0: $podfile: unexpected =item directive in paragraph $paragraph. ignoring.\n";
1094 # formatting: insert a paragraph if preceding item has >1 paragraph
1096 print HTML "<P></P>\n";
1100 # remove formatting instructions from the text
1101 my $text = depod( $otext );
1103 # all the list variants:
1104 if( $text =~ /\A\*/ ){ # bullet
1106 if ($text =~ /\A\*\s+(.+)\Z/s ) { # with additional text
1108 $otext =~ s/\A\*\s+//;
1109 emit_item_tag( $otext, $tag, 1 );
1112 } elsif( $text =~ /\A\d+/ ){ # numbered list
1114 if ($text =~ /\A(?>\d+\.?)\s*(.+)\Z/s ) { # with additional text
1116 $otext =~ s/\A\d+\.?\s*//;
1117 emit_item_tag( $otext, $tag, 1 );
1120 } else { # definition list
1122 if ($text =~ /\A(.+)\Z/s ){ # should have text
1123 emit_item_tag( $otext, $text, 1 );
1131 # process_over - process a pod over tag and start a corresponding HTML list.
1136 push( @items_seen, 0 );
1141 # process_back - process a pod back tag and convert it to HTML format.
1144 if( $listlevel == 0 ){
1145 warn "$0: $podfile: unexpected =back directive in paragraph $paragraph. ignoring.\n";
1149 # close off the list. note, I check to see if $listend[$listlevel] is
1150 # defined because an =item directive may have never appeared and thus
1151 # $listend[$listlevel] may have never been initialized.
1153 if( defined $listend[$listlevel] ){
1154 print HTML '<P></P>' if $after_lpar;
1155 print HTML $listend[$listlevel];
1161 # clean up item count
1166 # process_cut - process a pod cut tag, thus start ignoring pod directives.
1173 # process_pod - process a pod pod tag, thus stop ignoring pod directives
1174 # until we see a corresponding cut.
1177 # no need to set $ignore to 0 cause the main loop did it
1181 # process_for - process a =for pod tag. if it's for html, spit
1182 # it out verbatim, if illustration, center it, otherwise ignore it.
1185 my($whom, $text) = @_;
1186 if ( $whom =~ /^(pod2)?html$/i) {
1188 } elsif ($whom =~ /^illustration$/i) {
1189 1 while chomp $text;
1190 for my $ext (qw[.png .gif .jpeg .jpg .tga .pcl .bmp]) {
1191 $text .= $ext, last if -r "$text$ext";
1193 print HTML qq{<p align = "center"><img src = "$text" alt = "$text illustration"></p>};
1198 # process_begin - process a =begin pod tag. this pushes
1199 # whom we're beginning on the begin stack. if there's a
1200 # begin stack, we only print if it us.
1203 my($whom, $text) = @_;
1205 push (@begin_stack, $whom);
1206 if ( $whom =~ /^(pod2)?html$/) {
1207 print HTML $text if $text;
1212 # process_end - process a =end pod tag. pop the
1213 # begin stack. die if we're mismatched.
1216 my($whom, $text) = @_;
1218 if ($begin_stack[-1] ne $whom ) {
1219 die "Unmatched begin/end at chunk $paragraph\n"
1221 pop( @begin_stack );
1225 # process_pre - indented paragraph, made into <PRE></PRE>
1234 # insert spaces in place of tabs
1237 1 while $line =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e;
1241 # convert some special chars to HTML escapes
1242 $rest =~ s/&/&/g;
1243 $rest =~ s/</</g;
1244 $rest =~ s/>/>/g;
1245 $rest =~ s/"/"/g;
1247 # try and create links for all occurrences of perl.* within
1248 # the preformatted text.
1252 if ( defined $pages{$2} ){ # is a link
1253 qq($1<A HREF="$htmlroot/$pages{$2}">$2</A>);
1254 } elsif (defined $pages{dosify($2)}) { # is a link
1255 qq($1<A HREF="$htmlroot/$pages{dosify($2)}">$2</A>);
1261 (<A\ HREF="?) ([^>:]*:)? ([^>:]*) \.pod: ([^>:]*:)?
1264 if ( $htmlfileurl ne '' ){
1265 # Here, we take advantage of the knowledge
1266 # that $htmlfileurl ne '' implies $htmlroot eq ''.
1267 # Since $htmlroot eq '', we need to prepend $htmldir
1268 # on the fron of the link to get the absolute path
1269 # of the link's target. We check for a leading '/'
1270 # to avoid corrupting links that are #, file:, etc.
1272 $old_url = "$htmldir$old_url" if $old_url =~ m{^\/};
1273 $url = relativize_url( "$old_url.html", $htmlfileurl );
1280 # Look for embedded URLs and make them into links. We don't
1281 # relativize them since they are best left as the author intended.
1283 my $urls = '(' . join ('|', qw{
1296 my $gunk = '/#~:.?+=&%@!\-';
1298 my $any = "${ltrs}${gunk}${punc}";
1301 \b # start at word boundary
1303 $urls : # need resource and a colon
1304 (?!:) # Ignore File::, among others.
1305 [$any] +? # followed by on or more
1306 # of any valid character, but
1307 # be conservative and take only
1308 # what you need to....
1310 (?= # look-ahead non-consumptive assertion
1311 [$punc]* # either 0 or more puntuation
1312 [^$any] # followed by a non-url char
1314 $ # then end of the string
1316 }{<A HREF="$1">$1</A>}igox;
1318 # text should be as it is (verbatim)
1324 # pure text processing
1326 # pure_text/inIS_text: differ with respect to automatic C<> recognition.
1327 # we don't want this to happen within IS
1331 process_puretext( $text, \$ptQuote, 1 );
1336 process_puretext( $text, \$ptQuote, 0 );
1340 # process_puretext - process pure text (without pod-escapes) converting
1341 # double-quotes and handling implicit C<> links.
1343 sub process_puretext {
1344 my($text, $quote, $notinIS) = @_;
1346 ## Guessing at func() or [$@%&]*var references in plain text is destined
1347 ## to produce some strange looking ref's. uncomment to disable:
1350 my(@words, $lead, $trail);
1352 # convert double-quotes to single-quotes
1353 if( $$quote && $text =~ s/"/''/s ){
1356 while ($text =~ s/"([^"]*)"/``$1''/sg) {};
1357 $$quote = 1 if $text =~ s/"/``/s;
1359 # keep track of leading and trailing white-space
1360 $lead = ($text =~ s/\A(\s+)//s ? $1 : "");
1361 $trail = ($text =~ s/(\s+)\Z//s ? $1 : "");
1363 # split at space/non-space boundaries
1364 @words = split( /(?<=\s)(?=\S)|(?<=\S)(?=\s)/, $text );
1366 # process each word individually
1367 foreach my $word (@words) {
1369 next if $word =~ /^\s*$/;
1370 # see if we can infer a link
1371 if( $notinIS && $word =~ /^(\w+)\((.*)\)$/ ) {
1372 # has parenthesis so should have been a C<> ref
1373 ## try for a pagename (perlXXX(1))?
1374 my( $func, $args ) = ( $1, $2 );
1375 if( $args =~ /^\d+$/ ){
1376 my $url = page_sect( $word, '' );
1378 $word = "<A HREF=\"$url\">the $word manpage</A>";
1382 ## try function name for a link, append tt'ed argument list
1383 $word = emit_C( $func, '', "($args)");
1385 #### disabled. either all (including $\W, $\w+{.*} etc.) or nothing.
1386 ## } elsif( $notinIS && $word =~ /^[\$\@%&*]+\w+$/) {
1387 ## # perl variables, should be a C<> ref
1388 ## $word = emit_C( $word );
1390 } elsif ($word =~ m,^\w+://\w,) {
1392 # Don't relativize it: leave it as the author intended
1393 $word = qq(<A HREF="$word">$word</A>);
1394 } elsif ($word =~ /[\w.-]+\@[\w-]+\.\w/) {
1395 # looks like an e-mail address
1396 my ($w1, $w2, $w3) = ("", $word, "");
1397 ($w1, $w2, $w3) = ("(", $1, ")$2") if $word =~ /^\((.*?)\)(,?)/;
1398 ($w1, $w2, $w3) = ("<", $1, ">$2") if $word =~ /^<(.*?)>(,?)/;
1399 $word = qq($w1<A HREF="mailto:$w2">$w2</A>$w3);
1400 } elsif ($word !~ /[a-z]/ && $word =~ /[A-Z]/) { # all uppercase?
1401 $word = html_escape($word) if $word =~ /["&<>]/;
1402 $word = "\n<FONT SIZE=-1>$word</FONT>" if $netscape;
1404 $word = html_escape($word) if $word =~ /["&<>]/;
1408 # put everything back together
1409 return $lead . join( '', @words ) . $trail;
1414 # process_text - handles plaintext that appears in the input pod file.
1415 # there may be pod commands embedded within the text so those must be
1416 # converted to html commands.
1419 sub process_text1($$;$$);
1420 sub pattern ($) { $_[0] ? '[^\S\n]+'.('>' x ($_[0] + 1)) : '>' }
1421 sub closing ($) { local($_) = shift; (defined && s/\s+$//) ? length : 0 }
1426 my $res = process_text1( 0, $tref );
1430 sub process_text1($$;$$){
1431 my( $lev, $rstr, $func, $closing ) = @_;
1434 unless (defined $func) {
1440 # B<text> - boldface
1441 $res = '<STRONG>' . process_text1( $lev, $rstr ) . '</STRONG>';
1443 } elsif( $func eq 'C' ){
1444 # C<code> - can be a ref or <CODE></CODE>
1445 # need to extract text
1446 my $par = go_ahead( $rstr, 'C', $closing );
1448 ## clean-up of the link target
1449 my $text = depod( $par );
1451 ### my $x = $par =~ /[BI]</ ? 'yes' : 'no' ;
1452 ### print STDERR "-->call emit_C($par) lev=$lev, par with BI=$x\n";
1454 $res = emit_C( $text, $lev > 1 || ($par =~ /[BI]</) );
1456 } elsif( $func eq 'E' ){
1457 # E<x> - convert to character
1458 $$rstr =~ s/^([^>]*)>//;
1460 $escape =~ s/^(\d+|X[\dA-F]+)$/#$1/i;
1463 } elsif( $func eq 'F' ){
1464 # F<filename> - italizice
1465 $res = '<EM>' . process_text1( $lev, $rstr ) . '</EM>';
1467 } elsif( $func eq 'I' ){
1468 # I<text> - italizice
1469 $res = '<EM>' . process_text1( $lev, $rstr ) . '</EM>';
1471 } elsif( $func eq 'L' ){
1473 ## L<text|cross-ref> => produce text, use cross-ref for linking
1474 ## L<cross-ref> => make text from cross-ref
1475 ## need to extract text
1476 my $par = go_ahead( $rstr, 'L', $closing );
1478 # some L<>'s that shouldn't be:
1479 # a) full-blown URL's are emitted as-is
1480 if( $par =~ m{^\w+://}s ){
1481 return make_URL_href( $par );
1483 # b) C<...> is stripped and treated as C<>
1484 if( $par =~ /^C<(.*)>$/ ){
1485 my $text = depod( $1 );
1486 return emit_C( $text, $lev > 1 || ($par =~ /[BI]</) );
1489 # analyze the contents
1490 $par =~ s/\n/ /g; # undo word-wrapped tags
1493 if( $par =~ s{^([^|]+)\|}{} ){
1497 # make sure sections start with a /
1500 my( $page, $section, $ident );
1502 # check for link patterns
1503 if( $par =~ m{^([^/]+?)/(?!")(.*?)$} ){ # name/ident
1504 # we've got a name/ident (no quotes)
1505 ( $page, $ident ) = ( $1, $2 );
1506 ### print STDERR "--> L<$par> to page $page, ident $ident\n";
1508 } elsif( $par =~ m{^(.*?)/"?(.*?)"?$} ){ # [name]/"section"
1509 # even though this should be a "section", we go for ident first
1510 ( $page, $ident ) = ( $1, $2 );
1511 ### print STDERR "--> L<$par> to page $page, section $section\n";
1513 } elsif( $par =~ /\s/ ){ # this must be a section with missing quotes
1514 ( $page, $section ) = ( '', $par );
1515 ### print STDERR "--> L<$par> to void page, section $section\n";
1518 ( $page, $section ) = ( $par, '' );
1519 ### print STDERR "--> L<$par> to page $par, void section\n";
1522 # now, either $section or $ident is defined. the convoluted logic
1523 # below tries to resolve L<> according to what the user specified.
1524 # failing this, we try to find the next best thing...
1525 my( $url, $ltext, $fid );
1528 if( defined $ident ){
1529 ## try to resolve $ident as an item
1530 ( $url, $fid ) = coderef( $page, $ident );
1532 if( ! defined( $linktext ) ){
1534 $linktext .= " in " if $ident && $page;
1535 $linktext .= "the $page manpage" if $page;
1537 ### print STDERR "got coderef url=$url\n";
1540 ## no luck: go for a section (auto-quoting!)
1543 ## now go for a section
1544 my $htmlsection = htmlify( $section );
1545 $url = page_sect( $page, $htmlsection );
1547 if( ! defined( $linktext ) ){
1548 $linktext = $section;
1549 $linktext .= " in " if $section && $page;
1550 $linktext .= "the $page manpage" if $page;
1552 ### print STDERR "got page/section url=$url\n";
1555 ## no luck: go for an ident
1562 ( $url, $fid ) = coderef( $page, $ident );
1564 if( ! defined( $linktext ) ){
1566 $linktext .= " in " if $ident && $page;
1567 $linktext .= "the $page manpage" if $page;
1569 ### print STDERR "got section=>coderef url=$url\n";
1573 # warning; show some text.
1574 $linktext = $opar unless defined $linktext;
1575 warn "$0: $podfile: cannot resolve L<$opar> in paragraph $paragraph.";
1578 # now we have an URL or just plain code
1579 $$rstr = $linktext . '>' . $$rstr;
1580 if( defined( $url ) ){
1581 $res = "<A HREF=\"$url\">" . process_text1( $lev, $rstr ) . '</A>';
1583 $res = '<EM>' . process_text1( $lev, $rstr ) . '</EM>';
1586 } elsif( $func eq 'S' ){
1587 # S<text> - non-breaking spaces
1588 $res = process_text1( $lev, $rstr );
1589 $res =~ s/ / /g;
1591 } elsif( $func eq 'X' ){
1593 $$rstr =~ s/^[^>]*>//;
1595 } elsif( $func eq 'Z' ){
1597 warn "$0: $podfile: invalid X<> in paragraph $paragraph."
1598 unless $$rstr =~ s/^>//;
1601 my $term = pattern $closing;
1602 while( $$rstr =~ s/\A(.*?)(([BCEFILSXZ])<(<+[^\S\n]+)?|$term)//s ){
1603 # all others: either recurse into new function or
1604 # terminate at closing angle bracket(s)
1606 $pt .= $2 if !$3 && $lev == 1;
1607 $res .= $lev == 1 ? pure_text( $pt ) : inIS_text( $pt );
1608 return $res if !$3 && $lev > 1;
1610 $res .= process_text1( $lev, $rstr, $3, closing $4 );
1614 $res .= pure_text( $$rstr );
1616 warn "$0: $podfile: undelimited $func<> in paragraph $paragraph.";
1623 # go_ahead: extract text of an IS (can be nested)
1626 my( $rstr, $func, $closing ) = @_;
1628 my @closing = ($closing);
1630 s/\A(.*?)(([BCEFILSXZ])<(<+[^\S\n]+)?|@{[pattern $closing[0]]})//s ){
1634 return $res unless @closing;
1636 unshift @closing, closing $4;
1640 warn "$0: $podfile: undelimited $func<> in paragraph $paragraph.";
1645 # emit_C - output result of C<text>
1646 # $text is the depod-ed text
1649 my( $text, $nocode, $args ) = @_;
1650 $args = '' unless defined $args;
1652 my( $url, $fid ) = coderef( undef(), $text );
1654 # need HTML-safe text
1655 my $linktext = html_escape( "$text$args" );
1657 if( defined( $url ) &&
1658 (!defined( $EmittedItem ) || $EmittedItem ne $fid ) ){
1659 $res = "<A HREF=\"$url\"><CODE>$linktext</CODE></A>";
1660 } elsif( 0 && $nocode ){
1663 $res = "<CODE>$linktext</CODE>";
1669 # html_escape: make text safe for HTML
1673 $rest =~ s/&/&/g;
1674 $rest =~ s/</</g;
1675 $rest =~ s/>/>/g;
1676 $rest =~ s/"/"/g;
1682 # dosify - convert filenames to 8.3
1686 return lc($str) if $^O eq 'VMS'; # VMS just needs casing
1689 $str =~ s/(\.\w+)/substr ($1,0,4)/ge;
1690 $str =~ s/(\w+)/substr ($1,0,8)/ge;
1696 # page_sect - make an URL from the text of a L<>
1699 my( $page, $section ) = @_;
1700 my( $linktext, $page83, $link); # work strings
1702 # check if we know that this is a section in this page
1703 if (!defined $pages{$page} && defined $sections{$page}) {
1706 ### print STDERR "reset page='', section=$section\n";
1709 $page83=dosify($page);
1710 $page=$page83 if (defined $pages{$page83});
1712 $link = "#" . htmlify( $section );
1713 } elsif ( $page =~ /::/ ) {
1715 # Search page cache for an entry keyed under the html page name,
1716 # then look to see what directory that page might be in. NOTE:
1717 # this will only find one page. A better solution might be to produce
1718 # an intermediate page that is an index to all such pages.
1719 my $page_name = $page ;
1720 $page_name =~ s,^.*/,,s ;
1721 if ( defined( $pages{ $page_name } ) &&
1722 $pages{ $page_name } =~ /([^:]*$page)\.(?:pod|pm):/
1727 # NOTE: This branch assumes that all A::B pages are located in
1728 # $htmlroot/A/B.html . This is often incorrect, since they are
1729 # often in $htmlroot/lib/A/B.html or such like. Perhaps we could
1730 # analyze the contents of %pages and figure out where any
1731 # cousins of A::B are, then assume that. So, if A::B isn't found,
1732 # but A::C is found in lib/A/C.pm, then A::B is assumed to be in
1733 # lib/A/B.pm. This is also limited, but it's an improvement.
1734 # Maybe a hints file so that the links point to the correct places
1738 $link = "$htmlroot/$page.html";
1739 $link .= "#" . htmlify( $section ) if ($section);
1740 } elsif (!defined $pages{$page}) {
1743 $section = htmlify( $section ) if $section ne "";
1744 ### print STDERR "...section=$section\n";
1746 # if there is a directory by the name of the page, then assume that an
1747 # appropriate section will exist in the subdirectory
1748 # if ($section ne "" && $pages{$page} =~ /([^:]*[^(\.pod|\.pm)]):/) {
1749 if ($section ne "" && $pages{$page} =~ /([^:]*(?<!\.pod)(?<!\.pm)):/) {
1750 $link = "$htmlroot/$1/$section.html";
1751 ### print STDERR "...link=$link\n";
1753 # since there is no directory by the name of the page, the section will
1754 # have to exist within a .html of the same name. thus, make sure there
1755 # is a .pod or .pm that might become that .html
1757 $section = "#$section" if $section;
1758 ### print STDERR "...section=$section\n";
1760 # check if there is a .pod with the page name
1761 if ($pages{$page} =~ /([^:]*)\.pod:/) {
1762 $link = "$htmlroot/$1.html$section";
1763 } elsif ($pages{$page} =~ /([^:]*)\.pm:/) {
1764 $link = "$htmlroot/$1.html$section";
1772 # Here, we take advantage of the knowledge that $htmlfileurl ne ''
1773 # implies $htmlroot eq ''. This means that the link in question
1774 # needs a prefix of $htmldir if it begins with '/'. The test for
1775 # the initial '/' is done to avoid '#'-only links, and to allow
1776 # for other kinds of links, like file:, ftp:, etc.
1778 if ( $htmlfileurl ne '' ) {
1779 $link = "$htmldir$link" if $link =~ m{^/}s;
1780 $url = relativize_url( $link, $htmlfileurl );
1781 # print( " b: [$link,$htmlfileurl,$url]\n" );
1794 # relativize_url - convert an absolute URL to one relative to a base URL.
1795 # Assumes both end in a filename.
1797 sub relativize_url {
1798 my ($dest,$source) = @_ ;
1800 my ($dest_volume,$dest_directory,$dest_file) =
1801 File::Spec::Unix->splitpath( $dest ) ;
1802 $dest = File::Spec::Unix->catpath( $dest_volume, $dest_directory, '' ) ;
1804 my ($source_volume,$source_directory,$source_file) =
1805 File::Spec::Unix->splitpath( $source ) ;
1806 $source = File::Spec::Unix->catpath( $source_volume, $source_directory, '' ) ;
1809 if ( $dest ne '' ) {
1810 $rel_path = File::Spec::Unix->abs2rel( $dest, $source ) ;
1813 if ( $rel_path ne '' &&
1814 substr( $rel_path, -1 ) ne '/' &&
1815 substr( $dest_file, 0, 1 ) ne '#'
1817 $rel_path .= "/$dest_file" ;
1820 $rel_path .= "$dest_file" ;
1828 # coderef - make URL from the text of a C<>
1831 my( $page, $item ) = @_;
1834 my $fid = fragment_id( $item );
1835 if( defined( $page ) ){
1836 # we have been given a $page...
1839 # Do we take it? Item could be a section!
1840 my $base = $items{$fid} || "";
1841 $base =~ s{[^/]*/}{};
1842 if( $base ne "$page.html" ){
1843 ### print STDERR "coderef( $page, $item ): items{$fid} = $items{$fid} = $base => discard page!\n";
1848 # no page - local items precede cached items
1849 if( defined( $fid ) ){
1850 if( exists $local_items{$fid} ){
1851 $page = $local_items{$fid};
1853 $page = $items{$fid};
1858 # if there was a pod file that we found earlier with an appropriate
1859 # =item directive, then create a link to that page.
1860 if( defined $page ){
1862 if( exists $pages{$page} and $pages{$page} =~ /([^:.]*)\.[^:]*:/){
1863 $page = $1 . '.html';
1865 my $link = "$htmlroot/$page#item_$fid";
1867 # Here, we take advantage of the knowledge that $htmlfileurl
1868 # ne '' implies $htmlroot eq ''.
1869 if ( $htmlfileurl ne '' ) {
1870 $link = "$htmldir$link" ;
1871 $url = relativize_url( $link, $htmlfileurl ) ;
1876 $url = "#item_" . $fid;
1879 confess "url has space: $url" if $url =~ /"[^"]*\s[^"]*"/;
1881 return( $url, $fid );
1887 # Adapted from Nick Ing-Simmons' PodToHtml package.
1889 my $source_file = shift ;
1890 my $destination_file = shift;
1892 my $source = URI::file->new_abs($source_file);
1893 my $uo = URI::file->new($destination_file,$source)->abs;
1894 return $uo->rel->as_string;
1899 # finish_list - finish off any pending HTML lists. this should be called
1900 # after the entire pod file has been read and converted.
1903 while ($listlevel > 0) {
1904 print HTML "</DL>\n";
1910 # htmlify - converts a pod section specification to a suitable section
1911 # specification for HTML. Note that we keep spaces and special characters
1912 # except ", ? (Netscape problem) and the hyphen (writer's problem...).
1916 $heading =~ s/(\s+)/ /g;
1917 $heading =~ s/\s+\Z//;
1918 $heading =~ s/\A\s+//;
1919 # The hyphen is a disgrace to the English language.
1920 $heading =~ s/[-"?]//g;
1921 $heading = lc( $heading );
1926 # depod - convert text by eliminating all interior sequences
1927 # Note: can be called with copy or modify semantics
1934 $E2c{amp} = '&'; # in Tk's pods
1942 ${$_[0]} = depod1( \$string );
1950 my( $rstr, $func, $closing ) = @_;
1952 return $res unless defined $$rstr;
1953 if( ! defined( $func ) ){
1954 # skip to next begin of an interior sequence
1955 while( $$rstr =~ s/\A(.*?)([BCEFILSXZ])<(<+[^\S\n]+)?// ){
1956 # recurse into its text
1957 $res .= $1 . depod1( $rstr, $2, closing $3);
1960 } elsif( $func eq 'E' ){
1961 # E<x> - convert to character
1962 $$rstr =~ s/^([^>]*)>//;
1963 $res .= $E2c{$1} || "";
1964 } elsif( $func eq 'X' ){
1966 $$rstr =~ s/^[^>]*>//;
1967 } elsif( $func eq 'Z' ){
1971 # all others: either recurse into new function or
1972 # terminate at closing angle bracket
1973 my $term = pattern $closing;
1974 while( $$rstr =~ s/\A(.*?)(([BCEFILSXZ])<(<+[^\S\n]+)?|$term)// ){
1977 $res .= depod1( $rstr, $3, closing $4 );
1979 ## If we're here and $2 ne '>': undelimited interior sequence.
1980 ## Ignored, as this is called without proper indication of where we are.
1981 ## Rely on process_text to produce diagnostics.
1987 # fragment_id - construct a fragment identifier from:
1989 # b) contents of C<...>
1994 $text =~ s/\s+\Z//s;
1996 # a method or function?
1997 return $1 if $text =~ /(\w+)\s*\(/;
1998 return $1 if $text =~ /->\s*(\w+)\s*\(?/;
2001 return $1 if $text =~ /^([$@%*]\S+)/;
2003 # some pattern matching operator?
2004 return $1 if $text =~ m|^(\w+/).*/\w*$|;
2006 # fancy stuff... like "do { }"
2007 return $1 if $text =~ m|^(\w+)\s*{.*}$|;
2009 # honour the perlfunc manpage: func [PAR[,[ ]PAR]...]
2010 # and some funnies with ... Module ...
2011 return $1 if $text =~ m{^([a-z\d]+)(\s+[A-Z\d,/& ]+)?$};
2012 return $1 if $text =~ m{^([a-z\d]+)\s+Module(\s+[A-Z\d,/& ]+)?$};
2015 $text =~ s/\s+/_/sg;
2017 defined( $hc[ord($1)] ) ? $hc[ord($1)]
2018 : ( $hc[ord($1)] = sprintf( "%%%02X", ord($1) ) ) }gxe;
2019 $text = substr( $text, 0, 50 );
2026 # make_URL_href - generate HTML href from URL
2027 # Special treatment for CGI queries.
2029 sub make_URL_href($){
2032 s{^(http:[-\w/#~:.+=&%@!]+)(\?.*)$}{<A HREF="$1$2">$1</A>}i ){
2033 $url = "<A HREF=\"$url\">$url</A>";