require 5;
package Pod::Simple::HTML;
use strict;
use Pod::Simple::PullParser ();
use vars qw(
@ISA %Tagmap $Computerese $LamePad $Linearization_Limit $VERSION
$Perldoc_URL_Prefix $Perldoc_URL_Postfix $Man_URL_Prefix $Man_URL_Postfix
$Title_Prefix $Title_Postfix $HTML_EXTENSION %ToIndex
$Doctype_decl $Content_decl
);
@ISA = ('Pod::Simple::PullParser');
$VERSION = '3.40';
BEGIN {
if(defined &DEBUG) { } # no-op
elsif( defined &Pod::Simple::DEBUG ) { *DEBUG = \&Pod::Simple::DEBUG }
else { *DEBUG = sub () {0}; }
}
$Doctype_decl ||= ''; # No. Just No. Don't even ask me for it.
# qq{\n};
$Content_decl ||=
q{};
$HTML_EXTENSION = '.html' unless defined $HTML_EXTENSION;
$Computerese = "" unless defined $Computerese;
$LamePad = '' unless defined $LamePad;
$Linearization_Limit = 120 unless defined $Linearization_Limit;
# headings/items longer than that won't get an
$Perldoc_URL_Prefix = 'https://metacpan.org/pod/'
unless defined $Perldoc_URL_Prefix;
$Perldoc_URL_Postfix = ''
unless defined $Perldoc_URL_Postfix;
$Man_URL_Prefix = 'http://man.he.net/man';
$Man_URL_Postfix = '';
$Title_Prefix = '' unless defined $Title_Prefix;
$Title_Postfix = '' unless defined $Title_Postfix;
%ToIndex = map {; $_ => 1 } qw(head1 head2 head3 head4 ); # item-text
# 'item-text' stuff in the index doesn't quite work, and may
# not be a good idea anyhow.
__PACKAGE__->_accessorize(
'perldoc_url_prefix',
# In turning L",
'/Verbatim' => "
\n",
'VerbatimFormatted' => "\n",
'/VerbatimFormatted' => "
\n",
'VerbatimB' => "",
'/VerbatimB' => "",
'VerbatimI' => "",
'/VerbatimI' => "",
'VerbatimBI' => "",
'/VerbatimBI' => "",
'Data' => "\n",
'/Data' => "\n",
'head1' => "\n", # And also stick in an
'head2' => "\n
\n",
'/head2' => "", # ''
'head3' => "\n
", # ''
'head4' => "\n
", # ''
'/head1' => "
...
, I think
),
'/item-bullet' => "$LamePad\n",
'/item-number' => "$LamePad\n",
'/item-text' => "$LamePad\n",
'item-body' => "\n
", '/C' => "",
'L' => "", # ideally never used!
'/L' => "",
);
sub changes {
return map {; m/^([-_:0-9a-zA-Z]+)=([-_:0-9a-zA-Z]+)$/s
? ( $1, => "\n<$2>", "/$1", => "$2>\n" ) : die "Funky $_"
} @_;
}
sub changes2 {
return map {; m/^([-_:0-9a-zA-Z]+)=([-_:0-9a-zA-Z]+)$/s
? ( $1, => "<$2>", "/$1", => "$2>" ) : die "Funky $_"
} @_;
}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sub go { Pod::Simple::HTML->parse_from_file(@ARGV); exit 0 }
# Just so we can run from the command line. No options.
# For that, use perldoc!
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sub new {
my $new = shift->SUPER::new(@_);
#$new->nix_X_codes(1);
$new->nbsp_for_S(1);
$new->accept_targets( 'html', 'HTML' );
$new->accept_codes('VerbatimFormatted');
$new->accept_codes(@_to_accept);
DEBUG > 2 and print STDERR "To accept: ", join(' ',@_to_accept), "\n";
$new->perldoc_url_prefix( $Perldoc_URL_Prefix );
$new->perldoc_url_postfix( $Perldoc_URL_Postfix );
$new->man_url_prefix( $Man_URL_Prefix );
$new->man_url_postfix( $Man_URL_Postfix );
$new->title_prefix( $Title_Prefix );
$new->title_postfix( $Title_Postfix );
$new->html_header_before_title(
qq[$Doctype_decl " opening tag including the Document type and including the opening , Verbatim text maps to (Computerese defaults to "")
$Pod::Simple::HTML::Computerese = ' class="some_class_name';
=head2 html_css
=head2 html_javascript
=head2 title_prefix
=head2 title_postfix
=head2 html_header_before_title
This includes everything before the opening tag including the Document type
and including the opening tag. The following call will set it to be a simple HTML
file:
$p->html_header_before_title('');
=head2 top_anchor
By default Pod::Simple::HTML adds a dummy anchor at the top of the HTML.
You can change it by calling
$p->top_anchor('');
=head2 html_h_level
Normally =head1 will become , =head2 will become etc.
Using the html_h_level method will change these levels setting the h level
of =head1 tags:
$p->html_h_level(3);
Will make sure that =head1 will become and =head2 will become etc...
=head2 index
Set it to some true value if you want to have an index (in reality a table of contents)
to be added at the top of the generated HTML.
$p->index(1);
=head2 html_header_after_title
Includes the closing tag of
and through the rest of the head
till the opening of the body
$p->html_header_after_title(' ... ');
=head2 html_footer
The very end of the document:
$p->html_footer( qq[\n\n\n\n] );
=head1 SUBCLASSING
Can use any of the methods described above but for further customization
one needs to override some of the methods:
package My::Pod;
use strict;
use warnings;
use base 'Pod::Simple::HTML';
# needs to return a URL string such
# http://some.other.com/page.html
# #anchor_in_the_same_file
# /internal/ref.html
sub do_pod_link {
# My::Pod object and Pod::Simple::PullParserStartToken object
my ($self, $link) = @_;
say $link->tagname; # will be L for links
say $link->attr('to'); #
say $link->attr('type'); # will be 'pod' always
say $link->attr('section');
# Links local to our web site
if ($link->tagname eq 'L' and $link->attr('type') eq 'pod') {
my $to = $link->attr('to');
if ($to =~ /^Padre::/) {
$to =~ s{::}{/}g;
return "/docs/Padre/$to.html";
}
}
# all other links are generated by the parent class
my $ret = $self->SUPER::do_pod_link($link);
return $ret;
}
1;
Meanwhile in script.pl:
use My::Pod;
my $p = My::Pod->new;
my $html;
$p->output_string(\$html);
$p->parse_file('path/to/Module/Name.pm');
open my $out, '>', 'out.html' or die;
print $out $html;
TODO
maybe override do_beginning do_end
=head1 SEE ALSO
L, L
TODO: a corpus of sample Pod input and HTML output? Or common
idioms?
=head1 SUPPORT
Questions or discussion about POD and Pod::Simple should be sent to the
pod-people@perl.org mail list. Send an empty email to
pod-people-subscribe@perl.org to subscribe.
This module is managed in an open GitHub repository,
L . Feel free to fork and contribute, or
to clone L and send patches!
Patches against Pod::Simple are welcome. Please send bug reports to
.
=head1 COPYRIGHT AND DISCLAIMERS
Copyright (c) 2002-2004 Sean M. Burke.
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
This program is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of
merchantability or fitness for a particular purpose.
=head1 ACKNOWLEDGEMENTS
Thanks to L for permission to use its
L site for man page links.
Thanks to L for permission to use the
site for Perl module links.
=head1 AUTHOR
Pod::Simple was created by Sean M. Burke .
But don't bother him, he's retired.
Pod::Simple is maintained by:
=over
=item * Allison Randal C
=item * Hans Dieter Pearcey C
=item * David E. Wheeler C
=back
=cut