| 1 |
package Text::Markup::Pod; |
| 2 |
|
| 3 |
use 5.8.1; |
| 4 |
use strict; |
| 5 |
use warnings; |
| 6 |
use Text::Markup; |
| 7 |
use Pod::Simple::XHTML 3.15; |
| 8 |
|
| 9 |
sub import { |
| 10 |
# Replace the regex if passed one. |
| 11 |
Text::Markup->register( pod => $_[1] ) if $_[1]; |
| 12 |
} |
| 13 |
|
| 14 |
# Disable the use of HTML::Entities. |
| 15 |
$Pod::Simple::XHTML::HAS_HTML_ENTITIES = 0; |
| 16 |
|
| 17 |
our $VERSION = '0.41'; |
| 18 |
|
| 19 |
sub parser { |
| 20 |
my ($file, $encoding, $opts) = @_; |
| 21 |
my $p = Pod::Simple::XHTML->new; |
| 22 |
# Output everything as UTF-8. |
| 23 |
$p->html_header_tags('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'); |
| 24 |
$p->strip_verbatim_indent(sub { (sort map { /^(\s+)/ } @{$_[0]})[0] }); |
| •25 |
# Explicitly escape only the five HTML special characters; non-ASCII |
| 26 |
# characters remain raw UTF-8. Pod::Simple >= 3.48 escapes all non-ASCII |
| 27 |
# characters by default (perl-pod/pod-simple#188), which would change this |
| 28 |
# module's documented raw-UTF-8 output. |
| 29 |
$p->html_encode_chars(q{&<>"'}) if $p->can('html_encode_chars'); |
| 30 |
$p->output_string(\my $html); |
| 31 |
# Want user supplied options to override even these default behaviors, |
| 32 |
# if necessary |
| 33 |
my $opt = $opts ? { @$opts } : {}; |
| 34 |
foreach my $method ( keys %$opt ) { |
| 35 |
my $v = $opt->{$method}; |
| 36 |
$p->$method($v); |
| 37 |
} |
| 38 |
$p->parse_file($file); |
| 39 |
return unless $p->content_seen; |
| 40 |
utf8::encode($html); |
| 41 |
return $html; |
| 42 |
} |
| 43 |
|
| 44 |
1; |
| 45 |
__END__ |
| 46 |
|
| 47 |
=head1 Name |
| 48 |
|
| 49 |
Text::Markup::Pod - Pod parser for Text::Markup |
| 50 |
|
| 51 |
=head1 Synopsis |
| 52 |
|
| 53 |
use Text::Markup; |
| 54 |
my $pod = Text::Markup->new->parse(file => 'README.pod'); |
| 55 |
|
| 56 |
=head1 Description |
| 57 |
|
| 58 |
This is the L<Pod|perlpod> parser for L<Text::Markup>. It runs the file |
| 59 |
through L<Pod::Simple::XHTML> and returns the result. If the Pod contains any |
| 60 |
non-ASCII characters, the encoding must be declared either via a BOM or via |
| 61 |
the C<=encoding> tag. Text::Markup::Pod recognizes files with the following |
| 62 |
extensions as Pod: |
| 63 |
|
| 64 |
=over |
| 65 |
|
| 66 |
=item F<.pod> |
| 67 |
|
| 68 |
=item F<.pm> |
| 69 |
|
| 70 |
=item F<.pl> |
| 71 |
|
| 72 |
=back |
| 73 |
|
| 74 |
To change it the files it recognizes, load this module directly and pass a |
| 75 |
regular expression matching the desired extension(s), like so: |
| 76 |
|
| 77 |
use Text::Markup::Pod qr{cgi}; |
| 78 |
|
| 79 |
=head1 Options |
| 80 |
|
| 81 |
You may pass an arrayref of settings to this parser which changes the output returned. For example, |
| 82 |
to suppress an HTML header and footer, pass: |
| 83 |
|
| 84 |
my $pod_fragment = Text::Markup->new->parse( |
| 85 |
file => 'README.pod', |
| 86 |
options => [ |
| 87 |
html_header => '', |
| 88 |
html_footer => '', |
| 89 |
] |
| 90 |
); |
| 91 |
|
| 92 |
This implementation makes method calls to the L<Pod::Simple::XHTML> parser using the key as the method |
| 93 |
name and the value as the parameter list to pass. |
| 94 |
|
| 95 |
See L<Pod::Simple::XHTML> and L<Pod::Simple> for the full list of options and inherited options |
| 96 |
which can be manipulated. |
| 97 |
|
| 98 |
=head1 Author |
| 99 |
|
| 100 |
David E. Wheeler <[email protected]> |
| 101 |
|
| 102 |
=head1 Copyright and License |
| 103 |
|
| 104 |
Copyright (c) 2011-2025 David E. Wheeler. Some Rights Reserved. |
| 105 |
|
| 106 |
This module is free software; you can redistribute it and/or modify it under |
| 107 |
the same terms as Perl itself. |
| 108 |
|
| 109 |
=cut |