@@ -367,6 +367,9 @@ sub pod2html {
367367
368368 # set options for input parser
369369 my $parser = Pod::Simple::SimpleTree-> new;
370+ # Normalize whitespace indenting
371+ $parser -> strip_verbatim_indent(\&trim_leading_whitespace);
372+
370373 $parser -> codes_in_verbatim(0);
371374 $parser -> accept_targets(qw( html HTML) );
372375 $parser -> no_errata_section(!$Poderrors ); # note the inverse
@@ -842,4 +845,33 @@ sub relativize_url {
842845 return $rel_path ;
843846}
844847
848+ # Remove any level of indentation (spaces or tabs) from each code block consistently
849+ # Borrowed from: https://metacpan.org/source/HAARG/MetaCPAN-Pod-XHTML-0.002001/lib/Pod/Simple/Role/StripVerbatimIndent.pm
850+ sub trim_leading_whitespace {
851+ my ($para ) = @_ ;
852+ my $tab_width = 4;
853+
854+ # Start by converting tabs to spaces
855+ for my $line (@$para ) {
856+ # Count how many tabs on the beginnging of the line
857+ my ($tabs ) = $line =~ / ^(\t *)/ ;
858+ my $tab_count = length ($tabs );
859+
860+ # Remove all the tabs, and add them back as spaces
861+ $line =~ s / ^\t +// g ;
862+ $line = (" " x ($tab_count * $tab_width )) . $line ;
863+ }
864+
865+ # Find the line with the least amount of indent, as that's our "base"
866+ my @indent_levels = (sort (map { $_ =~ / ^( *)./mg } @$para ));
867+ my $indent = $indent_levels [0] || " " ;
868+
869+ # Remove the "base" amount of indent from each line
870+ foreach (@$para ) {
871+ $_ =~ s / ^\Q $indent// mg
872+ }
873+
874+ return ;
875+ }
876+
8458771;
0 commit comments