Open ole-tange opened 3 years ago
In summary, if I got it right, these are the issues reported above:
=head4
is not converted correctly #9=item *
should not make an extra bullet\n
is ignoredThanks for bringing them up.
This works around some of the remaining issues:
#!/usr/bin/perl
# Copyright (C) 2007-2022 Ole Tange, http://ole.tange.dk and Free
# Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <https://www.gnu.org/licenses/>
# or write to the Free Software Foundation, Inc., 51 Franklin St,
# Fifth Floor, Boston, MA 02110-1301 USA
#
# SPDX-FileCopyrightText: 2021-2022 Ole Tange, http://ole.tange.dk and Free Software and Foundation, Inc.
# SPDX-License-Identifier: GPL-3.0-or-later
# This fixes problems in pod2rst conversion
# Conversion errors:
# Fixed:
# ... B<foo>
# bar
# Fixed:
# =item - - a
# Not fixed (RST does not support Bold-Italic):
# B<cat | xargs -d "\n" -n1 I<command>>
sub pipefunc {
my $func = pop;
my $pid = open(my $kid_to_read, "-|");
defined($pid) || die "can't fork: $!";
if ($pid) {
open STDIN, "<&", $kid_to_read or die;
&$func();
} else { # child
close $kid_to_read;
if($_[1]) {
# More than one function remaining: Recurse
pipefunc(@_);
} else {
# Only one function remaining: Run it
$func = pop;
&$func();
}
exit 0;
}
}
sub pre {
# Remove comments
$_=join("", grep { ! /^#/ } <>);
# join lines in each paragraph
s/(\S)\n(\S)/$1 $2/g;
# quote -
s/^=item -/=item \001/gm;
print $_;
}
sub pod2rst {
exec "pod2rst";
}
sub post {
while(<STDIN>) {
# =item in =item
s/- \\[*]/- /;
# B<*.log>
s/\\\\[*]/\\*/g;
# - -
s/^-(\s+)\001/-$1\\-/g;
print;
}
}
# stdin | pre() | pod2rst() | post()
pipefunc(*pre,*pod2rst,*post);
POD input:
Output:
Expected output:
The example include #9 and #10.