Debian Codegraph @

upstream/mageia-cauldron/man3pm/Pod::Simple::XHTML.3pm

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\"
56 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "Pod::Simple::XHTML 3pm"
61 .TH Pod::Simple::XHTML 3pm 2023-12-22 "perl v5.42.0" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 Pod::Simple::XHTML \-\- format Pod as validating XHTML
68 .SH SYNOPSIS
69 .IX Header "SYNOPSIS"
70 .Vb 1
71 \& use Pod::Simple::XHTML;
72 \&
73 \& my $parser = Pod::Simple::XHTML\->new();
74 \&
75 \& ...
76 \&
77 \& $parser\->parse_file(\*(Aqpath/to/file.pod\*(Aq);
78 .Ve
79 .SH DESCRIPTION
80 .IX Header "DESCRIPTION"
81 This class is a formatter that takes Pod and renders it as XHTML
82 validating HTML.
83 .PP
84 This is a subclass of Pod::Simple::Methody and inherits all its
85 methods. The implementation is entirely different than
86 Pod::Simple::HTML, but it largely preserves the same interface.
87 .SS "Minimal code"
88 .IX Subsection "Minimal code"
89 .Vb 6
90 \& use Pod::Simple::XHTML;
91 \& my $psx = Pod::Simple::XHTML\->new;
92 \& $psx\->output_string(\emy $html);
93 \& $psx\->parse_file(\*(Aqpath/to/Module/Name.pm\*(Aq);
94 \& open my $out, \*(Aq>\*(Aq, \*(Aqout.html\*(Aq or die "Cannot open \*(Aqout.html\*(Aq: $!\en";
95 \& print $out $html;
96 .Ve
97 .PP
98 You can also control the character encoding and entities. For example, if
99 you\*(Aqre sure that the POD is properly encoded (using the \f(CW\*(C`=encoding\*(C'\fR command),
100 you can prevent high\-bit characters from being encoded as HTML entities and
101 declare the output character set as UTF\-8 before parsing, like so:
102 .PP
103 .Vb 3
104 \& $psx\->html_charset(\*(AqUTF\-8\*(Aq);
105 \&use warnings;
106 \& $psx\->html_encode_chars(q{&<>\*(Aq"});
107 .Ve
108 .SH METHODS
109 .IX Header "METHODS"
110 Pod::Simple::XHTML offers a number of methods that modify the format of
111 the HTML output. Call these after creating the parser object, but before
112 the call to \f(CW\*(C`parse_file\*(C'\fR:
113 .PP
114 .Vb 3
115 \& my $parser = Pod::PseudoPod::HTML\->new();
116 \& $parser\->set_optional_param("value");
117 \& $parser\->parse_file($file);
118 .Ve
119 .SS perldoc_url_prefix
120 .IX Subsection "perldoc_url_prefix"
121 In turning Foo::Bar into http://whatever/Foo%3a%3aBar, what
122 to put before the "Foo%3a%3aBar". The default value is
123 "https://metacpan.org/pod/".
124 .SS perldoc_url_postfix
125 .IX Subsection "perldoc_url_postfix"
126 What to put after "Foo%3a%3aBar" in the URL. This option is not set by
127 default.
128 .SS man_url_prefix
129 .IX Subsection "man_url_prefix"
130 In turning \f(CW\*(C`\fR\f(CBcrontab\fR\f(CW\|(5)\*(C'\fR into http://whatever/man/1/crontab, what
131 to put before the "1/crontab". The default value is
132 "http://man.he.net/man".
133 .SS man_url_postfix
134 .IX Subsection "man_url_postfix"
135 What to put after "1/crontab" in the URL. This option is not set by default.
136 .SS "title_prefix, title_postfix"
137 .IX Subsection "title_prefix, title_postfix"
138 What to put before and after the title in the head. The values should
139 already be &\-escaped.
140 .SS html_css
141 .IX Subsection "html_css"
142 .Vb 1
143 \& $parser\->html_css(\*(Aqpath/to/style.css\*(Aq);
144 .Ve
145 .PP
146 The URL or relative path of a CSS file to include. This option is not
147 set by default.
148 .SS html_javascript
149 .IX Subsection "html_javascript"
150 The URL or relative path of a JavaScript file to pull in. This option is
151 not set by default.
152 .SS html_doctype
153 .IX Subsection "html_doctype"
154 A document type tag for the file. This option is not set by default.
155 .SS html_charset
156 .IX Subsection "html_charset"
157 The character set to declare in the Content\-Type meta tag created by default
158 for \f(CW\*(C`html_header_tags\*(C'\fR. Note that this option will be ignored if the value of
159 \&\f(CW\*(C`html_header_tags\*(C'\fR is changed. Defaults to "ISO\-8859\-1".
160 .SS html_header_tags
161 .IX Subsection "html_header_tags"
162 Additional arbitrary HTML tags for the header of the document. The
163 default value is just a content type header tag:
164 .PP
165 .Vb 1
166 \& <meta http\-equiv="Content\-Type" content="text/html; charset=ISO\-8859\-1">
167 .Ve
168 .PP
169 Add additional meta tags here, or blocks of inline CSS or JavaScript
170 (wrapped in the appropriate tags).
171 .PP
172 \fIhtml_encode_chars\fR
173 .IX Subsection "html_encode_chars"
174 .PP
175 A string containing all characters that should be encoded as HTML entities,
176 specified using the regular expression character class syntax (what you find
177 within brackets in regular expressions). This value will be passed as the
178 second argument to the \f(CW\*(C`encode_entities\*(C'\fR function of HTML::Entities. If
179 HTML::Entities is not installed, then any characters other than \f(CW\*(C`&<\*(C'\fR"\*(Aq>
180 will be encoded numerically.
181 .SS html_h_level
182 .IX Subsection "html_h_level"
183 This is the level of HTML "Hn" element to which a Pod "head1" corresponds. For
184 example, if \f(CW\*(C`html_h_level\*(C'\fR is set to 2, a head1 will produce an H2, a head2
185 will produce an H3, and so on.
186 .SS default_title
187 .IX Subsection "default_title"
188 Set a default title for the page if no title can be determined from the
189 content. The value of this string should already be &\-escaped.
190 .SS force_title
191 .IX Subsection "force_title"
192 Force a title for the page (don\*(Aqt try to determine it from the content).
193 The value of this string should already be &\-escaped.
194 .SS "html_header, html_footer"
195 .IX Subsection "html_header, html_footer"
196 Set the HTML output at the beginning and end of each file. The default
197 header includes a title, a doctype tag (if \f(CW\*(C`html_doctype\*(C'\fR is set), a
198 content tag (customized by \f(CW\*(C`html_header_tags\*(C'\fR), a tag for a CSS file
199 (if \f(CW\*(C`html_css\*(C'\fR is set), and a tag for a Javascript file (if
200 \&\f(CW\*(C`html_javascript\*(C'\fR is set). The default footer simply closes the \f(CW\*(C`html\*(C'\fR
201 and \f(CW\*(C`body\*(C'\fR tags.
202 .PP
203 The options listed above customize parts of the default header, but
204 setting \f(CW\*(C`html_header\*(C'\fR or \f(CW\*(C`html_footer\*(C'\fR completely overrides the
205 built\-in header or footer. These may be useful if you want to use
206 template tags instead of literal HTML headers and footers or are
207 integrating converted POD pages in a larger website.
208 .PP
209 If you want no headers or footers output in the HTML, set these options
210 to the empty string.
211 .SS index
212 .IX Subsection "index"
213 Whether to add a table\-of\-contents at the top of each page (called an
214 index for the sake of tradition).
215 .SS anchor_items
216 .IX Subsection "anchor_items"
217 Whether to anchor every definition \f(CW\*(C`=item\*(C'\fR directive. This needs to be
218 enabled if you want to be able to link to specific \f(CW\*(C`=item\*(C'\fR directives, which
219 are output as \f(CW\*(C`<dt>\*(C'\fR elements. Disabled by default.
220 .SS backlink
221 .IX Subsection "backlink"
222 Whether to turn every =head1 directive into a link pointing to the top
223 of the page (specifically, the opening body tag).
224 .SH SUBCLASSING
225 .IX Header "SUBCLASSING"
226 If the standard options aren\*(Aqt enough, you may want to subclass
227 Pod::Simple::XHMTL. These are the most likely candidates for methods
228 you\*(Aqll want to override when subclassing.
229 .SS handle_text
230 .IX Subsection "handle_text"
231 This method handles the body of text within any element: it\*(Aqs the body
232 of a paragraph, or everything between a "=begin" tag and the
233 corresponding "=end" tag, or the text within an L entity, etc. You would
234 want to override this if you are adding a custom element type that does
235 more than just display formatted text. Perhaps adding a way to generate
236 HTML tables from an extended version of POD.
237 .PP
238 So, let\*(Aqs say you want to add a custom element called \*(Aqfoo\*(Aq. In your
239 subclass\*(Aqs \f(CW\*(C`new\*(C'\fR method, after calling \f(CW\*(C`SUPER::new\*(C'\fR you\*(Aqd call:
240 .PP
241 .Vb 1
242 \& $new\->accept_targets_as_text( \*(Aqfoo\*(Aq );
243 .Ve
244 .PP
245 Then override the \f(CW\*(C`start_for\*(C'\fR method in the subclass to check for when
246 "$flags\->{\*(Aqtarget\*(Aq}" is equal to \*(Aqfoo\*(Aq and set a flag that marks that
247 you\*(Aqre in a foo block (maybe "$self\->{\*(Aqin_foo\*(Aq} = 1"). Then override the
248 \&\f(CW\*(C`handle_text\*(C'\fR method to check for the flag, and pass \f(CW$text\fR to your
249 custom subroutine to construct the HTML output for \*(Aqfoo\*(Aq elements,
250 something like:
251 .PP
252 .Vb 8
253 \& sub handle_text {
254 \& my ($self, $text) = @_;
255 \& if ($self\->{\*(Aqin_foo\*(Aq}) {
256 \& $self\->{\*(Aqscratch\*(Aq} .= build_foo_html($text);
257 \& return;
258 \& }
259 \& $self\->SUPER::handle_text($text);
260 \& }
261 .Ve
262 .SS handle_code
263 .IX Subsection "handle_code"
264 This method handles the body of text that is marked up to be code.
265 You might for instance override this to plug in a syntax highlighter.
266 The base implementation just escapes the text.
267 .PP
268 The callback methods \f(CW\*(C`start_code\*(C'\fR and \f(CW\*(C`end_code\*(C'\fR emits the \f(CW\*(C`code\*(C'\fR tags
269 before and after \f(CW\*(C`handle_code\*(C'\fR is invoked, so you might want to override these
270 together with \f(CW\*(C`handle_code\*(C'\fR if this wrapping isn\*(Aqt suitable.
271 .PP
272 Note that the code might be broken into multiple segments if there are
273 nested formatting codes inside a \f(CW\*(C`C<...>\*(C'\fR sequence. In between the
274 calls to \f(CW\*(C`handle_code\*(C'\fR other markup tags might have been emitted in that
275 case. The same is true for verbatim sections if the \f(CW\*(C`codes_in_verbatim\*(C'\fR
276 option is turned on.
277 .SS accept_targets_as_html
278 .IX Subsection "accept_targets_as_html"
279 This method behaves like \f(CW\*(C`accept_targets_as_text\*(C'\fR, but also marks the region
280 as one whose content should be emitted literally, without HTML entity escaping
281 or wrapping in a \f(CW\*(C`div\*(C'\fR element.
282 .SS resolve_pod_page_link
283 .IX Subsection "resolve_pod_page_link"
284 .Vb 3
285 \& my $url = $pod\->resolve_pod_page_link(\*(AqNet::Ping\*(Aq, \*(AqINSTALL\*(Aq);
286 \& my $url = $pod\->resolve_pod_page_link(\*(Aqperlpodspec\*(Aq);
287 \& my $url = $pod\->resolve_pod_page_link(undef, \*(AqSYNOPSIS\*(Aq);
288 .Ve
289 .PP
290 Resolves a POD link target (typically a module or POD file name) and section
291 name to a URL. The resulting link will be returned for the above examples as:
292 .PP
293 .Vb 3
294 \& https://metacpan.org/pod/Net::Ping#INSTALL
295 \& https://metacpan.org/pod/perlpodspec
296 \& #SYNOPSIS
297 .Ve
298 .PP
299 Note that when there is only a section argument the URL will simply be a link
300 to a section in the current document.
301 .SS resolve_man_page_link
302 .IX Subsection "resolve_man_page_link"
303 .Vb 2
304 \& my $url = $pod\->resolve_man_page_link(\*(Aqcrontab(5)\*(Aq, \*(AqEXAMPLE CRON FILE\*(Aq);
305 \& my $url = $pod\->resolve_man_page_link(\*(Aqcrontab\*(Aq);
306 .Ve
307 .PP
308 Resolves a man page link target and numeric section to a URL. The resulting
309 link will be returned for the above examples as:
310 .PP
311 .Vb 2
312 \& http://man.he.net/man5/crontab
313 \& http://man.he.net/man1/crontab
314 .Ve
315 .PP
316 Note that the first argument is required. The section number will be parsed
317 from it, and if it\*(Aqs missing will default to 1. The second argument is
318 currently ignored, as man.he.net <http://man.he.net> does not currently
319 include linkable IDs or anchor names in its pages. Subclass to link to a
320 different man page HTTP server.
321 .SS idify
322 .IX Subsection "idify"
323 .Vb 2
324 \& my $id = $pod\->idify($text);
325 \& my $hash = $pod\->idify($text, 1);
326 .Ve
327 .PP
328 This method turns an arbitrary string into a valid XHTML ID attribute value.
329 The rules enforced, following
330 <http://webdesign.about.com/od/htmltags/a/aa031707.htm>, are:
331 .IP \(bu 4
332 The id must start with a letter (a\-z or A\-Z)
333 .IP \(bu 4
334 All subsequent characters can be letters, numbers (0\-9), hyphens (\-),
335 underscores (_), colons (:), and periods (.).
336 .IP \(bu 4
337 The final character can\*(Aqt be a hyphen, colon, or period. URLs ending with these
338 characters, while allowed by XHTML, can be awkward to extract from plain text.
339 .IP \(bu 4
340 Each id must be unique within the document.
341 .PP
342 In addition, the returned value will be unique within the context of the
343 Pod::Simple::XHTML object unless a second argument is passed a true value. ID
344 attributes should always be unique within a single XHTML document, but pass
345 the true value if you are creating not an ID but a URL hash to point to
346 an ID (i.e., if you need to put the "#foo" in \f(CW\*(C`<a href="#foo">foo</a>\*(C'\fR.
347 .SS batch_mode_page_object_init
348 .IX Subsection "batch_mode_page_object_init"
349 .Vb 1
350 \& $pod\->batch_mode_page_object_init($batchconvobj, $module, $infile, $outfile, $depth);
351 .Ve
352 .PP
353 Called by Pod::Simple::HTMLBatch so that the class has a chance to
354 initialize the converter. Internally it sets the \f(CW\*(C`batch_mode\*(C'\fR property to
355 true and sets \f(CWbatch_mode_current_level()\fR, but Pod::Simple::XHTML does not
356 currently use those features. Subclasses might, though.
357 .SH "SEE ALSO"
358 .IX Header "SEE ALSO"
359 Pod::Simple, Pod::Simple::Text, Pod::Spell
360 .SH SUPPORT
361 .IX Header "SUPPORT"
362 Questions or discussion about POD and Pod::Simple should be sent to the
363 pod\[email protected] mail list. Send an empty email to
364 pod\-people\[email protected] to subscribe.
365 .PP
366 This module is managed in an open GitHub repository,
367 <https://github.com/perl\-pod/pod\-simple/>. Feel free to fork and contribute, or
368 to clone <https://github.com/perl\-pod/pod\-simple.git> and send patches!
369 .PP
370 Patches against Pod::Simple are welcome. Please send bug reports to
371 <bug\-pod\[email protected]>.
372 .SH "COPYRIGHT AND DISCLAIMERS"
373 .IX Header "COPYRIGHT AND DISCLAIMERS"
374 Copyright (c) 2003\-2005 Allison Randal.
375 .PP
376 This library is free software; you can redistribute it and/or modify it
377 under the same terms as Perl itself.
378 .PP
379 This program is distributed in the hope that it will be useful, but
380 without any warranty; without even the implied warranty of
381 merchantability or fitness for a particular purpose.
382 .SH ACKNOWLEDGEMENTS
383 .IX Header "ACKNOWLEDGEMENTS"
384 Thanks to Hurricane Electric <http://he.net/> for permission to use its
385 Linux man pages online <http://man.he.net/> site for man page links.
386 .PP
387 Thanks to search.cpan.org <http://search.cpan.org/> for permission to use the
388 site for Perl module links.
389 .SH AUTHOR
390 .IX Header "AUTHOR"
391 Pod::Simpele::XHTML was created by Allison Randal <[email protected]>.
392 .PP
393 Pod::Simple was created by Sean M. Burke <[email protected]>.
394 But don\*(Aqt bother him, he\*(Aqs retired.
395 .PP
396 Pod::Simple is maintained by:
397 .IP \(bu 4
398 Allison Randal \f(CW\*(C`[email protected]\*(C'\fR
399 .IP \(bu 4
400 Hans Dieter Pearcey \f(CW\*(C`[email protected]\*(C'\fR
401 .IP \(bu 4
402 David E. Wheeler \f(CW\*(C`[email protected]\*(C'\fR