3 eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
4 if 0; # not running under some shell
14 my %opt = (index => 1, toplink => 'Top');
15 GetOptions(\%opt, qw(css=s toplink|backlink=s help index! infile:s outfile:s existing! frames:s))
17 pod2usage(-verbose => 2) if $opt{help};
19 my ($in,$out) = @ARGV;
21 pod2usage() unless ($in && $out);
23 my $toplink = $opt{toplink} ?
24 sprintf '<p><a href="#TOP" class="toplink">%s</a></p>', $opt{toplink} : '';
26 $opt{css} ||= 'pod.css';
28 my $link_parser = new LinkResolver( $opt{css} );
29 my $parser = new Pod::Xhtml(StringMode => 1, LinkParser => $link_parser);
31 my $parser = new Pod::Xhtml(
32 MakeIndex => $opt{index},
34 LinkParser => $link_parser,
37 $parser->addHeadText(qq[<link rel="stylesheet" href="$opt{css}"/>]);
42 # collect existing files
45 return unless (-f && -s && m/.html*$/i);
49 }, $out) if ($opt{existing});
51 # find all files to convert to pod
54 return unless (-f && -s && m/\.(pl|pm|pod)$/i);
59 # strip all up to filename
60 # $out_html =~ s#^.*/([^/]+)$#$1#;
63 $out_html =~ s#.*$in/*##;
64 $out_html =~ s#/+#-#g;
67 $out_html =~ s#\.(pl|pm|pod)$#.html#;
69 $out_html = $out . '/' . $out_html;
71 print "$in_pod -> $out_html\n";
73 $parser->parse_from_file($in_pod, $out_html);
76 push @navigation, $nav;
81 my $css_file = $out . '/' . $opt{css};
83 open(my $css, '>', $css_file) || die "can't open $css_file: $!";
90 exit unless ($opt{frames});
92 # dump navigation html
97 <link rel="stylesheet" href="pod.css"/>
105 foreach my $f (sort @navigation) {
114 warn "+nav $f -> $text\n";
116 $nav .= qq{ <br/><a href="${f}.html" target="pod">$text</a>\n};
124 write_file( "$out/toc.html", $nav );
129 <title>$opt{frames}</title>
131 <FRAMESET COLS="*, 250">
132 <FRAME src="./${first}.html" name="pod">
133 <FRAME src="./toc.html" name="toc">
135 <a style="display: none" href="./toc.html">Table of Contents</a>
141 write_file( "$out/index.html", $frameset );
144 # Subclass Pod::Hyperlink to create self-referring links
147 package LinkResolver;
149 use base qw(Pod::Hyperlink);
155 my $self = $class->SUPER::new();
163 if($self->SUPER::type() eq 'page')
165 my $url = $self->SUPER::page();
170 $self->SUPER::node(@_);
176 return $self->SUPER::page() if($self->SUPER::type() eq 'page');
177 $self->SUPER::text(@_);
183 return "hyperlink" if($self->SUPER::type() eq 'page');
184 $self->SUPER::type(@_);
195 allpod2xhtml - convert .pod files to .xhtml files
199 allpod2xhtml [--help] [OPTIONS] source_dir dest_dir
203 Converts files from pod format (see L<perlpod>) to XHTML format.
213 =item --infile FILENAME
215 the input filename. STDIN is used otherwise
217 =item --outfile FILENAME
219 the output filename. STDOUT is used otherwise
225 =item --index/--noindex
227 generate an index, or not. The default is to create an index.
229 =item --toplink LINK TEXT
231 set text for "back to top" links. The default is 'Top'.
233 =item --frames TITLE OF FRAMESET
235 create C<index.html> and C<toc.html> with frameset for all converted douments
239 include existing html files in C<dest_dir> in navigation
245 See L<Pod::Xhtml> for a list of known bugs in the translator.
249 P Kent E<lt>cpan _at_ bbc _dot_ co _dot_ ukE<gt>
251 Dobrica Pavlinusic C<< <dpavlin@rot13.org> >>
255 (c) BBC 2004. This program is free software; you can redistribute it and/or
256 modify it under the GNU GPL.
258 See the file COPYING in this distribution, or http://www.gnu.org/licenses/gpl.txt
262 L<perlpod>, L<Pod::Xhtml>
269 font-family: arial,sans-serif;
275 border-collapse: collapse;
283 input { margin: 2px; }
286 background: transparent;
290 A[href="#POD_ERRORS"] {
291 background: transparent;
315 TH A:link, TH A:visited {
316 background: transparent;
322 border: 1px solid #888888;
330 background: transparent;
336 background: transparent;
346 text-decoration: none;
351 list-style-type: none;