package Text::Markup::Pod;
use 5.8.1;
use strict;
use warnings;
use Text::Markup;
use Pod::Simple::XHTML 3.15;
sub import {
# Replace the regex if passed one.
Text::Markup->register( pod => $_[1] ) if $_[1];
}
# Disable the use of HTML::Entities.
$Pod::Simple::XHTML::HAS_HTML_ENTITIES = 0;
our $VERSION = '0.41';
sub parser {
my ($file, $encoding, $opts) = @_;
my $p = Pod::Simple::XHTML->new;
# Output everything as UTF-8.
$p->html_header_tags('');
$p->strip_verbatim_indent(sub { (sort map { /^(\s+)/ } @{$_[0]})[0] });
# Explicitly escape only the five HTML special characters; non-ASCII
# characters remain raw UTF-8. Pod::Simple >= 3.48 escapes all non-ASCII
# characters by default (perl-pod/pod-simple#188), which would change this
# module's documented raw-UTF-8 output.
$p->html_encode_chars(q{&<>"'}) if $p->can('html_encode_chars');
$p->output_string(\my $html);
# Want user supplied options to override even these default behaviors,
# if necessary
my $opt = $opts ? { @$opts } : {};
foreach my $method ( keys %$opt ) {
my $v = $opt->{$method};
$p->$method($v);
}
$p->parse_file($file);
return unless $p->content_seen;
utf8::encode($html);
return $html;
}
1;
__END__
=head1 Name
Text::Markup::Pod - Pod parser for Text::Markup
=head1 Synopsis
use Text::Markup;
my $pod = Text::Markup->new->parse(file => 'README.pod');
=head1 Description
This is the L parser for L. It runs the file
through L and returns the result. If the Pod contains any
non-ASCII characters, the encoding must be declared either via a BOM or via
the C<=encoding> tag. Text::Markup::Pod recognizes files with the following
extensions as Pod:
=over
=item F<.pod>
=item F<.pm>
=item F<.pl>
=back
To change it the files it recognizes, load this module directly and pass a
regular expression matching the desired extension(s), like so:
use Text::Markup::Pod qr{cgi};
=head1 Options
You may pass an arrayref of settings to this parser which changes the output returned. For example,
to suppress an HTML header and footer, pass:
my $pod_fragment = Text::Markup->new->parse(
file => 'README.pod',
options => [
html_header => '',
html_footer => '',
]
);
This implementation makes method calls to the L parser using the key as the method
name and the value as the parameter list to pass.
See L and L for the full list of options and inherited options
which can be manipulated.
=head1 Author
David E. Wheeler
=head1 Copyright and License
Copyright (c) 2011-2025 David E. Wheeler. Some Rights Reserved.
This module is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.
=cut