Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion ext/Pod-Html/lib/Pod/Html.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
2 changes: 1 addition & 1 deletion ext/Pod-Html/t/htmldir1.t
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ __DATA__

<h1 id="LINKS">LINKS</h1>

<pre><code> Verbatim B&lt;means&gt; verbatim.</code></pre>
<pre><code>Verbatim B&lt;means&gt; verbatim.</code></pre>

<p>Normal text, a <a>link</a> to nowhere,</p>

Expand Down
8 changes: 4 additions & 4 deletions ext/Pod-Html/t/htmlview.t
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ __DATA__

<h1 id="SYNOPSIS">SYNOPSIS</h1>

<pre><code> use My::Module;
<pre><code>use My::Module;

my $module = My::Module-&gt;new();</code></pre>
my $module = My::Module-&gt;new();</code></pre>

<h1 id="DESCRIPTION">DESCRIPTION</h1>

<p>This is the description.</p>

<pre><code> Here is a verbatim section.</code></pre>
<pre><code>Here is a verbatim section.</code></pre>

<p>This is some more regular text.</p>

Expand Down Expand Up @@ -207,7 +207,7 @@ some text

<p>This is an email link: mailto:foo@bar.com</p>

<pre><code> This is a link in a verbatim block &lt;a href=&quot;http://perl.org&quot;&gt; Perl &lt;/a&gt;</code></pre>
<pre><code>This is a link in a verbatim block &lt;a href=&quot;http://perl.org&quot;&gt; Perl &lt;/a&gt;</code></pre>

<h1 id="SEE-ALSO">SEE ALSO</h1>

Expand Down