1Pod::Simple::XHTML(3) User Contributed Perl DocumentationPod::Simple::XHTML(3)
2
3
4

NAME

6       Pod::Simple::XHTML -- format Pod as validating XHTML
7

SYNOPSIS

9         use Pod::Simple::XHTML;
10
11         my $parser = Pod::Simple::XHTML->new();
12
13         ...
14
15         $parser->parse_file('path/to/file.pod');
16

DESCRIPTION

18       This class is a formatter that takes Pod and renders it as XHTML
19       validating HTML.
20
21       This is a subclass of Pod::Simple::Methody and inherits all its
22       methods. The implementation is entirely different than
23       Pod::Simple::HTML, but it largely preserves the same interface.
24
25   Minimal code
26         use Pod::Simple::XHTML;
27         my $psx = Pod::Simple::XHTML->new;
28         $psx->output_string(\my $html);
29         $psx->parse_file('path/to/Module/Name.pm');
30         open my $out, '>', 'out.html' or die "Cannot open 'out.html': $!\n";
31         print $out $html;
32
33       You can also control the character encoding and entities. For example,
34       if you're sure that the POD is properly encoded (using the "=encoding"
35       command), you can prevent high-bit characters from being encoded as
36       HTML entities and declare the output character set as UTF-8 before
37       parsing, like so:
38
39         $psx->html_charset('UTF-8');
40       use warnings;
41         $psx->html_encode_chars(q{&<>'"});
42

METHODS

44       Pod::Simple::XHTML offers a number of methods that modify the format of
45       the HTML output. Call these after creating the parser object, but
46       before the call to "parse_file":
47
48         my $parser = Pod::PseudoPod::HTML->new();
49         $parser->set_optional_param("value");
50         $parser->parse_file($file);
51
52   perldoc_url_prefix
53       In turning Foo::Bar into http://whatever/Foo%3a%3aBar, what to put
54       before the "Foo%3a%3aBar". The default value is
55       "https://metacpan.org/pod/".
56
57   perldoc_url_postfix
58       What to put after "Foo%3a%3aBar" in the URL. This option is not set by
59       default.
60
61   man_url_prefix
62       In turning crontab(5) into http://whatever/man/1/crontab, what to put
63       before the "1/crontab". The default value is "http://man.he.net/man".
64
65   man_url_postfix
66       What to put after "1/crontab" in the URL. This option is not set by
67       default.
68
69   title_prefix, title_postfix
70       What to put before and after the title in the head. The values should
71       already be &-escaped.
72
73   html_css
74         $parser->html_css('path/to/style.css');
75
76       The URL or relative path of a CSS file to include. This option is not
77       set by default.
78
79   html_javascript
80       The URL or relative path of a JavaScript file to pull in. This option
81       is not set by default.
82
83   html_doctype
84       A document type tag for the file. This option is not set by default.
85
86   html_charset
87       The character set to declare in the Content-Type meta tag created by
88       default for "html_header_tags". Note that this option will be ignored
89       if the value of "html_header_tags" is changed. Defaults to
90       "ISO-8859-1".
91
92   html_header_tags
93       Additional arbitrary HTML tags for the header of the document. The
94       default value is just a content type header tag:
95
96         <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
97
98       Add additional meta tags here, or blocks of inline CSS or JavaScript
99       (wrapped in the appropriate tags).
100
101       html_encode_chars
102
103       A string containing all characters that should be encoded as HTML
104       entities, specified using the regular expression character class syntax
105       (what you find within brackets in regular expressions). This value will
106       be passed as the second argument to the "encode_entities" function of
107       HTML::Entities. If HTML::Entities is not installed, then any characters
108       other than "&<""'> will be encoded numerically.
109
110   html_h_level
111       This is the level of HTML "Hn" element to which a Pod "head1"
112       corresponds.  For example, if "html_h_level" is set to 2, a head1 will
113       produce an H2, a head2 will produce an H3, and so on.
114
115   default_title
116       Set a default title for the page if no title can be determined from the
117       content. The value of this string should already be &-escaped.
118
119   force_title
120       Force a title for the page (don't try to determine it from the
121       content).  The value of this string should already be &-escaped.
122
123   html_header, html_footer
124       Set the HTML output at the beginning and end of each file. The default
125       header includes a title, a doctype tag (if "html_doctype" is set), a
126       content tag (customized by "html_header_tags"), a tag for a CSS file
127       (if "html_css" is set), and a tag for a Javascript file (if
128       "html_javascript" is set). The default footer simply closes the "html"
129       and "body" tags.
130
131       The options listed above customize parts of the default header, but
132       setting "html_header" or "html_footer" completely overrides the built-
133       in header or footer. These may be useful if you want to use template
134       tags instead of literal HTML headers and footers or are integrating
135       converted POD pages in a larger website.
136
137       If you want no headers or footers output in the HTML, set these options
138       to the empty string.
139
140   index
141       Whether to add a table-of-contents at the top of each page (called an
142       index for the sake of tradition).
143
144   anchor_items
145       Whether to anchor every definition "=item" directive. This needs to be
146       enabled if you want to be able to link to specific "=item" directives,
147       which are output as "<dt>" elements. Disabled by default.
148
149   backlink
150       Whether to turn every =head1 directive into a link pointing to the top
151       of the page (specifically, the opening body tag).
152

SUBCLASSING

154       If the standard options aren't enough, you may want to subclass
155       Pod::Simple::XHMTL. These are the most likely candidates for methods
156       you'll want to override when subclassing.
157
158   handle_text
159       This method handles the body of text within any element: it's the body
160       of a paragraph, or everything between a "=begin" tag and the
161       corresponding "=end" tag, or the text within an L entity, etc. You
162       would want to override this if you are adding a custom element type
163       that does more than just display formatted text. Perhaps adding a way
164       to generate HTML tables from an extended version of POD.
165
166       So, let's say you want to add a custom element called 'foo'. In your
167       subclass's "new" method, after calling "SUPER::new" you'd call:
168
169         $new->accept_targets_as_text( 'foo' );
170
171       Then override the "start_for" method in the subclass to check for when
172       "$flags->{'target'}" is equal to 'foo' and set a flag that marks that
173       you're in a foo block (maybe "$self->{'in_foo'} = 1"). Then override
174       the "handle_text" method to check for the flag, and pass $text to your
175       custom subroutine to construct the HTML output for 'foo' elements,
176       something like:
177
178         sub handle_text {
179             my ($self, $text) = @_;
180             if ($self->{'in_foo'}) {
181                 $self->{'scratch'} .= build_foo_html($text);
182                 return;
183             }
184             $self->SUPER::handle_text($text);
185         }
186
187   handle_code
188       This method handles the body of text that is marked up to be code.  You
189       might for instance override this to plug in a syntax highlighter.  The
190       base implementation just escapes the text.
191
192       The callback methods "start_code" and "end_code" emits the "code" tags
193       before and after "handle_code" is invoked, so you might want to
194       override these together with "handle_code" if this wrapping isn't
195       suitable.
196
197       Note that the code might be broken into multiple segments if there are
198       nested formatting codes inside a "C<...>" sequence.  In between the
199       calls to "handle_code" other markup tags might have been emitted in
200       that case.  The same is true for verbatim sections if the
201       "codes_in_verbatim" option is turned on.
202
203   accept_targets_as_html
204       This method behaves like "accept_targets_as_text", but also marks the
205       region as one whose content should be emitted literally, without HTML
206       entity escaping or wrapping in a "div" element.
207
208   resolve_pod_page_link
209         my $url = $pod->resolve_pod_page_link('Net::Ping', 'INSTALL');
210         my $url = $pod->resolve_pod_page_link('perlpodspec');
211         my $url = $pod->resolve_pod_page_link(undef, 'SYNOPSIS');
212
213       Resolves a POD link target (typically a module or POD file name) and
214       section name to a URL. The resulting link will be returned for the
215       above examples as:
216
217         https://metacpan.org/pod/Net::Ping#INSTALL
218         https://metacpan.org/pod/perlpodspec
219         #SYNOPSIS
220
221       Note that when there is only a section argument the URL will simply be
222       a link to a section in the current document.
223
224   resolve_man_page_link
225         my $url = $pod->resolve_man_page_link('crontab(5)', 'EXAMPLE CRON FILE');
226         my $url = $pod->resolve_man_page_link('crontab');
227
228       Resolves a man page link target and numeric section to a URL. The
229       resulting link will be returned for the above examples as:
230
231           http://man.he.net/man5/crontab
232           http://man.he.net/man1/crontab
233
234       Note that the first argument is required. The section number will be
235       parsed from it, and if it's missing will default to 1. The second
236       argument is currently ignored, as man.he.net <http://man.he.net> does
237       not currently include linkable IDs or anchor names in its pages.
238       Subclass to link to a different man page HTTP server.
239
240   idify
241         my $id   = $pod->idify($text);
242         my $hash = $pod->idify($text, 1);
243
244       This method turns an arbitrary string into a valid XHTML ID attribute
245       value.  The rules enforced, following
246       <http://webdesign.about.com/od/htmltags/a/aa031707.htm>, are:
247
248       •   The id must start with a letter (a-z or A-Z)
249
250       •   All subsequent characters can be letters, numbers (0-9), hyphens
251           (-), underscores (_), colons (:), and periods (.).
252
253       •   The final character can't be a hyphen, colon, or period. URLs
254           ending with these characters, while allowed by XHTML, can be
255           awkward to extract from plain text.
256
257       •   Each id must be unique within the document.
258
259       In addition, the returned value will be unique within the context of
260       the Pod::Simple::XHTML object unless a second argument is passed a true
261       value. ID attributes should always be unique within a single XHTML
262       document, but pass the true value if you are creating not an ID but a
263       URL hash to point to an ID (i.e., if you need to put the "#foo" in "<a
264       href="#foo">foo</a>".
265
266   batch_mode_page_object_init
267         $pod->batch_mode_page_object_init($batchconvobj, $module, $infile, $outfile, $depth);
268
269       Called by Pod::Simple::HTMLBatch so that the class has a chance to
270       initialize the converter. Internally it sets the "batch_mode" property
271       to true and sets batch_mode_current_level(), but Pod::Simple::XHTML
272       does not currently use those features. Subclasses might, though.
273

SEE ALSO

275       Pod::Simple, Pod::Simple::Text, Pod::Spell
276

SUPPORT

278       Questions or discussion about POD and Pod::Simple should be sent to the
279       pod-people@perl.org mail list. Send an empty email to
280       pod-people-subscribe@perl.org to subscribe.
281
282       This module is managed in an open GitHub repository,
283       <https://github.com/perl-pod/pod-simple/>. Feel free to fork and
284       contribute, or to clone <https://github.com/perl-pod/pod-simple.git>
285       and send patches!
286
287       Patches against Pod::Simple are welcome. Please send bug reports to
288       <bug-pod-simple@rt.cpan.org>.
289
291       Copyright (c) 2003-2005 Allison Randal.
292
293       This library is free software; you can redistribute it and/or modify it
294       under the same terms as Perl itself.
295
296       This program is distributed in the hope that it will be useful, but
297       without any warranty; without even the implied warranty of
298       merchantability or fitness for a particular purpose.
299

ACKNOWLEDGEMENTS

301       Thanks to Hurricane Electric <http://he.net/> for permission to use its
302       Linux man pages online <http://man.he.net/> site for man page links.
303
304       Thanks to search.cpan.org <http://search.cpan.org/> for permission to
305       use the site for Perl module links.
306

AUTHOR

308       Pod::Simpele::XHTML was created by Allison Randal <allison@perl.org>.
309
310       Pod::Simple was created by Sean M. Burke <sburke@cpan.org>.  But don't
311       bother him, he's retired.
312
313       Pod::Simple is maintained by:
314
315       •   Allison Randal "allison@perl.org"
316
317       •   Hans Dieter Pearcey "hdp@cpan.org"
318
319       •   David E. Wheeler "dwheeler@cpan.org"
320
321
322
323perl v5.38.0                      2023-07-21             Pod::Simple::XHTML(3)
Impressum