| 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 |
$p->output_string(\my $html); |
| 26 |
# Want user supplied options to override even these default behaviors, |
| 27 |
# if necessary |
| 28 |
my $opt = $opts ? { @$opts } : {}; |
| 29 |
foreach my $method ( keys %$opt ) { |
| 30 |
my $v = $opt->{$method}; |
| 31 |
$p->$method($v); |
| 32 |
} |
| 33 |
$p->parse_file($file); |
| 34 |
return unless $p->content_seen; |
| 35 |
utf8::encode($html); |
| 36 |
return $html; |
| 37 |
} |
| 38 |
|
| 39 |
1; |
| 40 |
__END__ |
| 41 |
|
| 42 |
=head1 Name |
| 43 |
|
| 44 |
Text::Markup::Pod - Pod parser for Text::Markup |
| 45 |
|
| 46 |
=head1 Synopsis |
| 47 |
|
| 48 |
use Text::Markup; |
| 49 |
my $pod = Text::Markup->new->parse(file => 'README.pod'); |
| 50 |
|
| 51 |
=head1 Description |
| 52 |
|
| 53 |
This is the L<Pod|perlpod> parser for L<Text::Markup>. It runs the file |
| 54 |
through L<Pod::Simple::XHTML> and returns the result. If the Pod contains any |
| 55 |
non-ASCII characters, the encoding must be declared either via a BOM or via |
| 56 |
the C<=encoding> tag. Text::Markup::Pod recognizes files with the following |
| 57 |
extensions as Pod: |
| 58 |
|
| 59 |
=over |
| 60 |
|
| 61 |
=item F<.pod> |
| 62 |
|
| 63 |
=item F<.pm> |
| 64 |
|
| 65 |
=item F<.pl> |
| 66 |
|
| 67 |
=back |
| 68 |
|
| 69 |
To change it the files it recognizes, load this module directly and pass a |
| 70 |
regular expression matching the desired extension(s), like so: |
| 71 |
|
| 72 |
use Text::Markup::Pod qr{cgi}; |
| 73 |
|
| 74 |
=head1 Options |
| 75 |
|
| 76 |
You may pass an arrayref of settings to this parser which changes the output returned. For example, |
| 77 |
to suppress an HTML header and footer, pass: |
| 78 |
|
| 79 |
my $pod_fragment = Text::Markup->new->parse( |
| 80 |
file => 'README.pod', |
| 81 |
options => [ |
| 82 |
html_header => '', |
| 83 |
html_footer => '', |
| 84 |
] |
| 85 |
); |
| 86 |
|
| 87 |
This implementation makes method calls to the L<Pod::Simple::XHTML> parser using the key as the method |
| 88 |
name and the value as the parameter list to pass. |
| 89 |
|
| 90 |
See L<Pod::Simple::XHTML> and L<Pod::Simple> for the full list of options and inherited options |
| 91 |
which can be manipulated. |
| 92 |
|
| 93 |
=head1 Author |
| 94 |
|
| 95 |
David E. Wheeler <[email protected]> |
| 96 |
|
| 97 |
=head1 Copyright and License |
| 98 |
|
| 99 |
Copyright (c) 2011-2025 David E. Wheeler. Some Rights Reserved. |
| 100 |
|
| 101 |
This module is free software; you can redistribute it and/or modify it under |
| 102 |
the same terms as Perl itself. |
| 103 |
|
| 104 |
=cut |