From 320e3532033110bb49f0ac4f70c057bea10b63ba Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Mon, 3 Aug 2020 13:08:33 -0700 Subject: [PATCH 1/7] Make pod2html remove whitespace from literal blocks This brings pod2html functionality similar to how Metacpan handles whitespace --- ext/Pod-Html/lib/Pod/Html.pm | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/ext/Pod-Html/lib/Pod/Html.pm b/ext/Pod-Html/lib/Pod/Html.pm index 71555e723ca9..038050ffb75e 100644 --- a/ext/Pod-Html/lib/Pod/Html.pm +++ b/ext/Pod-Html/lib/Pod/Html.pm @@ -367,6 +367,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 +845,33 @@ sub relativize_url { return $rel_path; } +# Remove any level of indentation (spaces or tabs) from each code block consistently +# Borrowed from: https://metacpan.org/source/HAARG/MetaCPAN-Pod-XHTML-0.002001/lib/Pod/Simple/Role/StripVerbatimIndent.pm +sub trim_leading_whitespace { + my ($para) = @_; + my $tab_width = 4; + + # Start by converting tabs to spaces + for my $line (@$para) { + # Count how many tabs on the beginnging of the line + my ($tabs) = $line =~ /^(\t*)/; + my $tab_count = length($tabs); + + # Remove all the tabs, and add them back as spaces + $line =~ s/^\t+//g; + $line = (" " x ($tab_count * $tab_width)) . $line; + } + + # 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; From c0d579f07923c190e06afcb00f42774fb25f9124 Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Mon, 3 Aug 2020 14:25:00 -0700 Subject: [PATCH 2/7] Change wording on source of code --- ext/Pod-Html/lib/Pod/Html.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/Pod-Html/lib/Pod/Html.pm b/ext/Pod-Html/lib/Pod/Html.pm index 038050ffb75e..100f537ed159 100644 --- a/ext/Pod-Html/lib/Pod/Html.pm +++ b/ext/Pod-Html/lib/Pod/Html.pm @@ -846,7 +846,7 @@ sub relativize_url { } # Remove any level of indentation (spaces or tabs) from each code block consistently -# Borrowed from: https://metacpan.org/source/HAARG/MetaCPAN-Pod-XHTML-0.002001/lib/Pod/Simple/Role/StripVerbatimIndent.pm +# Adapted from: https://metacpan.org/source/HAARG/MetaCPAN-Pod-XHTML-0.002001/lib/Pod/Simple/Role/StripVerbatimIndent.pm sub trim_leading_whitespace { my ($para) = @_; my $tab_width = 4; From a5e0ffb0eed1a5d73ef8e463a90cf96a33736012 Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Mon, 3 Aug 2020 16:39:00 -0700 Subject: [PATCH 3/7] Use Text::Tabs to convert tabs to spaces instead --- ext/Pod-Html/lib/Pod/Html.pm | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/ext/Pod-Html/lib/Pod/Html.pm b/ext/Pod-Html/lib/Pod/Html.pm index 100f537ed159..b8f526faa341 100644 --- a/ext/Pod-Html/lib/Pod/Html.pm +++ b/ext/Pod-Html/lib/Pod/Html.pm @@ -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 @@ -848,19 +849,11 @@ sub relativize_url { # 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) = @_; - my $tab_width = 4; + my ($para) = @_; # Start by converting tabs to spaces - for my $line (@$para) { - # Count how many tabs on the beginnging of the line - my ($tabs) = $line =~ /^(\t*)/; - my $tab_count = length($tabs); - - # Remove all the tabs, and add them back as spaces - $line =~ s/^\t+//g; - $line = (" " x ($tab_count * $tab_width)) . $line; - } + $tabstop = 4; + @$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)); From 64a9a8b46b5bb30d048e07c0a8ca534c911d9570 Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Mon, 3 Aug 2020 16:34:40 -0700 Subject: [PATCH 4/7] Leave tabstops at 8 --- ext/Pod-Html/lib/Pod/Html.pm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ext/Pod-Html/lib/Pod/Html.pm b/ext/Pod-Html/lib/Pod/Html.pm index b8f526faa341..f95459ab4ae0 100644 --- a/ext/Pod-Html/lib/Pod/Html.pm +++ b/ext/Pod-Html/lib/Pod/Html.pm @@ -852,8 +852,7 @@ sub trim_leading_whitespace { my ($para) = @_; # Start by converting tabs to spaces - $tabstop = 4; - @$para = Text::Tabs::expand(@$para); + @$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)); From 9ffee6cad2515af3ed9cecf64d6a5a25fcc28d8f Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Tue, 11 Aug 2020 08:01:41 -0700 Subject: [PATCH 5/7] Fix some tests for Pod2HTML --- ext/Pod-Html/t/htmldir1.t | 2 +- ext/Pod-Html/t/htmlview.t | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) 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__

LINKS

-
  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..6f09e97c77b3 100644 --- a/ext/Pod-Html/t/htmlview.t +++ b/ext/Pod-Html/t/htmlview.t @@ -45,7 +45,7 @@ __DATA__

SYNOPSIS

-
    use My::Module;
+
use My::Module;
 
     my $module = My::Module->new();
@@ -53,7 +53,7 @@ __DATA__

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 text

This 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>

SEE ALSO

From 54b72824eb2782e7ac52c988b63372fd9e0dffe7 Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Tue, 11 Aug 2020 09:24:13 -0700 Subject: [PATCH 6/7] Fix a failing test --- ext/Pod-Html/t/htmlview.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/Pod-Html/t/htmlview.t b/ext/Pod-Html/t/htmlview.t index 6f09e97c77b3..3b6c45119737 100644 --- a/ext/Pod-Html/t/htmlview.t +++ b/ext/Pod-Html/t/htmlview.t @@ -47,7 +47,7 @@ __DATA__
use My::Module;
 
-    my $module = My::Module->new();
+my $module = My::Module->new();

DESCRIPTION

From 8452dbe6195a370284cb4a32c8e411ac345fd228 Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Tue, 11 Aug 2020 09:24:18 -0700 Subject: [PATCH 7/7] Bump the version --- ext/Pod-Html/lib/Pod/Html.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/Pod-Html/lib/Pod/Html.pm b/ext/Pod-Html/lib/Pod/Html.pm index f95459ab4ae0..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);