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
311 for my $i ( 0..$#{$dataref} ) {
312 ${$dataref}[$i] =~ s/\s+\Z//;
314 # have a look for all-space lines
315 if( ${$dataref}[$i] =~ /^\s+$/m and $dataref->[$i] !~ /^\s/ ){
316 my @chunks = split( /^\s+$/m, ${$dataref}[$i] );
317 splice( @$dataref, $i, 1, @chunks );
330 $Is83 = 0 if (defined (&Dos::UseLFN) && Dos::UseLFN());
332 # cache of %pages and %items from last time we ran pod2html
334 #undef $opt_help if defined $opt_help;
336 # parse the command-line parameters
337 parse_command_line();
339 # set some variables to their default values if necessary
341 unless (@ARGV && $ARGV[0]) {
342 $podfile = "-" unless $podfile; # stdin
343 open(POD, "<$podfile")
344 || die "$0: cannot open $podfile file for input: $!\n";
346 $podfile = $ARGV[0]; # XXX: might be more filenames
349 $htmlfile = "-" unless $htmlfile; # stdout
350 $htmlroot = "" if $htmlroot eq "/"; # so we don't get a //
351 $htmldir =~ s#/\z## ; # so we don't get a //
353 && defined( $htmldir )
355 && substr( $htmlfile, 0, length( $htmldir ) ) eq $htmldir
358 # Set the 'base' url for this file, so that we can use it
359 # as the location from which to calculate relative links
360 # to other files. If this is '', then absolute links will
361 # be used throughout.
362 $htmlfileurl= "$htmldir/" . substr( $htmlfile, length( $htmldir ) + 1);
365 # read the pod a paragraph at a time
366 warn "Scanning for sections in input file(s)\n" if $verbose;
370 clean_data( \@poddata );
372 # scan the pod for =head[1-6] directives and build an index
373 my $index = scan_headings(\%sections, @poddata);
376 warn "No headings in $podfile\n" if $verbose;
379 # open the output file
380 open(HTML, ">$htmlfile")
381 || die "$0: cannot open $htmlfile file for output: $!\n";
383 # put a title in the HTML file if one wasn't specified
386 for my $i ( 0..$#poddata ) {
387 if ($poddata[$i] =~ /^=head1\s*NAME\b/m) {
388 for my $para ( @poddata[$i, $i+1] ) {
390 if ($title) = $para =~ /(\S+\s+-+.*\S)/s;
397 if (!$title and $podfile =~ /\.pod\z/) {
398 # probably a split pod so take first =head[12] as title
399 for my $i ( 0..$#poddata ) {
400 last if ($title) = $poddata[$i] =~ /^=head[12]\s*(.*)/;
402 warn "adopted '$title' as title for $podfile\n"
403 if $verbose and $title;
406 $title =~ s/\s*\(.*\)//;
408 warn "$0: no title for $podfile" unless $quiet;
409 $podfile =~ /^(.*)(\.[^.\/]+)?\z/s;
410 $title = ($podfile eq "-" ? 'No Title' : $1);
411 warn "using $title" if $verbose;
413 my $csslink = $css ? qq(\n<LINK REL="stylesheet" HREF="$css" TYPE="text/css">) : '';
414 $csslink =~ s,\\,/,g;
415 $csslink =~ s,(/.):,$1|,;
417 my $block = $header ? <<END_OF_BLOCK : '';
418 <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
419 <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
420 <FONT SIZE=+1><STRONG><P CLASS=block> $title</P></STRONG></FONT>
425 print HTML <<END_OF_HEAD;
428 <TITLE>$title</TITLE>$csslink
435 # load/reload/validate/cache %pages and %items
436 get_cache($dircache, $itemcache, \@podpath, $podroot, $recurse);
438 # scan the pod for =item directives
439 scan_items( \%local_items, "", @poddata);
441 # put an index at the top of the file. note, if $doindex is 0 we
442 # still generate an index, but surround it with an html comment.
443 # that way some other program can extract it if desired.
445 print HTML "<A NAME=\"__index__\"></A>\n";
446 print HTML "<!-- INDEX BEGIN -->\n";
447 print HTML "<!--\n" unless $doindex;
449 print HTML "-->\n" unless $doindex;
450 print HTML "<!-- INDEX END -->\n\n";
451 print HTML "<HR>\n" if $doindex and $index;
453 # now convert this file
454 my $after_item; # set to true after an =item
455 warn "Converting input file $podfile\n" if $verbose;
456 foreach my $i (0..$#poddata){
457 $ptQuote = 0; # status of quote conversion
461 if (/^(=.*)/s) { # is it a pod directive?
465 if (/^=begin\s+(\S+)\s*(.*)/si) {# =begin
466 process_begin($1, $2);
467 } elsif (/^=end\s+(\S+)\s*(.*)/si) {# =end
469 } elsif (/^=cut/) { # =cut
471 } elsif (/^=pod/) { # =pod
474 next if @begin_stack && $begin_stack[-1] ne 'html';
476 if (/^=(head[1-6])\s+(.*\S)/s) { # =head[1-6] heading
477 process_head( $1, $2, $doindex && $index );
478 } elsif (/^=item\s*(.*\S)?/sm) { # =item text
479 warn "$0: $podfile: =item without bullet, number or text"
480 . " in paragraph $paragraph.\n" if !defined($1) or $1 eq '';
483 } elsif (/^=over\s*(.*)/) { # =over N
485 } elsif (/^=back/) { # =back
487 } elsif (/^=for\s+(\S+)\s*(.*)/si) {# =for
491 warn "$0: $podfile: unknown pod directive '$1' in "
492 . "paragraph $paragraph. ignoring.\n";
499 next if @begin_stack && $begin_stack[-1] ne 'html';
500 print HTML and next if @begin_stack && $begin_stack[-1] eq 'html';
502 if( $text =~ /\A\s+/ ){
503 process_pre( \$text );
504 print HTML "<PRE>\n$text</PRE>\n";
507 process_text( \$text );
509 # experimental: check for a paragraph where all lines
510 # have some ...\t...\t...\n pattern
512 my @lines = split( "\n", $text );
515 foreach my $line ( @lines ){
516 if( $line =~ /\S/ && $line !~ /\t/ ){
522 $text =~ s/\t+/<TD>/g;
523 $text =~ s/^/<TR><TD>/gm;
524 $text = '<TABLE CELLSPACING=0 CELLPADDING=0>' .
529 ## end of experimental
532 print HTML "$text\n";
535 print HTML "<P>$text</P>\n";
542 # finish off any pending directives
546 print HTML "<P><A HREF=\"#__index__\"><SMALL>$backlink</SMALL></A></P>\n"
547 if $doindex and $index and $backlink;
549 print HTML <<END_OF_TAIL;
556 # close the html file
559 warn "Finished\n" if $verbose;
562 ##############################################################################
564 my $usage; # see below
567 warn "$0: $podfile: @_\n" if @_;
571 $usage =<<END_OF_USAGE;
572 Usage: $0 --help --htmlroot=<name> --infile=<name> --outfile=<name>
573 --podpath=<name>:...:<name> --podroot=<name>
574 --libpods=<name>:...:<name> --recurse --verbose --index
575 --netscape --norecurse --noindex --cachedir=<name>
577 --backlink - set text for "back to top" links (default: none).
578 --cachedir - directory for the item and directory cache files.
579 --css - stylesheet URL
580 --flush - flushes the item and directory caches.
581 --[no]header - produce block header/footer (default is no headers).
582 --help - prints this message.
583 --htmldir - directory for resulting HTML files.
584 --htmlroot - http-server base directory from which all relative paths
585 in podpath stem (default is /).
586 --[no]index - generate an index at the top of the resulting html
588 --infile - filename for the pod to convert (input taken from stdin
590 --libpods - colon-separated list of pages to search for =item pod
591 directives in as targets of C<> and implicit links (empty
592 by default). note, these are not filenames, but rather
593 page names like those that appear in L<> links.
594 --[no]netscape - will use netscape html directives when applicable.
595 (default is not to use them).
596 --outfile - filename for the resulting html file (output sent to
598 --podpath - colon-separated list of directories containing library
599 pods (empty by default).
600 --podroot - filesystem base directory from which all relative paths
601 in podpath stem (default is .).
602 --[no]quiet - supress some benign warning messages (default is off).
603 --[no]recurse - recurse on those subdirectories listed in podpath
605 --title - title that will appear in resulting html file.
606 --[no]verbose - self-explanatory (off by default).
610 sub parse_command_line {
611 my ($opt_backlink,$opt_cachedir,$opt_css,$opt_flush,$opt_header,$opt_help,
612 $opt_htmldir,$opt_htmlroot,$opt_index,$opt_infile,$opt_libpods,
613 $opt_netscape,$opt_outfile,$opt_podpath,$opt_podroot,$opt_quiet,
614 $opt_recurse,$opt_title,$opt_verbose);
616 unshift @ARGV, split ' ', $Config{pod2html} if $Config{pod2html};
617 my $result = GetOptions(
618 'backlink=s' => \$opt_backlink,
619 'cachedir=s' => \$opt_cachedir,
620 'css=s' => \$opt_css,
621 'flush' => \$opt_flush,
622 'header!' => \$opt_header,
623 'help' => \$opt_help,
624 'htmldir=s' => \$opt_htmldir,
625 'htmlroot=s' => \$opt_htmlroot,
626 'index!' => \$opt_index,
627 'infile=s' => \$opt_infile,
628 'libpods=s' => \$opt_libpods,
629 'netscape!' => \$opt_netscape,
630 'outfile=s' => \$opt_outfile,
631 'podpath=s' => \$opt_podpath,
632 'podroot=s' => \$opt_podroot,
633 'quiet!' => \$opt_quiet,
634 'recurse!' => \$opt_recurse,
635 'title=s' => \$opt_title,
636 'verbose!' => \$opt_verbose,
638 usage("-", "invalid parameters") if not $result;
640 usage("-") if defined $opt_help; # see if the user asked for help
641 $opt_help = ""; # just to make -w shut-up.
643 @podpath = split(":", $opt_podpath) if defined $opt_podpath;
644 @libpods = split(":", $opt_libpods) if defined $opt_libpods;
646 $backlink = $opt_backlink if defined $opt_backlink;
647 $cachedir = $opt_cachedir if defined $opt_cachedir;
648 $css = $opt_css if defined $opt_css;
649 $header = $opt_header if defined $opt_header;
650 $htmldir = $opt_htmldir if defined $opt_htmldir;
651 $htmlroot = $opt_htmlroot if defined $opt_htmlroot;
652 $doindex = $opt_index if defined $opt_index;
653 $podfile = $opt_infile if defined $opt_infile;
654 $netscape = $opt_netscape if defined $opt_netscape;
655 $htmlfile = $opt_outfile if defined $opt_outfile;
656 $podroot = $opt_podroot if defined $opt_podroot;
657 $quiet = $opt_quiet if defined $opt_quiet;
658 $recurse = $opt_recurse if defined $opt_recurse;
659 $title = $opt_title if defined $opt_title;
660 $verbose = $opt_verbose if defined $opt_verbose;
662 warn "Flushing item and directory caches\n"
663 if $opt_verbose && defined $opt_flush;
664 $dircache = "$cachedir/pod2htmd$cache_ext";
665 $itemcache = "$cachedir/pod2htmi$cache_ext";
666 unlink($dircache, $itemcache) if defined $opt_flush;
673 my($dircache, $itemcache, $podpath, $podroot, $recurse) = @_;
674 my @cache_key_args = @_;
676 # A first-level cache:
677 # Don't bother reading the cache files if they still apply
678 # and haven't changed since we last read them.
680 my $this_cache_key = cache_key(@cache_key_args);
682 return if $saved_cache_key and $this_cache_key eq $saved_cache_key;
684 # load the cache of %pages and %items if possible. $tests will be
685 # non-zero if successful.
687 if (-f $dircache && -f $itemcache) {
688 warn "scanning for item cache\n" if $verbose;
689 $tests = load_cache($dircache, $itemcache, $podpath, $podroot);
692 # if we didn't succeed in loading the cache then we must (re)build
695 warn "scanning directories in pod-path\n" if $verbose;
696 scan_podpath($podroot, $recurse, 0);
698 $saved_cache_key = cache_key(@cache_key_args);
702 my($dircache, $itemcache, $podpath, $podroot, $recurse) = @_;
703 return join('!', $dircache, $itemcache, $recurse,
704 @$podpath, $podroot, stat($dircache), stat($itemcache));
708 # load_cache - tries to find if the caches stored in $dircache and $itemcache
709 # are valid caches of %pages and %items. if they are valid then it loads
710 # them and returns a non-zero value.
713 my($dircache, $itemcache, $podpath, $podroot) = @_;
719 open(CACHE, "<$itemcache") ||
720 die "$0: error opening $itemcache for reading: $!\n";
723 # is it the same podpath?
726 $tests++ if (join(":", @$podpath) eq $_);
728 # is it the same podroot?
731 $tests++ if ($podroot eq $_);
733 # load the cache if its good
739 warn "loading item cache\n" if $verbose;
746 warn "scanning for directory cache\n" if $verbose;
747 open(CACHE, "<$dircache") ||
748 die "$0: error opening $dircache for reading: $!\n";
752 # is it the same podpath?
755 $tests++ if (join(":", @$podpath) eq $_);
757 # is it the same podroot?
760 $tests++ if ($podroot eq $_);
762 # load the cache if its good
768 warn "loading directory cache\n" if $verbose;
780 # scan_podpath - scans the directories specified in @podpath for directories,
781 # .pod files, and .pm files. it also scans the pod files specified in
782 # @libpods for =item directives.
785 my($podroot, $recurse, $append) = @_;
787 my($libpod, $dirname, $pod, @files, @poddata);
794 # scan each directory listed in @podpath
797 || die "$0: error changing to directory $podroot: $!\n";
798 foreach $dir (@podpath) {
799 scan_dir($dir, $recurse);
802 # scan the pods listed in @libpods for =item directives
803 foreach $libpod (@libpods) {
804 # if the page isn't defined then we won't know where to find it
806 next unless defined $pages{$libpod} && $pages{$libpod};
808 # if there is a directory then use the .pod and .pm files within it.
809 # NOTE: Only finds the first so-named directory in the tree.
810 # if ($pages{$libpod} =~ /([^:]*[^(\.pod|\.pm)]):/) {
811 if ($pages{$libpod} =~ /([^:]*(?<!\.pod)(?<!\.pm)):/) {
812 # find all the .pod and .pm files within the directory
814 opendir(DIR, $dirname) ||
815 die "$0: error opening directory $dirname: $!\n";
816 @files = grep(/(\.pod|\.pm)\z/ && ! -d $_, readdir(DIR));
819 # scan each .pod and .pm file for =item directives
820 foreach $pod (@files) {
821 open(POD, "<$dirname/$pod") ||
822 die "$0: error opening $dirname/$pod for input: $!\n";
825 clean_data( \@poddata );
827 scan_items( \%items, "$dirname/$pod", @poddata);
830 # use the names of files as =item directives too.
831 ### Don't think this should be done this way - confuses issues.(WL)
832 ### foreach $pod (@files) {
833 ### $pod =~ /^(.*)(\.pod|\.pm)$/;
834 ### $items{$1} = "$dirname/$1.html" if $1;
836 } elsif ($pages{$libpod} =~ /([^:]*\.pod):/ ||
837 $pages{$libpod} =~ /([^:]*\.pm):/) {
838 # scan the .pod or .pm file for =item directives
840 open(POD, "<$pod") ||
841 die "$0: error opening $pod for input: $!\n";
844 clean_data( \@poddata );
846 scan_items( \%items, "$pod", @poddata);
848 warn "$0: shouldn't be here (line ".__LINE__."\n";
851 @poddata = (); # clean-up a bit
854 || die "$0: error changing to directory $pwd: $!\n";
856 # cache the item list for later use
857 warn "caching items for later use\n" if $verbose;
858 open(CACHE, ">$itemcache") ||
859 die "$0: error open $itemcache for writing: $!\n";
861 print CACHE join(":", @podpath) . "\n$podroot\n";
862 foreach my $key (keys %items) {
863 print CACHE "$key $items{$key}\n";
868 # cache the directory list for later use
869 warn "caching directories for later use\n" if $verbose;
870 open(CACHE, ">$dircache") ||
871 die "$0: error open $dircache for writing: $!\n";
873 print CACHE join(":", @podpath) . "\n$podroot\n";
874 foreach my $key (keys %pages) {
875 print CACHE "$key $pages{$key}\n";
882 # scan_dir - scans the directory specified in $dir for subdirectories, .pod
883 # files, and .pm files. notes those that it finds. this information will
884 # be used later in order to figure out where the pages specified in L<>
885 # links are on the filesystem.
888 my($dir, $recurse) = @_;
889 my($t, @subdirs, @pods, $pod, $dirname, @dirs);
895 opendir(DIR, $dir) ||
896 die "$0: error opening directory $dir: $!\n";
897 while (defined($_ = readdir(DIR))) {
898 if (-d "$dir/$_" && $_ ne "." && $_ ne "..") { # directory
899 $pages{$_} = "" unless defined $pages{$_};
900 $pages{$_} .= "$dir/$_:";
902 } elsif (/\.pod\z/) { # .pod
904 $pages{$_} = "" unless defined $pages{$_};
905 $pages{$_} .= "$dir/$_.pod:";
906 push(@pods, "$dir/$_.pod");
907 } elsif (/\.html\z/) { # .html
909 $pages{$_} = "" unless defined $pages{$_};
910 $pages{$_} .= "$dir/$_.pod:";
911 } elsif (/\.pm\z/) { # .pm
913 $pages{$_} = "" unless defined $pages{$_};
914 $pages{$_} .= "$dir/$_.pm:";
915 push(@pods, "$dir/$_.pm");
920 # recurse on the subdirectories if necessary
922 foreach my $subdir (@subdirs) {
923 scan_dir("$dir/$subdir", $recurse);
929 # scan_headings - scan a pod file for head[1-6] tags, note the tags, and
933 my($sections, @data) = @_;
934 my($tag, $which_head, $otitle, $listdepth, $index);
936 # here we need local $ignore = 0;
937 # unfortunately, we can't have it, because $ignore is lexical
943 # scan for =head directives, note their name, and build an index
944 # pointing to each of them.
945 foreach my $line (@data) {
946 if ($line =~ /^=(head)([1-6])\s+(.*)/) {
947 ($tag, $which_head, $otitle) = ($1,$2,$3);
949 my $title = depod( $otitle );
950 my $name = htmlify( $title );
951 $$sections{$name} = 1;
952 $title = process_text( \$otitle );
954 while ($which_head != $listdepth) {
955 if ($which_head > $listdepth) {
956 $index .= "\n" . ("\t" x $listdepth) . "<UL>\n";
958 } elsif ($which_head < $listdepth) {
960 $index .= "\n" . ("\t" x $listdepth) . "</UL>\n";
964 $index .= "\n" . ("\t" x $listdepth) . "<LI>" .
965 "<A HREF=\"#" . $name . "\">" .
966 $title . "</A></LI>";
970 # finish off the lists
971 while ($listdepth--) {
972 $index .= "\n" . ("\t" x $listdepth) . "</UL>\n";
975 # get rid of bogus lists
976 $index =~ s,\t*<UL>\s*</UL>\n,,g;
978 $ignore = 1; # restore old value;
984 # scan_items - scans the pod specified by $pod for =item directives. we
985 # will use this information later on in resolving C<> links.
988 my( $itemref, $pod, @poddata ) = @_;
993 $pod .= ".html" if $pod;
995 foreach $i (0..$#poddata) {
996 my $txt = depod( $poddata[$i] );
998 # figure out what kind of item it is.
999 # Build string for referencing this item.
1000 if ( $txt =~ /\A=item\s+\*\s*(.*)\Z/s ) { # bullet
1003 } elsif( $txt =~ /\A=item\s+(?>\d+\.?)\s*(.*)\Z/s ) { # numbered list
1005 } elsif( $txt =~ /\A=item\s+(.*)\Z/s ) { # plain item
1010 my $fid = fragment_id( $item );
1011 $$itemref{$fid} = "$pod" if $fid;
1016 # process_head - convert a pod head[1-6] tag and convert it to HTML format.
1019 my($tag, $heading, $hasindex) = @_;
1021 # figure out the level of the =head
1022 $tag =~ /head([1-6])/;
1026 warn "$0: $podfile: unterminated list at =head in paragraph $paragraph. ignoring.\n";
1027 while( $listlevel ){
1033 if( $level == 1 && ! $top ){
1034 print HTML "<A HREF=\"#__index__\"><SMALL>$backlink</SMALL></A>\n"
1035 if $hasindex and $backlink;
1039 my $name = htmlify( depod( $heading ) );
1040 my $convert = process_text( \$heading );
1041 print HTML "<H$level><A NAME=\"$name\">$convert</A></H$level>\n";
1046 # emit_item_tag - print an =item's text
1047 # Note: The global $EmittedItem is used for inhibiting self-references.
1051 sub emit_item_tag($$$){
1052 my( $otext, $text, $compact ) = @_;
1053 my $item = fragment_id( $text );
1055 $EmittedItem = $item;
1056 ### print STDERR "emit_item_tag=$item ($text)\n";
1058 print HTML '<STRONG>';
1059 if ($items_named{$item}++) {
1060 print HTML process_text( \$otext );
1062 my $name = 'item_' . $item;
1063 print HTML qq{<A NAME="$name">}, process_text( \$otext ), '</A>';
1065 print HTML "</STRONG><BR>\n";
1066 undef( $EmittedItem );
1071 if( $items_seen[$listlevel]++ == 0 ){
1072 push( @listend, "</$tag>" );
1073 print HTML "<$tag>\n";
1075 print HTML $tag eq 'DL' ? '<DT>' : '<LI>';
1079 # process_item - convert a pod item tag and convert it to HTML format.
1084 # lots of documents start a list without doing an =over. this is
1085 # bad! but, the proper thing to do seems to be to just assume
1086 # they did do an =over. so warn them once and then continue.
1087 if( $listlevel == 0 ){
1088 warn "$0: $podfile: unexpected =item directive in paragraph $paragraph. ignoring.\n";
1092 # formatting: insert a paragraph if preceding item has >1 paragraph
1094 print HTML "<P></P>\n";
1098 # remove formatting instructions from the text
1099 my $text = depod( $otext );
1101 # all the list variants:
1102 if( $text =~ /\A\*/ ){ # bullet
1104 if ($text =~ /\A\*\s+(.+)\Z/s ) { # with additional text
1106 $otext =~ s/\A\*\s+//;
1107 emit_item_tag( $otext, $tag, 1 );
1110 } elsif( $text =~ /\A\d+/ ){ # numbered list
1112 if ($text =~ /\A(?>\d+\.?)\s*(.+)\Z/s ) { # with additional text
1114 $otext =~ s/\A\d+\.?\s*//;
1115 emit_item_tag( $otext, $tag, 1 );
1118 } else { # definition list
1120 if ($text =~ /\A(.+)\Z/s ){ # should have text
1121 emit_item_tag( $otext, $text, 1 );
1129 # process_over - process a pod over tag and start a corresponding HTML list.
1134 push( @items_seen, 0 );
1139 # process_back - process a pod back tag and convert it to HTML format.
1142 if( $listlevel == 0 ){
1143 warn "$0: $podfile: unexpected =back directive in paragraph $paragraph. ignoring.\n";
1147 # close off the list. note, I check to see if $listend[$listlevel] is
1148 # defined because an =item directive may have never appeared and thus
1149 # $listend[$listlevel] may have never been initialized.
1151 if( defined $listend[$listlevel] ){
1152 print HTML '<P></P>' if $after_lpar;
1153 print HTML $listend[$listlevel];
1159 # clean up item count
1164 # process_cut - process a pod cut tag, thus start ignoring pod directives.
1171 # process_pod - process a pod tag, thus stop ignoring pod directives
1172 # until we see a corresponding cut.
1175 # no need to set $ignore to 0 cause the main loop did it
1179 # process_for - process a =for pod tag. if it's for html, spit
1180 # it out verbatim, if illustration, center it, otherwise ignore it.
1183 my($whom, $text) = @_;
1184 if ( $whom =~ /^(pod2)?html$/i) {
1186 } elsif ($whom =~ /^illustration$/i) {
1187 1 while chomp $text;
1188 for my $ext (qw[.png .gif .jpeg .jpg .tga .pcl .bmp]) {
1189 $text .= $ext, last if -r "$text$ext";
1191 print HTML qq{<p align = "center"><img src = "$text" alt = "$text illustration"></p>};
1196 # process_begin - process a =begin pod tag. this pushes
1197 # whom we're beginning on the begin stack. if there's a
1198 # begin stack, we only print if it us.
1201 my($whom, $text) = @_;
1203 push (@begin_stack, $whom);
1204 if ( $whom =~ /^(pod2)?html$/) {
1205 print HTML $text if $text;
1210 # process_end - process a =end pod tag. pop the
1211 # begin stack. die if we're mismatched.
1214 my($whom, $text) = @_;
1216 if ($begin_stack[-1] ne $whom ) {
1217 die "Unmatched begin/end at chunk $paragraph\n"
1219 pop( @begin_stack );
1223 # process_pre - indented paragraph, made into <PRE></PRE>
1232 # insert spaces in place of tabs
1235 1 while $line =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e;
1239 # convert some special chars to HTML escapes
1240 $rest =~ s/&/&/g;
1241 $rest =~ s/</</g;
1242 $rest =~ s/>/>/g;
1243 $rest =~ s/"/"/g;
1245 # try and create links for all occurrences of perl.* within
1246 # the preformatted text.
1250 if ( defined $pages{$2} ){ # is a link
1251 qq($1<A HREF="$htmlroot/$pages{$2}">$2</A>);
1252 } elsif (defined $pages{dosify($2)}) { # is a link
1253 qq($1<A HREF="$htmlroot/$pages{dosify($2)}">$2</A>);
1259 (<A\ HREF="?) ([^>:]*:)? ([^>:]*) \.pod: ([^>:]*:)?
1262 if ( $htmlfileurl ne '' ){
1263 # Here, we take advantage of the knowledge
1264 # that $htmlfileurl ne '' implies $htmlroot eq ''.
1265 # Since $htmlroot eq '', we need to prepend $htmldir
1266 # on the fron of the link to get the absolute path
1267 # of the link's target. We check for a leading '/'
1268 # to avoid corrupting links that are #, file:, etc.
1270 $old_url = "$htmldir$old_url" if $old_url =~ m{^\/};
1271 $url = relativize_url( "$old_url.html", $htmlfileurl );
1278 # Look for embedded URLs and make them into links. We don't
1279 # relativize them since they are best left as the author intended.
1281 my $urls = '(' . join ('|', qw{
1294 my $gunk = '/#~:.?+=&%@!\-';
1296 my $any = "${ltrs}${gunk}${punc}";
1299 \b # start at word boundary
1301 $urls : # need resource and a colon
1302 (?!:) # Ignore File::, among others.
1303 [$any] +? # followed by on or more
1304 # of any valid character, but
1305 # be conservative and take only
1306 # what you need to....
1308 (?= # look-ahead non-consumptive assertion
1309 [$punc]* # either 0 or more puntuation
1310 [^$any] # followed by a non-url char
1312 $ # then end of the string
1314 }{<A HREF="$1">$1</A>}igox;
1316 # text should be as it is (verbatim)
1322 # pure text processing
1324 # pure_text/inIS_text: differ with respect to automatic C<> recognition.
1325 # we don't want this to happen within IS
1329 process_puretext( $text, \$ptQuote, 1 );
1334 process_puretext( $text, \$ptQuote, 0 );
1338 # process_puretext - process pure text (without pod-escapes) converting
1339 # double-quotes and handling implicit C<> links.
1341 sub process_puretext {
1342 my($text, $quote, $notinIS) = @_;
1344 ## Guessing at func() or [$@%&]*var references in plain text is destined
1345 ## to produce some strange looking ref's. uncomment to disable:
1348 my(@words, $lead, $trail);
1350 # convert double-quotes to single-quotes
1351 if( $$quote && $text =~ s/"/''/s ){
1354 while ($text =~ s/"([^"]*)"/``$1''/sg) {};
1355 $$quote = 1 if $text =~ s/"/``/s;
1357 # keep track of leading and trailing white-space
1358 $lead = ($text =~ s/\A(\s+)//s ? $1 : "");
1359 $trail = ($text =~ s/(\s+)\Z//s ? $1 : "");
1361 # split at space/non-space boundaries
1362 @words = split( /(?<=\s)(?=\S)|(?<=\S)(?=\s)/, $text );
1364 # process each word individually
1365 foreach my $word (@words) {
1367 next if $word =~ /^\s*$/;
1368 # see if we can infer a link
1369 if( $notinIS && $word =~ /^(\w+)\((.*)\)$/ ) {
1370 # has parenthesis so should have been a C<> ref
1371 ## try for a pagename (perlXXX(1))?
1372 my( $func, $args ) = ( $1, $2 );
1373 if( $args =~ /^\d+$/ ){
1374 my $url = page_sect( $word, '' );
1376 $word = "<A HREF=\"$url\">the $word manpage</A>";
1380 ## try function name for a link, append tt'ed argument list
1381 $word = emit_C( $func, '', "($args)");
1383 #### disabled. either all (including $\W, $\w+{.*} etc.) or nothing.
1384 ## } elsif( $notinIS && $word =~ /^[\$\@%&*]+\w+$/) {
1385 ## # perl variables, should be a C<> ref
1386 ## $word = emit_C( $word );
1388 } elsif ($word =~ m,^\w+://\w,) {
1390 # Don't relativize it: leave it as the author intended
1391 $word = qq(<A HREF="$word">$word</A>);
1392 } elsif ($word =~ /[\w.-]+\@[\w-]+\.\w/) {
1393 # looks like an e-mail address
1394 my ($w1, $w2, $w3) = ("", $word, "");
1395 ($w1, $w2, $w3) = ("(", $1, ")$2") if $word =~ /^\((.*?)\)(,?)/;
1396 ($w1, $w2, $w3) = ("<", $1, ">$2") if $word =~ /^<(.*?)>(,?)/;
1397 $word = qq($w1<A HREF="mailto:$w2">$w2</A>$w3);
1398 } elsif ($word !~ /[a-z]/ && $word =~ /[A-Z]/) { # all uppercase?
1399 $word = html_escape($word) if $word =~ /["&<>]/;
1400 $word = "\n<FONT SIZE=-1>$word</FONT>" if $netscape;
1402 $word = html_escape($word) if $word =~ /["&<>]/;
1406 # put everything back together
1407 return $lead . join( '', @words ) . $trail;
1412 # process_text - handles plaintext that appears in the input pod file.
1413 # there may be pod commands embedded within the text so those must be
1414 # converted to html commands.
1417 sub process_text1($$;$$);
1418 sub pattern ($) { $_[0] ? '[^\S\n]+'.('>' x ($_[0] + 1)) : '>' }
1419 sub closing ($) { local($_) = shift; (defined && s/\s+$//) ? length : 0 }
1424 my $res = process_text1( 0, $tref );
1428 sub process_text1($$;$$){
1429 my( $lev, $rstr, $func, $closing ) = @_;
1432 unless (defined $func) {
1438 # B<text> - boldface
1439 $res = '<STRONG>' . process_text1( $lev, $rstr ) . '</STRONG>';
1441 } elsif( $func eq 'C' ){
1442 # C<code> - can be a ref or <CODE></CODE>
1443 # need to extract text
1444 my $par = go_ahead( $rstr, 'C', $closing );
1446 ## clean-up of the link target
1447 my $text = depod( $par );
1449 ### my $x = $par =~ /[BI]</ ? 'yes' : 'no' ;
1450 ### print STDERR "-->call emit_C($par) lev=$lev, par with BI=$x\n";
1452 $res = emit_C( $text, $lev > 1 || ($par =~ /[BI]</) );
1454 } elsif( $func eq 'E' ){
1455 # E<x> - convert to character
1456 $$rstr =~ s/^([^>]*)>//;
1458 $escape =~ s/^(\d+|X[\dA-F]+)$/#$1/i;
1461 } elsif( $func eq 'F' ){
1462 # F<filename> - italizice
1463 $res = '<EM>' . process_text1( $lev, $rstr ) . '</EM>';
1465 } elsif( $func eq 'I' ){
1466 # I<text> - italizice
1467 $res = '<EM>' . process_text1( $lev, $rstr ) . '</EM>';
1469 } elsif( $func eq 'L' ){
1471 ## L<text|cross-ref> => produce text, use cross-ref for linking
1472 ## L<cross-ref> => make text from cross-ref
1473 ## need to extract text
1474 my $par = go_ahead( $rstr, 'L', $closing );
1476 # some L<>'s that shouldn't be:
1477 # a) full-blown URL's are emitted as-is
1478 if( $par =~ m{^\w+://}s ){
1479 return make_URL_href( $par );
1481 # b) C<...> is stripped and treated as C<>
1482 if( $par =~ /^C<(.*)>$/ ){
1483 my $text = depod( $1 );
1484 return emit_C( $text, $lev > 1 || ($par =~ /[BI]</) );
1487 # analyze the contents
1488 $par =~ s/\n/ /g; # undo word-wrapped tags
1491 if( $par =~ s{^([^|]+)\|}{} ){
1495 # make sure sections start with a /
1498 my( $page, $section, $ident );
1500 # check for link patterns
1501 if( $par =~ m{^([^/]+?)/(?!")(.*?)$} ){ # name/ident
1502 # we've got a name/ident (no quotes)
1503 ( $page, $ident ) = ( $1, $2 );
1504 ### print STDERR "--> L<$par> to page $page, ident $ident\n";
1506 } elsif( $par =~ m{^(.*?)/"?(.*?)"?$} ){ # [name]/"section"
1507 # even though this should be a "section", we go for ident first
1508 ( $page, $ident ) = ( $1, $2 );
1509 ### print STDERR "--> L<$par> to page $page, section $section\n";
1511 } elsif( $par =~ /\s/ ){ # this must be a section with missing quotes
1512 ( $page, $section ) = ( '', $par );
1513 ### print STDERR "--> L<$par> to void page, section $section\n";
1516 ( $page, $section ) = ( $par, '' );
1517 ### print STDERR "--> L<$par> to page $par, void section\n";
1520 # now, either $section or $ident is defined. the convoluted logic
1521 # below tries to resolve L<> according to what the user specified.
1522 # failing this, we try to find the next best thing...
1523 my( $url, $ltext, $fid );
1526 if( defined $ident ){
1527 ## try to resolve $ident as an item
1528 ( $url, $fid ) = coderef( $page, $ident );
1530 if( ! defined( $linktext ) ){
1532 $linktext .= " in " if $ident && $page;
1533 $linktext .= "the $page manpage" if $page;
1535 ### print STDERR "got coderef url=$url\n";
1538 ## no luck: go for a section (auto-quoting!)
1541 ## now go for a section
1542 my $htmlsection = htmlify( $section );
1543 $url = page_sect( $page, $htmlsection );
1545 if( ! defined( $linktext ) ){
1546 $linktext = $section;
1547 $linktext .= " in " if $section && $page;
1548 $linktext .= "the $page manpage" if $page;
1550 ### print STDERR "got page/section url=$url\n";
1553 ## no luck: go for an ident
1560 ( $url, $fid ) = coderef( $page, $ident );
1562 if( ! defined( $linktext ) ){
1564 $linktext .= " in " if $ident && $page;
1565 $linktext .= "the $page manpage" if $page;
1567 ### print STDERR "got section=>coderef url=$url\n";
1571 # warning; show some text.
1572 $linktext = $opar unless defined $linktext;
1573 warn "$0: $podfile: cannot resolve L<$opar> in paragraph $paragraph.";
1576 # now we have a URL or just plain code
1577 $$rstr = $linktext . '>' . $$rstr;
1578 if( defined( $url ) ){
1579 $res = "<A HREF=\"$url\">" . process_text1( $lev, $rstr ) . '</A>';
1581 $res = '<EM>' . process_text1( $lev, $rstr ) . '</EM>';
1584 } elsif( $func eq 'S' ){
1585 # S<text> - non-breaking spaces
1586 $res = process_text1( $lev, $rstr );
1587 $res =~ s/ / /g;
1589 } elsif( $func eq 'X' ){
1591 $$rstr =~ s/^[^>]*>//;
1593 } elsif( $func eq 'Z' ){
1595 warn "$0: $podfile: invalid X<> in paragraph $paragraph."
1596 unless $$rstr =~ s/^>//;
1599 my $term = pattern $closing;
1600 while( $$rstr =~ s/\A(.*?)(([BCEFILSXZ])<(<+[^\S\n]+)?|$term)//s ){
1601 # all others: either recurse into new function or
1602 # terminate at closing angle bracket(s)
1604 $pt .= $2 if !$3 && $lev == 1;
1605 $res .= $lev == 1 ? pure_text( $pt ) : inIS_text( $pt );
1606 return $res if !$3 && $lev > 1;
1608 $res .= process_text1( $lev, $rstr, $3, closing $4 );
1612 $res .= pure_text( $$rstr );
1614 warn "$0: $podfile: undelimited $func<> in paragraph $paragraph.";
1621 # go_ahead: extract text of an IS (can be nested)
1624 my( $rstr, $func, $closing ) = @_;
1626 my @closing = ($closing);
1628 s/\A(.*?)(([BCEFILSXZ])<(<+[^\S\n]+)?|@{[pattern $closing[0]]})//s ){
1632 return $res unless @closing;
1634 unshift @closing, closing $4;
1638 warn "$0: $podfile: undelimited $func<> in paragraph $paragraph.";
1643 # emit_C - output result of C<text>
1644 # $text is the depod-ed text
1647 my( $text, $nocode, $args ) = @_;
1648 $args = '' unless defined $args;
1650 my( $url, $fid ) = coderef( undef(), $text );
1652 # need HTML-safe text
1653 my $linktext = html_escape( "$text$args" );
1655 if( defined( $url ) &&
1656 (!defined( $EmittedItem ) || $EmittedItem ne $fid ) ){
1657 $res = "<A HREF=\"$url\"><CODE>$linktext</CODE></A>";
1658 } elsif( 0 && $nocode ){
1661 $res = "<CODE>$linktext</CODE>";
1667 # html_escape: make text safe for HTML
1671 $rest =~ s/&/&/g;
1672 $rest =~ s/</</g;
1673 $rest =~ s/>/>/g;
1674 $rest =~ s/"/"/g;
1680 # dosify - convert filenames to 8.3
1684 return lc($str) if $^O eq 'VMS'; # VMS just needs casing
1687 $str =~ s/(\.\w+)/substr ($1,0,4)/ge;
1688 $str =~ s/(\w+)/substr ($1,0,8)/ge;
1694 # page_sect - make a URL from the text of a L<>
1697 my( $page, $section ) = @_;
1698 my( $linktext, $page83, $link); # work strings
1700 # check if we know that this is a section in this page
1701 if (!defined $pages{$page} && defined $sections{$page}) {
1704 ### print STDERR "reset page='', section=$section\n";
1707 $page83=dosify($page);
1708 $page=$page83 if (defined $pages{$page83});
1710 $link = "#" . htmlify( $section );
1711 } elsif ( $page =~ /::/ ) {
1713 # Search page cache for an entry keyed under the html page name,
1714 # then look to see what directory that page might be in. NOTE:
1715 # this will only find one page. A better solution might be to produce
1716 # an intermediate page that is an index to all such pages.
1717 my $page_name = $page ;
1718 $page_name =~ s,^.*/,,s ;
1719 if ( defined( $pages{ $page_name } ) &&
1720 $pages{ $page_name } =~ /([^:]*$page)\.(?:pod|pm):/
1725 # NOTE: This branch assumes that all A::B pages are located in
1726 # $htmlroot/A/B.html . This is often incorrect, since they are
1727 # often in $htmlroot/lib/A/B.html or such like. Perhaps we could
1728 # analyze the contents of %pages and figure out where any
1729 # cousins of A::B are, then assume that. So, if A::B isn't found,
1730 # but A::C is found in lib/A/C.pm, then A::B is assumed to be in
1731 # lib/A/B.pm. This is also limited, but it's an improvement.
1732 # Maybe a hints file so that the links point to the correct places
1736 $link = "$htmlroot/$page.html";
1737 $link .= "#" . htmlify( $section ) if ($section);
1738 } elsif (!defined $pages{$page}) {
1741 $section = htmlify( $section ) if $section ne "";
1742 ### print STDERR "...section=$section\n";
1744 # if there is a directory by the name of the page, then assume that an
1745 # appropriate section will exist in the subdirectory
1746 # if ($section ne "" && $pages{$page} =~ /([^:]*[^(\.pod|\.pm)]):/) {
1747 if ($section ne "" && $pages{$page} =~ /([^:]*(?<!\.pod)(?<!\.pm)):/) {
1748 $link = "$htmlroot/$1/$section.html";
1749 ### print STDERR "...link=$link\n";
1751 # since there is no directory by the name of the page, the section will
1752 # have to exist within a .html of the same name. thus, make sure there
1753 # is a .pod or .pm that might become that .html
1755 $section = "#$section" if $section;
1756 ### print STDERR "...section=$section\n";
1758 # check if there is a .pod with the page name
1759 if ($pages{$page} =~ /([^:]*)\.pod:/) {
1760 $link = "$htmlroot/$1.html$section";
1761 } elsif ($pages{$page} =~ /([^:]*)\.pm:/) {
1762 $link = "$htmlroot/$1.html$section";
1770 # Here, we take advantage of the knowledge that $htmlfileurl ne ''
1771 # implies $htmlroot eq ''. This means that the link in question
1772 # needs a prefix of $htmldir if it begins with '/'. The test for
1773 # the initial '/' is done to avoid '#'-only links, and to allow
1774 # for other kinds of links, like file:, ftp:, etc.
1776 if ( $htmlfileurl ne '' ) {
1777 $link = "$htmldir$link" if $link =~ m{^/}s;
1778 $url = relativize_url( $link, $htmlfileurl );
1779 # print( " b: [$link,$htmlfileurl,$url]\n" );
1792 # relativize_url - convert an absolute URL to one relative to a base URL.
1793 # Assumes both end in a filename.
1795 sub relativize_url {
1796 my ($dest,$source) = @_ ;
1798 my ($dest_volume,$dest_directory,$dest_file) =
1799 File::Spec::Unix->splitpath( $dest ) ;
1800 $dest = File::Spec::Unix->catpath( $dest_volume, $dest_directory, '' ) ;
1802 my ($source_volume,$source_directory,$source_file) =
1803 File::Spec::Unix->splitpath( $source ) ;
1804 $source = File::Spec::Unix->catpath( $source_volume, $source_directory, '' ) ;
1807 if ( $dest ne '' ) {
1808 $rel_path = File::Spec::Unix->abs2rel( $dest, $source ) ;
1811 if ( $rel_path ne '' &&
1812 substr( $rel_path, -1 ) ne '/' &&
1813 substr( $dest_file, 0, 1 ) ne '#'
1815 $rel_path .= "/$dest_file" ;
1818 $rel_path .= "$dest_file" ;
1826 # coderef - make URL from the text of a C<>
1829 my( $page, $item ) = @_;
1832 my $fid = fragment_id( $item );
1833 if( defined( $page ) ){
1834 # we have been given a $page...
1837 # Do we take it? Item could be a section!
1838 my $base = $items{$fid} || "";
1839 $base =~ s{[^/]*/}{};
1840 if( $base ne "$page.html" ){
1841 ### print STDERR "coderef( $page, $item ): items{$fid} = $items{$fid} = $base => discard page!\n";
1846 # no page - local items precede cached items
1847 if( defined( $fid ) ){
1848 if( exists $local_items{$fid} ){
1849 $page = $local_items{$fid};
1851 $page = $items{$fid};
1856 # if there was a pod file that we found earlier with an appropriate
1857 # =item directive, then create a link to that page.
1858 if( defined $page ){
1860 if( exists $pages{$page} and $pages{$page} =~ /([^:.]*)\.[^:]*:/){
1861 $page = $1 . '.html';
1863 my $link = "$htmlroot/$page#item_$fid";
1865 # Here, we take advantage of the knowledge that $htmlfileurl
1866 # ne '' implies $htmlroot eq ''.
1867 if ( $htmlfileurl ne '' ) {
1868 $link = "$htmldir$link" ;
1869 $url = relativize_url( $link, $htmlfileurl ) ;
1874 $url = "#item_" . $fid;
1877 confess "url has space: $url" if $url =~ /"[^"]*\s[^"]*"/;
1879 return( $url, $fid );
1885 # Adapted from Nick Ing-Simmons' PodToHtml package.
1887 my $source_file = shift ;
1888 my $destination_file = shift;
1890 my $source = URI::file->new_abs($source_file);
1891 my $uo = URI::file->new($destination_file,$source)->abs;
1892 return $uo->rel->as_string;
1897 # finish_list - finish off any pending HTML lists. this should be called
1898 # after the entire pod file has been read and converted.
1901 while ($listlevel > 0) {
1902 print HTML "</DL>\n";
1908 # htmlify - converts a pod section specification to a suitable section
1909 # specification for HTML. Note that we keep spaces and special characters
1910 # except ", ? (Netscape problem) and the hyphen (writer's problem...).
1914 $heading =~ s/(\s+)/ /g;
1915 $heading =~ s/\s+\Z//;
1916 $heading =~ s/\A\s+//;
1917 # The hyphen is a disgrace to the English language.
1918 $heading =~ s/[-"?]//g;
1919 $heading = lc( $heading );
1924 # depod - convert text by eliminating all interior sequences
1925 # Note: can be called with copy or modify semantics
1932 $E2c{amp} = '&'; # in Tk's pods
1940 ${$_[0]} = depod1( \$string );
1948 my( $rstr, $func, $closing ) = @_;
1950 return $res unless defined $$rstr;
1951 if( ! defined( $func ) ){
1952 # skip to next begin of an interior sequence
1953 while( $$rstr =~ s/\A(.*?)([BCEFILSXZ])<(<+[^\S\n]+)?// ){
1954 # recurse into its text
1955 $res .= $1 . depod1( $rstr, $2, closing $3);
1958 } elsif( $func eq 'E' ){
1959 # E<x> - convert to character
1960 $$rstr =~ s/^([^>]*)>//;
1961 $res .= $E2c{$1} || "";
1962 } elsif( $func eq 'X' ){
1964 $$rstr =~ s/^[^>]*>//;
1965 } elsif( $func eq 'Z' ){
1969 # all others: either recurse into new function or
1970 # terminate at closing angle bracket
1971 my $term = pattern $closing;
1972 while( $$rstr =~ s/\A(.*?)(([BCEFILSXZ])<(<+[^\S\n]+)?|$term)// ){
1975 $res .= depod1( $rstr, $3, closing $4 );
1977 ## If we're here and $2 ne '>': undelimited interior sequence.
1978 ## Ignored, as this is called without proper indication of where we are.
1979 ## Rely on process_text to produce diagnostics.
1985 # fragment_id - construct a fragment identifier from:
1987 # b) contents of C<...>
1992 $text =~ s/\s+\Z//s;
1994 # a method or function?
1995 return $1 if $text =~ /(\w+)\s*\(/;
1996 return $1 if $text =~ /->\s*(\w+)\s*\(?/;
1999 return $1 if $text =~ /^([$@%*]\S+)/;
2001 # some pattern matching operator?
2002 return $1 if $text =~ m|^(\w+/).*/\w*$|;
2004 # fancy stuff... like "do { }"
2005 return $1 if $text =~ m|^(\w+)\s*{.*}$|;
2007 # honour the perlfunc manpage: func [PAR[,[ ]PAR]...]
2008 # and some funnies with ... Module ...
2009 return $1 if $text =~ m{^([a-z\d]+)(\s+[A-Z\d,/& ]+)?$};
2010 return $1 if $text =~ m{^([a-z\d]+)\s+Module(\s+[A-Z\d,/& ]+)?$};
2013 $text =~ s/\s+/_/sg;
2015 defined( $hc[ord($1)] ) ? $hc[ord($1)]
2016 : ( $hc[ord($1)] = sprintf( "%%%02X", ord($1) ) ) }gxe;
2017 $text = substr( $text, 0, 50 );
2024 # make_URL_href - generate HTML href from URL
2025 # Special treatment for CGI queries.
2027 sub make_URL_href($){
2030 s{^(http:[-\w/#~:.+=&%@!]+)(\?.*)$}{<A HREF="$1$2">$1</A>}i ){
2031 $url = "<A HREF=\"$url\">$url</A>";