<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">=pod

=head1 NAME

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

=head1 SYNOPSIS

  use Pod::Simple::XHTML;

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

  ...

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

=head1 DESCRIPTION

This class is a formatter that takes Pod and renders it as XHTML
validating HTML.

This is a subclass of L&lt;Pod::Simple::Methody&gt; and inherits all its
methods. The implementation is entirely different than
L&lt;Pod::Simple::HTML&gt;, but it largely preserves the same interface.

=head2 Minimal code

  use Pod::Simple::XHTML;
  my $psx = Pod::Simple::XHTML-&gt;new;
  $psx-&gt;output_string(\my $html);
  $psx-&gt;parse_file('path/to/Module/Name.pm');
  open my $out, '&gt;', '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 C&lt;=encoding&gt; 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-&gt;html_charset('UTF-8');
use warnings;
  $psx-&gt;html_encode_chars(q{&amp;&lt;&gt;'"});

=cut

package Pod::Simple::XHTML;
use strict;
our $VERSION = '3.45';
use Pod::Simple::Methody ();
our @ISA = ('Pod::Simple::Methody');

our $HAS_HTML_ENTITIES;
BEGIN {
  $HAS_HTML_ENTITIES = eval "require HTML::Entities; 1";
}

my %entities = (
  q{&gt;} =&gt; 'gt',
  q{&lt;} =&gt; 'lt',
  q{'} =&gt; '#39',
  q{"} =&gt; 'quot',
  q{&amp;} =&gt; 'amp',
);

sub encode_entities {
  my $self = shift;
  my $ents = $self-&gt;html_encode_chars;
  return HTML::Entities::encode_entities( $_[0], $ents ) if $HAS_HTML_ENTITIES;
  if (defined $ents) {
      $ents =~ s,(?&lt;!\\)([]/]),\\$1,g;
      $ents =~ s,(?&lt;!\\)\\\z,\\\\,;
  } else {
      $ents = join '', keys %entities;
  }
  my $str = $_[0];
  $str =~ s/([$ents])/'&amp;' . ($entities{$1} || sprintf '#x%X', ord $1) . ';'/ge;
  return $str;
}

my %entity_to_char = reverse %entities;
my ($entity_re) = map qr{$_}, join '|', map quotemeta, sort keys %entity_to_char;

sub decode_entities {
  my ($self, $string) = @_;
  return HTML::Entities::decode_entities( $string ) if $HAS_HTML_ENTITIES;

  $string =~ s{&amp;(?:($entity_re)|#x([0123456789abcdefABCDEF]+)|#([0123456789]+));}{
      defined $1 ? $entity_to_char{$1}
    : defined $2 ? chr(hex($2))
    : defined $3 ? chr($3)
    : die;
  }ge;

  return $string;
}

sub encode_url {
  my ($self, $string) = @_;

  $string =~ s{([^-_.!~*()abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZZ0123456789])}{
    sprintf('%%%02X', ord($1))
  }eg;

  return $string;
}

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

=head1 METHODS

Pod::Simple::XHTML offers a number of methods that modify the format of
the HTML output. Call these after creating the parser object, but before
the call to C&lt;parse_file&gt;:

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

=head2 perldoc_url_prefix

In turning L&lt;Foo::Bar&gt; into http://whatever/Foo%3a%3aBar, what
to put before the "Foo%3a%3aBar". The default value is
"https://metacpan.org/pod/".

=head2 perldoc_url_postfix

What to put after "Foo%3a%3aBar" in the URL. This option is not set by
default.

=head2 man_url_prefix

In turning C&lt;&lt; L&lt;crontab(5)&gt; &gt;&gt; into http://whatever/man/1/crontab, what
to put before the "1/crontab". The default value is
"http://man.he.net/man".

=head2 man_url_postfix

What to put after "1/crontab" in the URL. This option is not set by default.

=head2 title_prefix, title_postfix

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

=head2 html_css

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

The URL or relative path of a CSS file to include. This option is not
set by default.

=head2 html_javascript

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

=head2 html_doctype

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

=head2 html_charset

The character set to declare in the Content-Type meta tag created by default
for C&lt;html_header_tags&gt;. Note that this option will be ignored if the value of
C&lt;html_header_tags&gt; is changed. Defaults to "ISO-8859-1".

=head2 html_header_tags

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

  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;

Add additional meta tags here, or blocks of inline CSS or JavaScript
(wrapped in the appropriate tags).

=head3 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 C&lt;encode_entities&gt; function of L&lt;HTML::Entities&gt;. If
L&lt;HTML::Entities&gt; is not installed, then any characters other than C&lt;&amp;&lt;&gt;"'&gt;
will be encoded numerically.

=head2 html_h_level

This is the level of HTML "Hn" element to which a Pod "head1" corresponds.  For
example, if C&lt;html_h_level&gt; is set to 2, a head1 will produce an H2, a head2
will produce an H3, and so on.

=head2 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 &amp;-escaped.

=head2 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 &amp;-escaped.

=head2 html_header, html_footer

Set the HTML output at the beginning and end of each file. The default
header includes a title, a doctype tag (if C&lt;html_doctype&gt; is set), a
content tag (customized by C&lt;html_header_tags&gt;), a tag for a CSS file
(if C&lt;html_css&gt; is set), and a tag for a Javascript file (if
C&lt;html_javascript&gt; is set). The default footer simply closes the C&lt;html&gt;
and C&lt;body&gt; tags.

The options listed above customize parts of the default header, but
setting C&lt;html_header&gt; or C&lt;html_footer&gt; 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.

=head2 index

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

=head2 anchor_items

Whether to anchor every definition C&lt;=item&gt; directive. This needs to be
enabled if you want to be able to link to specific C&lt;=item&gt; directives, which
are output as C&lt;&lt; &lt;dt&gt; &gt;&gt; elements. Disabled by default.

=head2 backlink

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

=cut

__PACKAGE__-&gt;_accessorize(
 'perldoc_url_prefix',
 'perldoc_url_postfix',
 'man_url_prefix',
 'man_url_postfix',
 'title_prefix',  'title_postfix',
 'html_css',
 'html_javascript',
 'html_doctype',
 'html_charset',
 'html_encode_chars',
 'html_h_level',
 'title', # Used internally for the title extracted from the content
 'default_title',
 'force_title',
 'html_header',
 'html_footer',
 'index',
 'anchor_items',
 'backlink',
 'batch_mode', # whether we're in batch mode
 'batch_mode_current_level',
    # When in batch mode, how deep the current module is: 1 for "LWP",
    #  2 for "LWP::Procotol", 3 for "LWP::Protocol::GHTTP", etc
);

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

=head1 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.

=cut

sub new {
  my $self = shift;
  my $new = $self-&gt;SUPER::new(@_);
  $new-&gt;{'output_fh'} ||= *STDOUT{IO};
  $new-&gt;perldoc_url_prefix('https://metacpan.org/pod/');
  $new-&gt;man_url_prefix('http://man.he.net/man');
  $new-&gt;html_charset('ISO-8859-1');
  $new-&gt;nix_X_codes(1);
  $new-&gt;{'scratch'} = '';
  $new-&gt;{'to_index'} = [];
  $new-&gt;{'output'} = [];
  $new-&gt;{'saved'} = [];
  $new-&gt;{'ids'} = { '_podtop_' =&gt; 1 }; # used in &lt;body&gt;
  $new-&gt;{'in_li'} = [];

  $new-&gt;{'__region_targets'}  = [];
  $new-&gt;{'__literal_targets'} = {};
  $new-&gt;accept_targets_as_html( 'html', 'HTML' );

  return $new;
}

sub html_header_tags {
    my $self = shift;
    return $self-&gt;{html_header_tags} = shift if @_;
    return $self-&gt;{html_header_tags}
        ||= '&lt;meta http-equiv="Content-Type" content="text/html; charset='
            . $self-&gt;html_charset . '" /&gt;';
}

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

=head2 handle_text

This method handles the body of text within any element: it's the body
of a paragraph, or everything between a "=begin" tag and the
corresponding "=end" 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
HTML tables from an extended version of POD.

So, let's say you want to add a custom element called 'foo'. In your
subclass's C&lt;new&gt; method, after calling C&lt;SUPER::new&gt; you'd call:

  $new-&gt;accept_targets_as_text( 'foo' );

Then override the C&lt;start_for&gt; method in the subclass to check for when
"$flags-&gt;{'target'}" is equal to 'foo' and set a flag that marks that
you're in a foo block (maybe "$self-&gt;{'in_foo'} = 1"). Then override the
C&lt;handle_text&gt; 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-&gt;{'in_foo'}) {
          $self-&gt;{'scratch'} .= build_foo_html($text);
          return;
      }
      $self-&gt;SUPER::handle_text($text);
  }

=head2 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&lt;start_code&gt; and C&lt;end_code&gt; emits the C&lt;code&gt; tags
before and after C&lt;handle_code&gt; is invoked, so you might want to override these
together with C&lt;handle_code&gt; 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&lt;&lt; CE&lt;lt&gt;...&gt; &gt;&gt; sequence.  In between the
calls to C&lt;handle_code&gt; other markup tags might have been emitted in that
case.  The same is true for verbatim sections if the C&lt;codes_in_verbatim&gt;
option is turned on.

=head2 accept_targets_as_html

This method behaves like C&lt;accept_targets_as_text&gt;, but also marks the region
as one whose content should be emitted literally, without HTML entity escaping
or wrapping in a C&lt;div&gt; element.

=cut

sub __in_literal_xhtml_region {
    return unless @{ $_[0]{__region_targets} };
    my $target = $_[0]{__region_targets}[-1];
    return $_[0]{__literal_targets}{ $target };
}

sub accept_targets_as_html {
    my ($self, @targets) = @_;
    $self-&gt;accept_targets(@targets);
    $self-&gt;{__literal_targets}{$_} = 1 for @targets;
}

sub handle_text {
    # escape special characters in HTML (&lt;, &gt;, &amp;, etc)
    my $text = $_[1];
    my $html;
    if ($_[0]-&gt;__in_literal_xhtml_region) {
        $html = $text;
        $text =~ s{&lt;[^&gt;]+?&gt;}{}g;
        $text = $_[0]-&gt;decode_entities($text);
    }
    else {
        $html = $_[0]-&gt;encode_entities($text);
    }

    if ($_[0]{'in_code'} &amp;&amp; @{$_[0]{'in_code'}}) {
        # Intentionally use the raw text in $_[1], even if we're not in a
        # literal xhtml region, since handle_code calls encode_entities.
        $_[0]-&gt;handle_code( $_[1], $_[0]{'in_code'}[-1] );
    } else {
        if ($_[0]-&gt;{in_for}) {
            my $newlines = $_[0]-&gt;__in_literal_xhtml_region ? "\n\n" : '';
            if ($_[0]-&gt;{started_for}) {
                if ($html =~ /\S/) {
                    delete $_[0]-&gt;{started_for};
                    $_[0]{'scratch'} .= $html . $newlines;
                }
                # Otherwise, append nothing until we have something to append.
            } else {
                # The parser sometimes preserves newlines and sometimes doesn't!
                $html =~ s/\n\z//;
                $_[0]{'scratch'} .= $html . $newlines;
            }
        } else {
            # Just plain text.
            $_[0]{'scratch'} .= $html;
        }
    }

    $_[0]{hhtml} .= $html if $_[0]{'in_head'};
    $_[0]{htext} .= $text if $_[0]{'in_head'};
    $_[0]{itext} .= $text if $_[0]{'in_item_text'};
}

sub start_code {
    $_[0]{'scratch'} .= '&lt;code&gt;';
}

sub end_code {
    $_[0]{'scratch'} .= '&lt;/code&gt;';
}

sub handle_code {
    $_[0]{'scratch'} .= $_[0]-&gt;encode_entities( $_[1] );
}

sub start_Para {
    $_[0]{'scratch'} .= '&lt;p&gt;';
}

sub start_Verbatim {
    $_[0]{'scratch'} = '&lt;pre&gt;';
    push(@{$_[0]{'in_code'}}, 'Verbatim');
    $_[0]-&gt;start_code($_[0]{'in_code'}[-1]);
}

sub start_head1 {  $_[0]{'in_head'} = 1; $_[0]{htext} = $_[0]{hhtml} = ''; }
sub start_head2 {  $_[0]{'in_head'} = 2; $_[0]{htext} = $_[0]{hhtml} = ''; }
sub start_head3 {  $_[0]{'in_head'} = 3; $_[0]{htext} = $_[0]{hhtml} = ''; }
sub start_head4 {  $_[0]{'in_head'} = 4; $_[0]{htext} = $_[0]{hhtml} = ''; }
sub start_head5 {  $_[0]{'in_head'} = 5; $_[0]{htext} = $_[0]{hhtml} = ''; }
sub start_head6 {  $_[0]{'in_head'} = 6; $_[0]{htext} = $_[0]{hhtml} = ''; }

sub start_item_number {
    $_[0]{'scratch'} = "&lt;/li&gt;\n" if ($_[0]{'in_li'}-&gt;[-1] &amp;&amp; pop @{$_[0]{'in_li'}});
    $_[0]{'scratch'} .= '&lt;li&gt;&lt;p&gt;';
    push @{$_[0]{'in_li'}}, 1;
}

sub start_item_bullet {
    $_[0]{'scratch'} = "&lt;/li&gt;\n" if ($_[0]{'in_li'}-&gt;[-1] &amp;&amp; pop @{$_[0]{'in_li'}});
    $_[0]{'scratch'} .= '&lt;li&gt;&lt;p&gt;';
    push @{$_[0]{'in_li'}}, 1;
}

sub start_item_text   {
    $_[0]{'in_item_text'} = 1; $_[0]{itext} = '';
    # see end_item_text
}

sub start_over_bullet { $_[0]{'scratch'} = '&lt;ul&gt;'; push @{$_[0]{'in_li'}}, 0; $_[0]-&gt;emit }
sub start_over_block  { $_[0]{'scratch'} = '&lt;ul&gt;'; $_[0]-&gt;emit }
sub start_over_number { $_[0]{'scratch'} = '&lt;ol&gt;'; push @{$_[0]{'in_li'}}, 0; $_[0]-&gt;emit }
sub start_over_text   {
    $_[0]{'scratch'} = '&lt;dl&gt;';
    $_[0]{'dl_level'}++;
    $_[0]{'in_dd'} ||= [];
    $_[0]-&gt;emit
}

sub end_over_block  { $_[0]{'scratch'} .= '&lt;/ul&gt;'; $_[0]-&gt;emit }

sub end_over_number   {
    $_[0]{'scratch'} = "&lt;/li&gt;\n" if ( pop @{$_[0]{'in_li'}} );
    $_[0]{'scratch'} .= '&lt;/ol&gt;';
    pop @{$_[0]{'in_li'}};
    $_[0]-&gt;emit;
}

sub end_over_bullet   {
    $_[0]{'scratch'} = "&lt;/li&gt;\n" if ( pop @{$_[0]{'in_li'}} );
    $_[0]{'scratch'} .= '&lt;/ul&gt;';
    pop @{$_[0]{'in_li'}};
    $_[0]-&gt;emit;
}

sub end_over_text   {
    if ($_[0]{'in_dd'}[ $_[0]{'dl_level'} ]) {
        $_[0]{'scratch'} = "&lt;/dd&gt;\n";
        $_[0]{'in_dd'}[ $_[0]{'dl_level'} ] = 0;
    }
    $_[0]{'scratch'} .= '&lt;/dl&gt;';
    $_[0]{'dl_level'}--;
    $_[0]-&gt;emit;
}

# . . . . . Now the actual formatters:

sub end_Para     { $_[0]{'scratch'} .= '&lt;/p&gt;'; $_[0]-&gt;emit }
sub end_Verbatim {
    $_[0]-&gt;end_code(pop(@{$_[0]-&gt;{'in_code'}}));
    $_[0]{'scratch'} .= '&lt;/pre&gt;';
    $_[0]-&gt;emit;
}

sub _end_head {
    my $h = delete $_[0]{in_head};

    my $add = $_[0]-&gt;html_h_level;
    $add = 1 unless defined $add;
    $h += $add - 1;

    my $id = $_[0]-&gt;idify(delete $_[0]{htext});
    my $text = $_[0]{scratch};
    my $head = qq{&lt;h$h id="} . $_[0]-&gt;encode_entities($id) . qq{"&gt;$text&lt;/h$h&gt;};
    $_[0]{'scratch'} = $_[0]-&gt;backlink &amp;&amp; ($h - $add == 0)
                         # backlinks enabled &amp;&amp; =head1
                         ? qq{&lt;a href="#_podtop_"&gt;$head&lt;/a&gt;}
                         : $head;
    $_[0]-&gt;emit;
    push @{ $_[0]{'to_index'} }, [$h, $id, delete $_[0]{'hhtml'}];
}

sub end_head1       { shift-&gt;_end_head(@_); }
sub end_head2       { shift-&gt;_end_head(@_); }
sub end_head3       { shift-&gt;_end_head(@_); }
sub end_head4       { shift-&gt;_end_head(@_); }
sub end_head5       { shift-&gt;_end_head(@_); }
sub end_head6       { shift-&gt;_end_head(@_); }

sub end_item_bullet { $_[0]{'scratch'} .= '&lt;/p&gt;'; $_[0]-&gt;emit }
sub end_item_number { $_[0]{'scratch'} .= '&lt;/p&gt;'; $_[0]-&gt;emit }

sub end_item_text   {
    # idify and anchor =item content if wanted
    my $dt_id = $_[0]{'anchor_items'}
                 ? ' id="'. $_[0]-&gt;encode_entities($_[0]-&gt;idify($_[0]{'itext'})) .'"'
                 : '';

    # reset scratch
    my $text = $_[0]{scratch};
    $_[0]{'scratch'} = '';

    if ($_[0]{'in_dd'}[ $_[0]{'dl_level'} ]) {
        $_[0]{'scratch'} = "&lt;/dd&gt;\n";
        $_[0]{'in_dd'}[ $_[0]{'dl_level'} ] = 0;
    }

    $_[0]{'scratch'} .= qq{&lt;dt$dt_id&gt;$text&lt;/dt&gt;\n&lt;dd&gt;};
    $_[0]{'in_dd'}[ $_[0]{'dl_level'} ] = 1;
    $_[0]-&gt;emit;
}

# This handles =begin and =for blocks of all kinds.
sub start_for {
  my ($self, $flags) = @_;

  push @{ $self-&gt;{__region_targets} }, $flags-&gt;{target_matching};
  $self-&gt;{started_for} = 1;
  $self-&gt;{in_for} = 1;

  unless ($self-&gt;__in_literal_xhtml_region) {
    $self-&gt;{scratch} .= '&lt;div';
    $self-&gt;{scratch} .= qq( class="$flags-&gt;{target}") if $flags-&gt;{target};
    $self-&gt;{scratch} .= "&gt;\n\n";
  }
}

sub end_for {
  my ($self) = @_;
  delete $self-&gt;{started_for};
  delete $self-&gt;{in_for};

  if ($self-&gt;__in_literal_xhtml_region) {
    # Remove trailine newlines.
    $self-&gt;{'scratch'} =~ s/\s+\z//s;
  } else {
    $self-&gt;{'scratch'} .= '&lt;/div&gt;';
  }

  pop @{ $self-&gt;{__region_targets} };
  $self-&gt;emit;
}

sub start_Document {
  my ($self) = @_;
  if (defined $self-&gt;html_header) {
    $self-&gt;{'scratch'} .= $self-&gt;html_header;
    $self-&gt;emit unless $self-&gt;html_header eq "";
  } else {
    my ($doctype, $title, $metatags, $bodyid);
    $doctype = $self-&gt;html_doctype || '';
    $title = $self-&gt;force_title || $self-&gt;title || $self-&gt;default_title || '';
    $metatags = $self-&gt;html_header_tags || '';
    if (my $css = $self-&gt;html_css) {
        if ($css !~ /&lt;link/) {
            # this is required to be compatible with Pod::Simple::BatchHTML
            $metatags .= '&lt;link rel="stylesheet" href="'
                . $self-&gt;encode_entities($css) . '" type="text/css" /&gt;';
        } else {
            $metatags .= $css;
        }
    }
    if ($self-&gt;html_javascript) {
      $metatags .= qq{\n&lt;script type="text/javascript" src="} .
                    $self-&gt;html_javascript . '"&gt;&lt;/script&gt;';
    }
    $bodyid = $self-&gt;backlink ? ' id="_podtop_"' : '';
    $self-&gt;{'scratch'} .= &lt;&lt;"HTML";
$doctype
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;$title&lt;/title&gt;
$metatags
&lt;/head&gt;
&lt;body$bodyid&gt;
HTML
    $self-&gt;emit;
  }
}

sub build_index {
    my ($self, $to_index) = @_;

    my @out;
    my $level  = 0;
    my $indent = -1;
    my $space  = '';
    my $id     = ' id="index"';

    for my $h (@{ $to_index }, [0]) {
        my $target_level = $h-&gt;[0];
        # Get to target_level by opening or closing ULs
        if ($level == $target_level) {
            $out[-1] .= '&lt;/li&gt;';
        } elsif ($level &gt; $target_level) {
            $out[-1] .= '&lt;/li&gt;' if $out[-1] =~ /^\s+&lt;li&gt;/;
            while ($level &gt; $target_level) {
                --$level;
                push @out, ('  ' x --$indent) . '&lt;/li&gt;' if @out &amp;&amp; $out[-1] =~ m{^\s+&lt;\/ul};
                push @out, ('  ' x --$indent) . '&lt;/ul&gt;';
            }
            push @out, ('  ' x --$indent) . '&lt;/li&gt;' if $level;
        } else {
            while ($level &lt; $target_level) {
                ++$level;
                push @out, ('  ' x ++$indent) . '&lt;li&gt;' if @out &amp;&amp; $out[-1]=~ /^\s*&lt;ul/;
                push @out, ('  ' x ++$indent) . "&lt;ul$id&gt;";
                $id = '';
            }
            ++$indent;
        }

        next unless $level;
        $space = '  '  x $indent;
        my $fragment = $self-&gt;encode_entities($self-&gt;encode_url($h-&gt;[1]));
        push @out, sprintf '%s&lt;li&gt;&lt;a href="#%s"&gt;%s&lt;/a&gt;',
            $space, $fragment, $h-&gt;[2];
    }

    return join "\n", @out;
}

sub end_Document   {
  my ($self) = @_;
  my $to_index = $self-&gt;{'to_index'};
  if ($self-&gt;index &amp;&amp; @{ $to_index } ) {
      my $index = $self-&gt;build_index($to_index);

      # Splice the index in between the HTML headers and the first element.
      my $offset = defined $self-&gt;html_header ? $self-&gt;html_header eq '' ? 0 : 1 : 1;
      splice @{ $self-&gt;{'output'} }, $offset, 0, $index;
  }

  if (defined $self-&gt;html_footer) {
    $self-&gt;{'scratch'} .= $self-&gt;html_footer;
    $self-&gt;emit unless $self-&gt;html_footer eq "";
  } else {
    $self-&gt;{'scratch'} .= "&lt;/body&gt;\n&lt;/html&gt;";
    $self-&gt;emit;
  }

  if ($self-&gt;index) {
      print {$self-&gt;{'output_fh'}} join ("\n\n", @{ $self-&gt;{'output'} }), "\n\n";
      @{$self-&gt;{'output'}} = ();
  }

}

# Handling code tags
sub start_B { $_[0]{'scratch'} .= '&lt;b&gt;' }
sub end_B   { $_[0]{'scratch'} .= '&lt;/b&gt;' }

sub start_C { push(@{$_[0]{'in_code'}}, 'C'); $_[0]-&gt;start_code($_[0]{'in_code'}[-1]); }
sub end_C   { $_[0]-&gt;end_code(pop(@{$_[0]{'in_code'}})); }

sub start_F { $_[0]{'scratch'} .= '&lt;i&gt;' }
sub end_F   { $_[0]{'scratch'} .= '&lt;/i&gt;' }

sub start_I { $_[0]{'scratch'} .= '&lt;i&gt;' }
sub end_I   { $_[0]{'scratch'} .= '&lt;/i&gt;' }

sub start_L {
  my ($self, $flags) = @_;
    my ($type, $to, $section) = @{$flags}{'type', 'to', 'section'};
    my $url = $self-&gt;encode_entities(
        $type eq 'url' ? $to
            : $type eq 'pod' ? $self-&gt;resolve_pod_page_link($to, $section)
            : $type eq 'man' ? $self-&gt;resolve_man_page_link($to, $section)
            :                  undef
    );

    # If it's an unknown type, use an attribute-less &lt;a&gt; like HTML.pm.
    $self-&gt;{'scratch'} .= '&lt;a' . ($url ? ' href="'. $url . '"&gt;' : '&gt;');
}

sub end_L   { $_[0]{'scratch'} .= '&lt;/a&gt;' }

sub start_S { $_[0]{'scratch'} .= '&lt;span style="white-space: nowrap;"&gt;' }
sub end_S   { $_[0]{'scratch'} .= '&lt;/span&gt;' }

sub emit {
  my($self) = @_;
  if ($self-&gt;index) {
      push @{ $self-&gt;{'output'} }, $self-&gt;{'scratch'};
  } else {
      print {$self-&gt;{'output_fh'}} $self-&gt;{'scratch'}, "\n\n";
  }
  $self-&gt;{'scratch'} = '';
  return;
}

=head2 resolve_pod_page_link

  my $url = $pod-&gt;resolve_pod_page_link('Net::Ping', 'INSTALL');
  my $url = $pod-&gt;resolve_pod_page_link('perlpodspec');
  my $url = $pod-&gt;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:

  https://metacpan.org/pod/Net::Ping#INSTALL
  https://metacpan.org/pod/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.

=cut

sub resolve_pod_page_link {
    my ($self, $to, $section) = @_;
    return undef unless defined $to || defined $section;
    if (defined $section) {
        my $id = $self-&gt;idify($section, 1);
        $section = '#' . $self-&gt;encode_url($id);
        return $section unless defined $to;
    } else {
        $section = ''
    }

    return ($self-&gt;perldoc_url_prefix || '')
        . $to . $section
        . ($self-&gt;perldoc_url_postfix || '');
}

=head2 resolve_man_page_link

  my $url = $pod-&gt;resolve_man_page_link('crontab(5)', 'EXAMPLE CRON FILE');
  my $url = $pod-&gt;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 L&lt;man.he.net|http://man.he.net&gt; does not currently
include linkable IDs or anchor names in its pages. Subclass to link to a
different man page HTTP server.

=cut

sub resolve_man_page_link {
    my ($self, $to, $section) = @_;
    return undef unless defined $to;
    my ($page, $part) = $to =~ /^([^(]+)(?:[(](\d+)[)])?$/;
    return undef unless $page;
    return ($self-&gt;man_url_prefix || '')
        . ($part || 1) . "/" . $self-&gt;encode_entities($page)
        . ($self-&gt;man_url_postfix || '');

}

=head2 idify

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

This method turns an arbitrary string into a valid XHTML ID attribute value.
The rules enforced, following
L&lt;http://webdesign.about.com/od/htmltags/a/aa031707.htm&gt;, are:

=over

=item *

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

=item *

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

=item *

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

=item *

Each id must be unique within the document.

=back

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 C&lt;&lt; &lt;a href="#foo"&gt;foo&lt;/a&gt; &gt;&gt;.

=cut

sub idify {
    my ($self, $t, $not_unique) = @_;
    for ($t) {
        s/[&lt;&gt;&amp;'"]//g;            # Strip HTML special characters
        s/^\s+//; s/\s+$//;      # Strip white space.
        s/^([^a-zA-Z]+)$/pod$1/; # Prepend "pod" if no valid chars.
        s/^[^a-zA-Z]+//;         # First char must be a letter.
        s/[^-a-zA-Z0-9_:.]+/-/g; # All other chars must be valid.
        s/[-:.]+$//;             # Strip trailing punctuation.
    }
    return $t if $not_unique;
    my $i = '';
    $i++ while $self-&gt;{ids}{"$t$i"}++;
    return "$t$i";
}

=head2 batch_mode_page_object_init

  $pod-&gt;batch_mode_page_object_init($batchconvobj, $module, $infile, $outfile, $depth);

Called by L&lt;Pod::Simple::HTMLBatch&gt; so that the class has a chance to
initialize the converter. Internally it sets the C&lt;batch_mode&gt; property to
true and sets C&lt;batch_mode_current_level()&gt;, but Pod::Simple::XHTML does not
currently use those features. Subclasses might, though.

=cut

sub batch_mode_page_object_init {
  my ($self, $batchconvobj, $module, $infile, $outfile, $depth) = @_;
  $self-&gt;batch_mode(1);
  $self-&gt;batch_mode_current_level($depth);
  return $self;
}

sub html_header_after_title {
}


1;

__END__

=head1 SEE ALSO

L&lt;Pod::Simple&gt;, L&lt;Pod::Simple::Text&gt;, L&lt;Pod::Spell&gt;

=head1 SUPPORT

Questions or discussion about POD and Pod::Simple should be sent to the
pod-people@perl.org mail list. Send an empty email to
pod-people-subscribe@perl.org to subscribe.

This module is managed in an open GitHub repository,
L&lt;https://github.com/perl-pod/pod-simple/&gt;. Feel free to fork and contribute, or
to clone L&lt;https://github.com/perl-pod/pod-simple.git&gt; and send patches!

Patches against Pod::Simple are welcome. Please send bug reports to
&lt;bug-pod-simple@rt.cpan.org&gt;.

=head1 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.

=head1 ACKNOWLEDGEMENTS

Thanks to L&lt;Hurricane Electric|http://he.net/&gt; for permission to use its
L&lt;Linux man pages online|http://man.he.net/&gt; site for man page links.

Thanks to L&lt;search.cpan.org|http://search.cpan.org/&gt; for permission to use the
site for Perl module links.

=head1 AUTHOR

Pod::Simpele::XHTML was created by Allison Randal &lt;allison@perl.org&gt;.

Pod::Simple was created by Sean M. Burke &lt;sburke@cpan.org&gt;.
But don't bother him, he's retired.

Pod::Simple is maintained by:

=over

=item * Allison Randal C&lt;allison@perl.org&gt;

=item * Hans Dieter Pearcey C&lt;hdp@cpan.org&gt;

=item * David E. Wheeler C&lt;dwheeler@cpan.org&gt;

=back

=cut
</pre></body></html>