1=pod 2 3=head1 NAME 4 5Pod::Simple::XHTML -- format Pod as validating XHTML 6 7=head1 SYNOPSIS 8 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 17=head1 DESCRIPTION 18 19This class is a formatter that takes Pod and renders it as XHTML 20validating HTML. 21 22This is a subclass of L<Pod::Simple::Methody> and inherits all its 23methods. The implementation is entirely different than 24L<Pod::Simple::HTML>, but it largely preserves the same interface. 25 26=head2 Minimal code 27 28 use Pod::Simple::XHTML; 29 my $psx = Pod::Simple::XHTML->new; 30 $psx->output_string(\my $html); 31 $psx->parse_file('path/to/Module/Name.pm'); 32 open my $out, '>', 'out.html' or die "Cannot open 'out.html': $!\n"; 33 print $out $html; 34 35You can also control the character encoding and entities. For example, if 36you're sure that the POD is properly encoded (using the C<=encoding> command), 37you can prevent high-bit characters from being encoded as HTML entities and 38declare the output character set as UTF-8 before parsing, like so: 39 40 $psx->html_charset('UTF-8'); 41 $psx->html_encode_chars('&<>">'); 42 43=cut 44 45package Pod::Simple::XHTML; 46use strict; 47use vars qw( $VERSION @ISA $HAS_HTML_ENTITIES ); 48$VERSION = '3.20'; 49use Pod::Simple::Methody (); 50@ISA = ('Pod::Simple::Methody'); 51 52BEGIN { 53 $HAS_HTML_ENTITIES = eval "require HTML::Entities; 1"; 54} 55 56my %entities = ( 57 q{>} => 'gt', 58 q{<} => 'lt', 59 q{'} => '#39', 60 q{"} => 'quot', 61 q{&} => 'amp', 62); 63 64sub encode_entities { 65 my $self = shift; 66 my $ents = $self->html_encode_chars; 67 return HTML::Entities::encode_entities( $_[0], $ents ) if $HAS_HTML_ENTITIES; 68 if (defined $ents) { 69 $ents =~ s,(?<!\\)([]/]),\\$1,g; 70 $ents =~ s,(?<!\\)\\\z,\\\\,; 71 } else { 72 $ents = join '', keys %entities; 73 } 74 my $str = $_[0]; 75 $str =~ s/([$ents])/'&' . ($entities{$1} || sprintf '#x%X', ord $1) . ';'/ge; 76 return $str; 77} 78 79#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 80 81=head1 METHODS 82 83Pod::Simple::XHTML offers a number of methods that modify the format of 84the HTML output. Call these after creating the parser object, but before 85the call to C<parse_file>: 86 87 my $parser = Pod::PseudoPod::HTML->new(); 88 $parser->set_optional_param("value"); 89 $parser->parse_file($file); 90 91=head2 perldoc_url_prefix 92 93In turning L<Foo::Bar> into http://whatever/Foo%3a%3aBar, what 94to put before the "Foo%3a%3aBar". The default value is 95"http://search.cpan.org/perldoc?". 96 97=head2 perldoc_url_postfix 98 99What to put after "Foo%3a%3aBar" in the URL. This option is not set by 100default. 101 102=head2 man_url_prefix 103 104In turning C<< L<crontab(5)> >> into http://whatever/man/1/crontab, what 105to put before the "1/crontab". The default value is 106"http://man.he.net/man". 107 108=head2 man_url_postfix 109 110What to put after "1/crontab" in the URL. This option is not set by default. 111 112=head2 title_prefix, title_postfix 113 114What to put before and after the title in the head. The values should 115already be &-escaped. 116 117=head2 html_css 118 119 $parser->html_css('path/to/style.css'); 120 121The URL or relative path of a CSS file to include. This option is not 122set by default. 123 124=head2 html_javascript 125 126The URL or relative path of a JavaScript file to pull in. This option is 127not set by default. 128 129=head2 html_doctype 130 131A document type tag for the file. This option is not set by default. 132 133=head2 html_charset 134 135The charater set to declare in the Content-Type meta tag created by default 136for C<html_header_tags>. Note that this option will be ignored if the value of 137C<html_header_tags> is changed. Defaults to "ISO-8859-1". 138 139=head2 html_header_tags 140 141Additional arbitrary HTML tags for the header of the document. The 142default value is just a content type header tag: 143 144 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 145 146Add additional meta tags here, or blocks of inline CSS or JavaScript 147(wrapped in the appropriate tags). 148 149=head3 html_encode_chars 150 151A string containing all characters that should be encoded as HTML entities, 152specified using the regular expression character class syntax (what you find 153within brackets in regular expressions). This value will be passed as the 154second argument to the C<encode_entities> fuction of L<HTML::Entities>. IF 155L<HTML::Entities> is not installed, then any characters other than C<&<>"'> 156will be encoded numerically. 157 158=head2 html_h_level 159 160This is the level of HTML "Hn" element to which a Pod "head1" corresponds. For 161example, if C<html_h_level> is set to 2, a head1 will produce an H2, a head2 162will produce an H3, and so on. 163 164=head2 default_title 165 166Set a default title for the page if no title can be determined from the 167content. The value of this string should already be &-escaped. 168 169=head2 force_title 170 171Force a title for the page (don't try to determine it from the content). 172The value of this string should already be &-escaped. 173 174=head2 html_header, html_footer 175 176Set the HTML output at the beginning and end of each file. The default 177header includes a title, a doctype tag (if C<html_doctype> is set), a 178content tag (customized by C<html_header_tags>), a tag for a CSS file 179(if C<html_css> is set), and a tag for a Javascript file (if 180C<html_javascript> is set). The default footer simply closes the C<html> 181and C<body> tags. 182 183The options listed above customize parts of the default header, but 184setting C<html_header> or C<html_footer> completely overrides the 185built-in header or footer. These may be useful if you want to use 186template tags instead of literal HTML headers and footers or are 187integrating converted POD pages in a larger website. 188 189If you want no headers or footers output in the HTML, set these options 190to the empty string. 191 192=head2 index 193 194Whether to add a table-of-contents at the top of each page (called an 195index for the sake of tradition). 196 197=head2 anchor_items 198 199Whether to anchor every definition C<=item> directive. This needs to be 200enabled if you want to be able to link to specific C<=item> directives, which 201are output as C<< <dt> >> elements. Disabled by default. 202 203=head2 backlink 204 205Whether to turn every =head1 directive into a link pointing to the top 206of the page (specifically, the opening body tag). 207 208=cut 209 210__PACKAGE__->_accessorize( 211 'perldoc_url_prefix', 212 'perldoc_url_postfix', 213 'man_url_prefix', 214 'man_url_postfix', 215 'title_prefix', 'title_postfix', 216 'html_css', 217 'html_javascript', 218 'html_doctype', 219 'html_charset', 220 'html_encode_chars', 221 'html_h_level', 222 'title', # Used internally for the title extracted from the content 223 'default_title', 224 'force_title', 225 'html_header', 226 'html_footer', 227 'index', 228 'anchor_items', 229 'backlink', 230 'batch_mode', # whether we're in batch mode 231 'batch_mode_current_level', 232 # When in batch mode, how deep the current module is: 1 for "LWP", 233 # 2 for "LWP::Procotol", 3 for "LWP::Protocol::GHTTP", etc 234); 235 236#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 237 238=head1 SUBCLASSING 239 240If the standard options aren't enough, you may want to subclass 241Pod::Simple::XHMTL. These are the most likely candidates for methods 242you'll want to override when subclassing. 243 244=cut 245 246sub new { 247 my $self = shift; 248 my $new = $self->SUPER::new(@_); 249 $new->{'output_fh'} ||= *STDOUT{IO}; 250 $new->perldoc_url_prefix('http://search.cpan.org/perldoc?'); 251 $new->man_url_prefix('http://man.he.net/man'); 252 $new->html_charset('ISO-8859-1'); 253 $new->nix_X_codes(1); 254 $new->codes_in_verbatim(1); 255 $new->{'scratch'} = ''; 256 $new->{'to_index'} = []; 257 $new->{'output'} = []; 258 $new->{'saved'} = []; 259 $new->{'ids'} = { '_podtop_' => 1 }; # used in <body> 260 $new->{'in_li'} = []; 261 262 $new->{'__region_targets'} = []; 263 $new->{'__literal_targets'} = {}; 264 $new->accept_targets_as_html( 'html', 'HTML' ); 265 266 return $new; 267} 268 269sub html_header_tags { 270 my $self = shift; 271 return $self->{html_header_tags} = shift if @_; 272 return $self->{html_header_tags} 273 ||= '<meta http-equiv="Content-Type" content="text/html; charset=' 274 . $self->html_charset . '" />'; 275} 276 277#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 278 279=head2 handle_text 280 281This method handles the body of text within any element: it's the body 282of a paragraph, or everything between a "=begin" tag and the 283corresponding "=end" tag, or the text within an L entity, etc. You would 284want to override this if you are adding a custom element type that does 285more than just display formatted text. Perhaps adding a way to generate 286HTML tables from an extended version of POD. 287 288So, let's say you want to add a custom element called 'foo'. In your 289subclass's C<new> method, after calling C<SUPER::new> you'd call: 290 291 $new->accept_targets_as_text( 'foo' ); 292 293Then override the C<start_for> method in the subclass to check for when 294"$flags->{'target'}" is equal to 'foo' and set a flag that marks that 295you're in a foo block (maybe "$self->{'in_foo'} = 1"). Then override the 296C<handle_text> method to check for the flag, and pass $text to your 297custom subroutine to construct the HTML output for 'foo' elements, 298something like: 299 300 sub handle_text { 301 my ($self, $text) = @_; 302 if ($self->{'in_foo'}) { 303 $self->{'scratch'} .= build_foo_html($text); 304 } else { 305 $self->{'scratch'} .= $text; 306 } 307 } 308 309=head2 accept_targets_as_html 310 311This method behaves like C<accept_targets_as_text>, but also marks the region 312as one whose content should be emitted literally, without HTML entity escaping 313or wrapping in a C<div> element. 314 315=cut 316 317sub __in_literal_xhtml_region { 318 return unless @{ $_[0]{__region_targets} }; 319 my $target = $_[0]{__region_targets}[-1]; 320 return $_[0]{__literal_targets}{ $target }; 321} 322 323sub accept_targets_as_html { 324 my ($self, @targets) = @_; 325 $self->accept_targets(@targets); 326 $self->{__literal_targets}{$_} = 1 for @targets; 327} 328 329sub handle_text { 330 # escape special characters in HTML (<, >, &, etc) 331 $_[0]{'scratch'} .= $_[0]->__in_literal_xhtml_region 332 ? $_[1] 333 : $_[0]->encode_entities( $_[1] ); 334} 335 336sub start_Para { $_[0]{'scratch'} = '<p>' } 337sub start_Verbatim { $_[0]{'scratch'} = '<pre><code>' } 338 339sub start_head1 { $_[0]{'in_head'} = 1 } 340sub start_head2 { $_[0]{'in_head'} = 2 } 341sub start_head3 { $_[0]{'in_head'} = 3 } 342sub start_head4 { $_[0]{'in_head'} = 4 } 343 344sub start_item_number { 345 $_[0]{'scratch'} = "</li>\n" if ($_[0]{'in_li'}->[-1] && pop @{$_[0]{'in_li'}}); 346 $_[0]{'scratch'} .= '<li><p>'; 347 push @{$_[0]{'in_li'}}, 1; 348} 349 350sub start_item_bullet { 351 $_[0]{'scratch'} = "</li>\n" if ($_[0]{'in_li'}->[-1] && pop @{$_[0]{'in_li'}}); 352 $_[0]{'scratch'} .= '<li><p>'; 353 push @{$_[0]{'in_li'}}, 1; 354} 355 356sub start_item_text { 357 # see end_item_text 358} 359 360sub start_over_bullet { $_[0]{'scratch'} = '<ul>'; push @{$_[0]{'in_li'}}, 0; $_[0]->emit } 361sub start_over_block { $_[0]{'scratch'} = '<ul>'; $_[0]->emit } 362sub start_over_number { $_[0]{'scratch'} = '<ol>'; push @{$_[0]{'in_li'}}, 0; $_[0]->emit } 363sub start_over_text { 364 $_[0]{'scratch'} = '<dl>'; 365 $_[0]{'dl_level'}++; 366 $_[0]{'in_dd'} ||= []; 367 $_[0]->emit 368} 369 370sub end_over_block { $_[0]{'scratch'} .= '</ul>'; $_[0]->emit } 371 372sub end_over_number { 373 $_[0]{'scratch'} = "</li>\n" if ( pop @{$_[0]{'in_li'}} ); 374 $_[0]{'scratch'} .= '</ol>'; 375 pop @{$_[0]{'in_li'}}; 376 $_[0]->emit; 377} 378 379sub end_over_bullet { 380 $_[0]{'scratch'} = "</li>\n" if ( pop @{$_[0]{'in_li'}} ); 381 $_[0]{'scratch'} .= '</ul>'; 382 pop @{$_[0]{'in_li'}}; 383 $_[0]->emit; 384} 385 386sub end_over_text { 387 if ($_[0]{'in_dd'}[ $_[0]{'dl_level'} ]) { 388 $_[0]{'scratch'} = "</dd>\n"; 389 $_[0]{'in_dd'}[ $_[0]{'dl_level'} ] = 0; 390 } 391 $_[0]{'scratch'} .= '</dl>'; 392 $_[0]{'dl_level'}--; 393 $_[0]->emit; 394} 395 396# . . . . . Now the actual formatters: 397 398sub end_Para { $_[0]{'scratch'} .= '</p>'; $_[0]->emit } 399sub end_Verbatim { 400 $_[0]{'scratch'} .= '</code></pre>'; 401 $_[0]->emit; 402} 403 404sub _end_head { 405 my $h = delete $_[0]{in_head}; 406 407 my $add = $_[0]->html_h_level; 408 $add = 1 unless defined $add; 409 $h += $add - 1; 410 411 my $id = $_[0]->idify($_[0]{scratch}); 412 my $text = $_[0]{scratch}; 413 $_[0]{'scratch'} = $_[0]->backlink && ($h - $add == 0) 414 # backlinks enabled && =head1 415 ? qq{<a href="#_podtop_"><h$h id="$id">$text</h$h></a>} 416 : qq{<h$h id="$id">$text</h$h>}; 417 $_[0]->emit; 418 push @{ $_[0]{'to_index'} }, [$h, $id, $text]; 419} 420 421sub end_head1 { shift->_end_head(@_); } 422sub end_head2 { shift->_end_head(@_); } 423sub end_head3 { shift->_end_head(@_); } 424sub end_head4 { shift->_end_head(@_); } 425 426sub end_item_bullet { $_[0]{'scratch'} .= '</p>'; $_[0]->emit } 427sub end_item_number { $_[0]{'scratch'} .= '</p>'; $_[0]->emit } 428 429sub end_item_text { 430 # idify and anchor =item content if wanted 431 my $dt_id = $_[0]{'anchor_items'} 432 ? ' id="'. $_[0]->idify($_[0]{'scratch'}) .'"' 433 : ''; 434 435 # reset scratch 436 my $text = $_[0]{scratch}; 437 $_[0]{'scratch'} = ''; 438 439 if ($_[0]{'in_dd'}[ $_[0]{'dl_level'} ]) { 440 $_[0]{'scratch'} = "</dd>\n"; 441 $_[0]{'in_dd'}[ $_[0]{'dl_level'} ] = 0; 442 } 443 444 $_[0]{'scratch'} .= qq{<dt$dt_id>$text</dt>\n<dd>}; 445 $_[0]{'in_dd'}[ $_[0]{'dl_level'} ] = 1; 446 $_[0]->emit; 447} 448 449# This handles =begin and =for blocks of all kinds. 450sub start_for { 451 my ($self, $flags) = @_; 452 453 push @{ $self->{__region_targets} }, $flags->{target_matching}; 454 455 unless ($self->__in_literal_xhtml_region) { 456 $self->{scratch} .= '<div'; 457 $self->{scratch} .= qq( class="$flags->{target}") if $flags->{target}; 458 $self->{scratch} .= '>'; 459 } 460 461 $self->emit; 462 463} 464sub end_for { 465 my ($self) = @_; 466 467 $self->{'scratch'} .= '</div>' unless $self->__in_literal_xhtml_region; 468 469 pop @{ $self->{__region_targets} }; 470 $self->emit; 471} 472 473sub start_Document { 474 my ($self) = @_; 475 if (defined $self->html_header) { 476 $self->{'scratch'} .= $self->html_header; 477 $self->emit unless $self->html_header eq ""; 478 } else { 479 my ($doctype, $title, $metatags, $bodyid); 480 $doctype = $self->html_doctype || ''; 481 $title = $self->force_title || $self->title || $self->default_title || ''; 482 $metatags = $self->html_header_tags || ''; 483 if (my $css = $self->html_css) { 484 $metatags .= $css; 485 if ($css !~ /<link/) { 486 # this is required to be compatible with Pod::Simple::BatchHTML 487 $metatags .= '<link rel="stylesheet" href="' 488 . $self->encode_entities($css) . '" type="text/css" />'; 489 } 490 } 491 if ($self->html_javascript) { 492 $metatags .= qq{\n<script type="text/javascript" src="} . 493 $self->html_javascript . "'></script>"; 494 } 495 $bodyid = $self->backlink ? ' id="_podtop_"' : ''; 496 $self->{'scratch'} .= <<"HTML"; 497$doctype 498<html> 499<head> 500<title>$title</title> 501$metatags 502</head> 503<body$bodyid> 504HTML 505 $self->emit; 506 } 507} 508 509sub end_Document { 510 my ($self) = @_; 511 my $to_index = $self->{'to_index'}; 512 if ($self->index && @{ $to_index } ) { 513 my @out; 514 my $level = 0; 515 my $indent = -1; 516 my $space = ''; 517 my $id = ' id="index"'; 518 519 for my $h (@{ $to_index }, [0]) { 520 my $target_level = $h->[0]; 521 # Get to target_level by opening or closing ULs 522 if ($level == $target_level) { 523 $out[-1] .= '</li>'; 524 } elsif ($level > $target_level) { 525 $out[-1] .= '</li>' if $out[-1] =~ /^\s+<li>/; 526 while ($level > $target_level) { 527 --$level; 528 push @out, (' ' x --$indent) . '</li>' if @out && $out[-1] =~ m{^\s+<\/ul}; 529 push @out, (' ' x --$indent) . '</ul>'; 530 } 531 push @out, (' ' x --$indent) . '</li>' if $level; 532 } else { 533 while ($level < $target_level) { 534 ++$level; 535 push @out, (' ' x ++$indent) . '<li>' if @out && $out[-1]=~ /^\s*<ul/; 536 push @out, (' ' x ++$indent) . "<ul$id>"; 537 $id = ''; 538 } 539 ++$indent; 540 } 541 542 next unless $level; 543 $space = ' ' x $indent; 544 push @out, sprintf '%s<li><a href="#%s">%s</a>', 545 $space, $h->[1], $h->[2]; 546 } 547 # Splice the index in between the HTML headers and the first element. 548 my $offset = defined $self->html_header ? $self->html_header eq '' ? 0 : 1 : 1; 549 splice @{ $self->{'output'} }, $offset, 0, join "\n", @out; 550 } 551 552 if (defined $self->html_footer) { 553 $self->{'scratch'} .= $self->html_footer; 554 $self->emit unless $self->html_footer eq ""; 555 } else { 556 $self->{'scratch'} .= "</body>\n</html>"; 557 $self->emit; 558 } 559 560 if ($self->index) { 561 print {$self->{'output_fh'}} join ("\n\n", @{ $self->{'output'} }), "\n\n"; 562 @{$self->{'output'}} = (); 563 } 564 565} 566 567# Handling code tags 568sub start_B { $_[0]{'scratch'} .= '<b>' } 569sub end_B { $_[0]{'scratch'} .= '</b>' } 570 571sub start_C { $_[0]{'scratch'} .= '<code>' } 572sub end_C { $_[0]{'scratch'} .= '</code>' } 573 574sub start_F { $_[0]{'scratch'} .= '<i>' } 575sub end_F { $_[0]{'scratch'} .= '</i>' } 576 577sub start_I { $_[0]{'scratch'} .= '<i>' } 578sub end_I { $_[0]{'scratch'} .= '</i>' } 579 580sub start_L { 581 my ($self, $flags) = @_; 582 my ($type, $to, $section) = @{$flags}{'type', 'to', 'section'}; 583 my $url = $self->encode_entities( 584 $type eq 'url' ? $to 585 : $type eq 'pod' ? $self->resolve_pod_page_link($to, $section) 586 : $type eq 'man' ? $self->resolve_man_page_link($to, $section) 587 : undef 588 ); 589 590 # If it's an unknown type, use an attribute-less <a> like HTML.pm. 591 $self->{'scratch'} .= '<a' . ($url ? ' href="'. $url . '">' : '>'); 592} 593 594sub end_L { $_[0]{'scratch'} .= '</a>' } 595 596sub start_S { $_[0]{'scratch'} .= '<span style="white-space: nowrap;">' } 597sub end_S { $_[0]{'scratch'} .= '</span>' } 598 599sub emit { 600 my($self) = @_; 601 if ($self->index) { 602 push @{ $self->{'output'} }, $self->{'scratch'}; 603 } else { 604 print {$self->{'output_fh'}} $self->{'scratch'}, "\n\n"; 605 } 606 $self->{'scratch'} = ''; 607 return; 608} 609 610=head2 resolve_pod_page_link 611 612 my $url = $pod->resolve_pod_page_link('Net::Ping', 'INSTALL'); 613 my $url = $pod->resolve_pod_page_link('perlpodspec'); 614 my $url = $pod->resolve_pod_page_link(undef, 'SYNOPSIS'); 615 616Resolves a POD link target (typically a module or POD file name) and section 617name to a URL. The resulting link will be returned for the above examples as: 618 619 http://search.cpan.org/perldoc?Net::Ping#INSTALL 620 http://search.cpan.org/perldoc?perlpodspec 621 #SYNOPSIS 622 623Note that when there is only a section argument the URL will simply be a link 624to a section in the current document. 625 626=cut 627 628sub resolve_pod_page_link { 629 my ($self, $to, $section) = @_; 630 return undef unless defined $to || defined $section; 631 if (defined $section) { 632 $section = '#' . $self->idify($self->encode_entities($section), 1); 633 return $section unless defined $to; 634 } else { 635 $section = '' 636 } 637 638 return ($self->perldoc_url_prefix || '') 639 . $self->encode_entities($to) . $section 640 . ($self->perldoc_url_postfix || ''); 641} 642 643=head2 resolve_man_page_link 644 645 my $url = $pod->resolve_man_page_link('crontab(5)', 'EXAMPLE CRON FILE'); 646 my $url = $pod->resolve_man_page_link('crontab'); 647 648Resolves a man page link target and numeric section to a URL. The resulting 649link will be returned for the above examples as: 650 651 http://man.he.net/man5/crontab 652 http://man.he.net/man1/crontab 653 654Note that the first argument is required. The section number will be parsed 655from it, and if it's missing will default to 1. The second argument is 656currently ignored, as L<man.he.net|http://man.he.net> does not currently 657include linkable IDs or anchor names in its pages. Subclass to link to a 658different man page HTTP server. 659 660=cut 661 662sub resolve_man_page_link { 663 my ($self, $to, $section) = @_; 664 return undef unless defined $to; 665 my ($page, $part) = $to =~ /^([^(]+)(?:[(](\d+)[)])?$/; 666 return undef unless $page; 667 return ($self->man_url_prefix || '') 668 . ($part || 1) . "/" . $self->encode_entities($page) 669 . ($self->man_url_postfix || ''); 670 671} 672 673=head2 idify 674 675 my $id = $pod->idify($text); 676 my $hash = $pod->idify($text, 1); 677 678This method turns an arbitrary string into a valid XHTML ID attribute value. 679The rules enforced, following 680L<http://webdesign.about.com/od/htmltags/a/aa031707.htm>, are: 681 682=over 683 684=item * 685 686The id must start with a letter (a-z or A-Z) 687 688=item * 689 690All subsequent characters can be letters, numbers (0-9), hyphens (-), 691underscores (_), colons (:), and periods (.). 692 693=item * 694 695Each id must be unique within the document. 696 697=back 698 699In addition, the returned value will be unique within the context of the 700Pod::Simple::XHTML object unless a second argument is passed a true value. ID 701attributes should always be unique within a single XHTML document, but pass 702the true value if you are creating not an ID but a URL hash to point to 703an ID (i.e., if you need to put the "#foo" in C<< <a href="#foo">foo</a> >>. 704 705=cut 706 707sub idify { 708 my ($self, $t, $not_unique) = @_; 709 for ($t) { 710 s/<[^>]+>//g; # Strip HTML. 711 s/&[^;]+;//g; # Strip entities. 712 s/^\s+//; s/\s+$//; # Strip white space. 713 s/^([^a-zA-Z]+)$/pod$1/; # Prepend "pod" if no valid chars. 714 s/^[^a-zA-Z]+//; # First char must be a letter. 715 s/[^-a-zA-Z0-9_:.]+/-/g; # All other chars must be valid. 716 } 717 return $t if $not_unique; 718 my $i = ''; 719 $i++ while $self->{ids}{"$t$i"}++; 720 return "$t$i"; 721} 722 723=head2 batch_mode_page_object_init 724 725 $pod->batch_mode_page_object_init($batchconvobj, $module, $infile, $outfile, $depth); 726 727Called by L<Pod::Simple::HTMLBatch> so that the class has a chance to 728initialize the converter. Internally it sets the C<batch_mode> property to 729true and sets C<batch_mode_current_level()>, but Pod::Simple::XHTML does not 730currently use those features. Subclasses might, though. 731 732=cut 733 734sub batch_mode_page_object_init { 735 my ($self, $batchconvobj, $module, $infile, $outfile, $depth) = @_; 736 $self->batch_mode(1); 737 $self->batch_mode_current_level($depth); 738 return $self; 739} 740 741sub html_header_after_title { 742} 743 744 7451; 746 747__END__ 748 749=head1 SEE ALSO 750 751L<Pod::Simple>, L<Pod::Simple::Text>, L<Pod::Spell> 752 753=head1 SUPPORT 754 755Questions or discussion about POD and Pod::Simple should be sent to the 756pod-people@perl.org mail list. Send an empty email to 757pod-people-subscribe@perl.org to subscribe. 758 759This module is managed in an open GitHub repository, 760L<http://github.com/theory/pod-simple/>. Feel free to fork and contribute, or 761to clone L<git://github.com/theory/pod-simple.git> and send patches! 762 763Patches against Pod::Simple are welcome. Please send bug reports to 764<bug-pod-simple@rt.cpan.org>. 765 766=head1 COPYRIGHT AND DISCLAIMERS 767 768Copyright (c) 2003-2005 Allison Randal. 769 770This library is free software; you can redistribute it and/or modify it 771under the same terms as Perl itself. 772 773This program is distributed in the hope that it will be useful, but 774without any warranty; without even the implied warranty of 775merchantability or fitness for a particular purpose. 776 777=head1 ACKNOWLEDGEMENTS 778 779Thanks to L<Hurricane Electric|http://he.net/> for permission to use its 780L<Linux man pages online|http://man.he.net/> site for man page links. 781 782Thanks to L<search.cpan.org|http://search.cpan.org/> for permission to use the 783site for Perl module links. 784 785=head1 AUTHOR 786 787Pod::Simpele::XHTML was created by Allison Randal <allison@perl.org>. 788 789Pod::Simple was created by Sean M. Burke <sburke@cpan.org>. 790But don't bother him, he's retired. 791 792Pod::Simple is maintained by: 793 794=over 795 796=item * Allison Randal C<allison@perl.org> 797 798=item * Hans Dieter Pearcey C<hdp@cpan.org> 799 800=item * David E. Wheeler C<dwheeler@cpan.org> 801 802=back 803 804=cut 805