SYNOPSIS

  use Pod::Simple::XHTML;

  my $parser = Pod::Simple::XHTML->new();

  ...

  $parser->parse_file('path/to/file.pod');

DESCRIPTION

This class is a formatter that takes Pod and renders it as \s-1XHTML\s0 validating \s-1HTML\s0.

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.

Minimal code

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 \s-1POD\s0 is properly encoded (using the \*(C`=encoding\*(C' command), you can prevent high-bit characters from being encoded as \s-1HTML\s0 entities and declare the output character set as \s-1UTF-8\s0 before parsing, like so:

$psx->html_charset('UTF-8'); $psx->html_encode_chars('&<>">');

METHODS

Pod::Simple::XHTML offers a number of methods that modify the format of the \s-1HTML\s0 output. Call these after creating the parser object, but before the call to \*(C`parse_file\*(C':

my $parser = Pod::PseudoPod::HTML->new(); $parser->set_optional_param("value"); $parser->parse_file($file);

perldoc_url_prefix

In turning Foo::Bar into http://whatever/Foo%3a%3aBar, what to put before the \*(L"Foo%3a%3aBar\*(R". The default value is \*(L"http://search.cpan.org/perldoc?\*(R".

perldoc_url_postfix

What to put after \*(L"Foo%3a%3aBar\*(R" in the \s-1URL\s0. This option is not set by default.

man_url_prefix

In turning crontab(5) into http://whatever/man/1/crontab, what to put before the \*(L"1/crontab\*(R". The default value is \*(L"http://man.he.net/man\*(R".

man_url_postfix

What to put after \*(L"1/crontab\*(R" in the \s-1URL\s0. This option is not set by default.

title_prefix, title_postfix

What to put before and after the title in the head. The values should already be &-escaped.

html_css

$parser->html_css('path/to/style.css');

The \s-1URL\s0 or relative path of a \s-1CSS\s0 file to include. This option is not set by default.

html_javascript

The \s-1URL\s0 or relative path of a JavaScript file to pull in. This option is not set by default.

html_doctype

A document type tag for the file. This option is not set by default.

html_charset

The character set to declare in the Content-Type meta tag created by default for \*(C`html_header_tags\*(C'. Note that this option will be ignored if the value of \*(C`html_header_tags\*(C' is changed. Defaults to \*(L"\s-1ISO-8859-1\s0\*(R".

html_header_tags

Additional arbitrary \s-1HTML\s0 tags for the header of the document. The default value is just a content type header tag:

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

Add additional meta tags here, or blocks of inline \s-1CSS\s0 or JavaScript (wrapped in the appropriate tags).

html_encode_chars

A string containing all characters that should be encoded as \s-1HTML\s0 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 \*(C`encode_entities\*(C' function of HTML::Entities. If HTML::Entities is not installed, then any characters other than \*(C`&<\*(C'"'> will be encoded numerically.

html_h_level

This is the level of \s-1HTML\s0 \*(L"Hn\*(R" element to which a Pod \*(L"head1\*(R" corresponds. For example, if \*(C`html_h_level\*(C' is set to 2, a head1 will produce an H2, a head2 will produce an H3, and so on.

default_title

Set a default title for the page if no title can be determined from the content. The value of this string should already be &-escaped.

force_title

Force a title for the page (don't try to determine it from the content). The value of this string should already be &-escaped.

html_header, html_footer

Set the \s-1HTML\s0 output at the beginning and end of each file. The default header includes a title, a doctype tag (if \*(C`html_doctype\*(C' is set), a content tag (customized by \*(C`html_header_tags\*(C'), a tag for a \s-1CSS\s0 file (if \*(C`html_css\*(C' is set), and a tag for a Javascript file (if \*(C`html_javascript\*(C' is set). The default footer simply closes the \*(C`html\*(C' and \*(C`body\*(C' tags.

The options listed above customize parts of the default header, but setting \*(C`html_header\*(C' or \*(C`html_footer\*(C' completely overrides the built-in header or footer. These may be useful if you want to use template tags instead of literal \s-1HTML\s0 headers and footers or are integrating converted \s-1POD\s0 pages in a larger website.

If you want no headers or footers output in the \s-1HTML\s0, set these options to the empty string.

index

Whether to add a table-of-contents at the top of each page (called an index for the sake of tradition).

anchor_items

Whether to anchor every definition \*(C`=item\*(C' directive. This needs to be enabled if you want to be able to link to specific \*(C`=item\*(C' directives, which are output as \*(C`<dt>\*(C' elements. Disabled by default.

backlink

Whether to turn every =head1 directive into a link pointing to the top of the page (specifically, the opening body tag).

SUBCLASSING

If the standard options aren't enough, you may want to subclass Pod::Simple::XHMTL. These are the most likely candidates for methods you'll want to override when subclassing.

handle_text

This method handles the body of text within any element: it's the body of a paragraph, or everything between a \*(L"=begin\*(R" tag and the corresponding \*(L"=end\*(R" tag, or the text within an L entity, etc. You would want to override this if you are adding a custom element type that does more than just display formatted text. Perhaps adding a way to generate \s-1HTML\s0 tables from an extended version of \s-1POD\s0.

So, let's say you want to add a custom element called 'foo'. In your subclass's \*(C`new\*(C' method, after calling \*(C`SUPER::new\*(C' you'd call:

$new->accept_targets_as_text( 'foo' );

Then override the \*(C`start_for\*(C' method in the subclass to check for when \*(L"$flags->{'target'}\*(R" is equal to 'foo' and set a flag that marks that you're in a foo block (maybe \*(L"$self->{'in_foo'} = 1\*(R"). Then override the \*(C`handle_text\*(C' method to check for the flag, and pass $text to your custom subroutine to construct the \s-1HTML\s0 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); }

handle_code

This method handles the body of text that is marked up to be code. You might for instance override this to plug in a syntax highlighter. The base implementation just escapes the text.

The callback methods \*(C`start_code\*(C' and \*(C`end_code\*(C' emits the \*(C`code\*(C' tags before and after \*(C`handle_code\*(C' is invoked, so you might want to override these together with \*(C`handle_code\*(C' 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`C<...>\*(C' sequence. In between the calls to \*(C`handle_code\*(C' other markup tags might have been emitted in that case. The same is true for verbatim sections if the \*(C`codes_in_verbatim\*(C' option is turned on.

accept_targets_as_html

This method behaves like \*(C`accept_targets_as_text\*(C', but also marks the region as one whose content should be emitted literally, without \s-1HTML\s0 entity escaping or wrapping in a \*(C`div\*(C' element.

resolve_pod_page_link

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 \s-1POD\s0 link target (typically a module or \s-1POD\s0 file name) and section name to a \s-1URL\s0. 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 \s-1URL\s0 will simply be a link to a section in the current document.

resolve_man_page_link

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 \s-1URL\s0. 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 \s-1HTTP\s0 server.

idify

my $id = $pod->idify($text); my $hash = $pod->idify($text, 1);

This method turns an arbitrary string into a valid \s-1XHTML\s0 \s-1ID\s0 attribute value. The rules enforced, following <http://webdesign.about.com/od/htmltags/a/aa031707.htm>, are:

  • The id must start with a letter (a-z or A-Z)

  • All subsequent characters can be letters, numbers (0-9), hyphens (-), underscores (_), colons (:), and periods (.).

  • The final character can't be a hyphen, colon, or period. URLs ending with these characters, while allowed by \s-1XHTML\s0, can be awkward to extract from plain text.

  • Each id must be unique within the document.

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. \s-1ID\s0 attributes should always be unique within a single \s-1XHTML\s0 document, but pass the true value if you are creating not an \s-1ID\s0 but a \s-1URL\s0 hash to point to an \s-1ID\s0 (i.e., if you need to put the \*(L"#foo\*(R" in \*(C`<a href="#foo">foo</a>\*(C'.

batch_mode_page_object_init

$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 \*(C`batch_mode\*(C' property to true and sets \*(C`batch_mode_current_level()\*(C', but Pod::Simple::XHTML does not currently use those features. Subclasses might, though.

RELATED TO Pod::Simple::XHTML…

Pod::Simple, Pod::Simple::Text, Pod::Spell

SUPPORT

Questions or discussion about \s-1POD\s0 and Pod::Simple should be sent to the [email protected] mail list. Send an empty email to [email protected] to subscribe.

This module is managed in an open GitHub repository, https://github.com/theory/pod-simple/ <https://github.com/theory/pod-simple/>. Feel free to fork and contribute, or to clone git://github.com/theory/pod-simple.git <git://github.com/theory/pod-simple.git> and send patches!

Patches against Pod::Simple are welcome. Please send bug reports to <[email protected]>.

COPYRIGHT AND DISCLAIMERS

Copyright (c) 2003-2005 Allison Randal.

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.

ACKNOWLEDGEMENTS

Thanks to Hurricane Electric <http://he.net/> for permission to use its Linux man pages online <http://man.he.net/> site for man page links.

Thanks to search.cpan.org <http://search.cpan.org/> for permission to use the site for Perl module links.

AUTHOR

Pod::Simpele::XHTML was created by Allison Randal <[email protected]>.

Pod::Simple was created by Sean M. Burke <[email protected]>. But don't bother him, he's retired.

Pod::Simple is maintained by: