diff --git a/ext/Pod-Html/lib/Pod/Html.pm b/ext/Pod-Html/lib/Pod/Html.pm index 71555e723ca9..b825acadca9a 100644 --- a/ext/Pod-Html/lib/Pod/Html.pm +++ b/ext/Pod-Html/lib/Pod/Html.pm @@ -2,7 +2,7 @@ package Pod::Html; use strict; require Exporter; -our $VERSION = 1.25; +our $VERSION = 1.26; our @ISA = qw(Exporter); our @EXPORT = qw(pod2html htmlify); our @EXPORT_OK = qw(anchorify relativize_url); @@ -16,6 +16,7 @@ use File::Spec::Unix; use Getopt::Long; use Pod::Simple::Search; use Pod::Simple::SimpleTree (); +use Text::Tabs; use locale; # make \w work right in non-ASCII lands =head1 NAME @@ -367,6 +368,9 @@ sub pod2html { # set options for input parser my $parser = Pod::Simple::SimpleTree->new; + # Normalize whitespace indenting + $parser->strip_verbatim_indent(\&trim_leading_whitespace); + $parser->codes_in_verbatim(0); $parser->accept_targets(qw(html HTML)); $parser->no_errata_section(!$Poderrors); # note the inverse @@ -842,4 +846,24 @@ sub relativize_url { return $rel_path; } +# Remove any level of indentation (spaces or tabs) from each code block consistently +# Adapted from: https://metacpan.org/source/HAARG/MetaCPAN-Pod-XHTML-0.002001/lib/Pod/Simple/Role/StripVerbatimIndent.pm +sub trim_leading_whitespace { + my ($para) = @_; + + # Start by converting tabs to spaces + @$para = Text::Tabs::expand(@$para); + + # Find the line with the least amount of indent, as that's our "base" + my @indent_levels = (sort(map { $_ =~ /^( *)./mg } @$para)); + my $indent = $indent_levels[0] || ""; + + # Remove the "base" amount of indent from each line + foreach (@$para) { + $_ =~ s/^\Q$indent//mg; + } + + return; +} + 1; diff --git a/ext/Pod-Html/t/htmldir1.t b/ext/Pod-Html/t/htmldir1.t index 22632a18ba57..cd760a725d84 100644 --- a/ext/Pod-Html/t/htmldir1.t +++ b/ext/Pod-Html/t/htmldir1.t @@ -72,7 +72,7 @@ __DATA__
Verbatim B<means> verbatim.
+Verbatim B<means> verbatim.
Normal text, a link to nowhere,
diff --git a/ext/Pod-Html/t/htmlview.t b/ext/Pod-Html/t/htmlview.t index 1e3a304b368d..3b6c45119737 100644 --- a/ext/Pod-Html/t/htmlview.t +++ b/ext/Pod-Html/t/htmlview.t @@ -45,15 +45,15 @@ __DATA__ use My::Module;
+use My::Module;
- my $module = My::Module->new();
+my $module = My::Module->new();
This is the description.
- Here is a verbatim section.
+Here is a verbatim section.
This is some more regular text.
@@ -207,7 +207,7 @@ some textThis is an email link: mailto:foo@bar.com
- This is a link in a verbatim block <a href="http://perl.org"> Perl </a>
+This is a link in a verbatim block <a href="http://perl.org"> Perl </a>