use Pod::Simple::XHTML; my $parser = Pod::Simple::XHTML->new(); ... $parser->parse_file('path/to/file.pod');
This is a subclass of Pod::Simple::Methody and inherits all its methods. The implementation is entirely different than Pod::Simple::HTML, but it largely preserves the same interface.
use Pod::Simple::XHTML; my $psx = Pod::Simple::XHTML->new; $psx->output_string(\my $html); $psx->parse_file('path/to/Module/Name.pm'); open my $out, '>', 'out.html' or die "Cannot open 'out.html': $!\n"; print $out $html;
You can also control the character encoding and entities. For example, if you're sure that the POD is properly encoded (using the "=encoding" command), you can prevent high-bit characters from being encoded as HTML entities and declare the output character set as UTF-8 before parsing, like so:
$psx->html_charset('UTF-8'); $psx->html_encode_chars(q{&<>'"});
my $parser = Pod::PseudoPod::HTML->new(); $parser->set_optional_param("value"); $parser->parse_file($file);
$parser->html_css('path/to/style.css');
The URL or relative path of a CSS file to include. This option is not set by default.
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
Add additional meta tags here, or blocks of inline CSS or JavaScript (wrapped in the appropriate tags).
html_encode_chars
A string containing all characters that should be encoded as HTML entities, specified using the regular expression character class syntax (what you find within brackets in regular expressions). This value will be passed as the second argument to the "encode_entities" function of HTML::Entities. If HTML::Entities is not installed, then any characters other than "&<""'> will be encoded numerically.
The options listed above customize parts of the default header, but setting "html_header" or "html_footer" completely overrides the built-in header or footer. These may be useful if you want to use template tags instead of literal HTML headers and footers or are integrating converted POD pages in a larger website.
If you want no headers or footers output in the HTML, set these options to the empty string.
So, let's say you want to add a custom element called 'foo'. In your subclass's "new" method, after calling "SUPER::new" you'd call:
$new->accept_targets_as_text( 'foo' );
Then override the "start_for" method in the subclass to check for when ``$flags->{'target'}'' is equal to 'foo' and set a flag that marks that you're in a foo block (maybe ``$self->{'in_foo'} = 1''). Then override the "handle_text" method to check for the flag, and pass $text to your custom subroutine to construct the HTML output for 'foo' elements, something like:
sub handle_text { my ($self, $text) = @_; if ($self->{'in_foo'}) { $self->{'scratch'} .= build_foo_html($text); return; } $self->SUPER::handle_text($text); }
The callback methods "start_code" and "end_code" emits the "code" tags before and after "handle_code" is invoked, so you might want to override these together with "handle_code" if this wrapping isn't suitable.
Note that the code might be broken into multiple segments if there are nested formatting codes inside a "C<...>" sequence. In between the calls to "handle_code" other markup tags might have been emitted in that case. The same is true for verbatim sections if the "codes_in_verbatim" option is turned on.
my $url = $pod->resolve_pod_page_link('Net::Ping', 'INSTALL'); my $url = $pod->resolve_pod_page_link('perlpodspec'); my $url = $pod->resolve_pod_page_link(undef, 'SYNOPSIS');
Resolves a POD link target (typically a module or POD file name) and section name to a URL. The resulting link will be returned for the above examples as:
http://search.cpan.org/perldoc?Net::Ping#INSTALL http://search.cpan.org/perldoc?perlpodspec #SYNOPSIS
Note that when there is only a section argument the URL will simply be a link to a section in the current document.
my $url = $pod->resolve_man_page_link('crontab(5)', 'EXAMPLE CRON FILE'); my $url = $pod->resolve_man_page_link('crontab');
Resolves a man page link target and numeric section to a URL. The resulting link will be returned for the above examples as:
http://man.he.net/man5/crontab http://man.he.net/man1/crontab
Note that the first argument is required. The section number will be parsed from it, and if it's missing will default to 1. The second argument is currently ignored, as man.he.net <http://man.he.net> does not currently include linkable IDs or anchor names in its pages. Subclass to link to a different man page HTTP server.
my $id = $pod->idify($text); my $hash = $pod->idify($text, 1);
This method turns an arbitrary string into a valid XHTML ID attribute value. The rules enforced, following <http://webdesign.about.com/od/htmltags/a/aa031707.htm>, are:
In addition, the returned value will be unique within the context of the Pod::Simple::XHTML object unless a second argument is passed a true value. ID attributes should always be unique within a single XHTML document, but pass the true value if you are creating not an ID but a URL hash to point to an ID (i.e., if you need to put the ``#foo'' in "<a href="#foo">foo</a>".
$pod->batch_mode_page_object_init($batchconvobj, $module, $infile, $outfile, $depth);
Called by Pod::Simple::HTMLBatch so that the class has a chance to initialize the converter. Internally it sets the "batch_mode" property to true and sets "batch_mode_current_level()", but Pod::Simple::XHTML does not currently use those features. Subclasses might, though.
This module is managed in an open GitHub repository, <https://github.com/perl-pod/pod-simple/>. Feel free to fork and contribute, or to clone <git://github.com/perl-pod/pod-simple.git> and send patches!
Patches against Pod::Simple are welcome. Please send bug reports to <bug-pod-simple@rt.cpan.org>.
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.
Thanks to search.cpan.org <http://search.cpan.org/> for permission to use the site for Perl module links.
Pod::Simple was created by Sean M. Burke <sburke@cpan.org>. But don't bother him, he's retired.
Pod::Simple is maintained by: