Fix squasher stripping repeated newlines in ignored sections

This commit is contained in:
Dan Church 2023-06-29 13:28:03 -05:00
parent 4d4edd5e9d
commit a26764fd2f
Signed by: h3xx
GPG Key ID: EA2BF379CD2CDBD0
1 changed files with 13 additions and 3 deletions

View File

@ -20,6 +20,7 @@ for my $arg (@ARGV) {
my $in_pod = 0;
my $in_section = '';
my $ignore_lines = 0;
my $empty_lines = 0;
while (<$fh>) {
if (/#.*:squash-ignore-start:$/) {
$in_section = 'ignore';
@ -34,10 +35,22 @@ for my $arg (@ARGV) {
}
if ($in_section eq 'ignore') {
$empty_lines = 0 unless /^$/;
$code .= $_;
next;
}
# Remove repeated newlines between paragraphs
# (Provided of course we're not in an 'ignore' section)
if (/^$/) {
++$empty_lines;
if ($empty_lines > 1) {
next;
}
} else {
$empty_lines = 0;
}
if (/#.*:squash-remove-start:$/) {
$in_section = 'remove';
next;
@ -74,9 +87,6 @@ for my $arg (@ARGV) {
close $fh;
}
# Remove repeated newlines between paragraphs
$code =~ s/\n\n+/\n\n/gs;
print $code;
exit 0;