From Code to Community: Sponsoring The Perl and Raku Conference 2025 Learn more

#! /usr/local/bin/perl -ws
use strict;
use Carp;
our $toc; # was the -toc flag specified on the command-line?
my $source_file = $ARGV[0] || \*STDIN;
# Add in this CSS so that tables look nicer...
my $CSS = <<'END_CSS';
th, td { padding-right: 2em; }
th p { margin: 3pt;
text-align: left;
border-bottom: thin solid;
}
td p { margin: 3pt; }
END_CSS
# Handle -toc requests by prepending a =TOC section with a P<toc:...> link
if ($toc) {
if (!ref $source_file) {
my $filename = $source_file;
undef $source_file;
open $source_file, '<', $filename
or croak "Couldn't open file '$filename': $!";
}
my $source = "=TOC\nP<toc:head1 head2 head3>\n\n"
. do { local $/; <$source_file> };
$source_file = \$source;
}
print Perl6::Perldoc::Parser->parse( $source_file, {all_pod=>'auto'} )
->report_errors()
->to_xhtml({ full_doc => { style=>$CSS } });
__END__
=head1 NAME
perldoc2xhtml - Convert Perldoc markup to XHTML
=head1 VERSION
This documentation refers to perldoc2xhtml version 0.0.1
This version is still a prototype.
=head1 USAGE
perldoc2xhtml [-toc] [filename]
=head1 REQUIRED ARGUMENTS
None.
=head1 OPTIONS
May be given a single argument specifying the name of the file to convert.
If filename not given, input is read from STDIN.
May also be given a C<-toc> flag to autgenerate a table-of-contents at
the start of the document.
=head1 DESCRIPTION
This utility converts documentation in the Perl 6 "Perldoc" notation to
XHTML. The XHTML is always written to STDOUT.
=head1 DIAGNOSTICS
See the documentation for Perl6::Perldoc::Parser
=head1 CONFIGURATION AND ENVIRONMENT
Requires no configuration files or environment variables.
=head1 DEPENDENCIES
Perl6::Perldoc::Parser
=head1 BUGS
None reported.
Bug reports and other feedback are most welcome.
=head1 AUTHOR
Damian Conway C<< DCONWAY@cpan.org >>
=head1 COPYRIGHT
Copyright (c) 2007, Damian Conway C<< <DCONWAY@cpan.org> >>. All rights reserved.
This module is free software. It may be used, redistributed
and/or modified under the terms of the Perl Artistic License
=head1 DISCLAIMER OF WARRANTY
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.