cuberat / Pod-POM-View-Restructured

CPAN module Pod::POM::View::Restructured
1 stars 2 forks source link

Several conversion errors #11

Open ole-tange opened 3 years ago

ole-tange commented 3 years ago

POD input:


=head1 Long title converted incorrectly

=head2 dummy

=head3 dummy

=head4 A very looooooooooooooooooooooooooooooooooooooooooooooooong
title

=head1 Item gives an extra bullet

=over 4

=item *

This should not make an extra bullet. pod2pdf/pod2man does not do so.

=back

=head1 Back quotes are not converted correctly

B<Bold back quotes: `-i`>

=head1 The items starting with - are converted incorrectly

=over

=item A B C

=item A - C

=item - - C

=item - - -

=back

=head1 Backslash ignored

\n is newline

=head1 Bold at end of line merges line

B<word>
other word

=cut

Output:

********************************
Long title converted incorrectly
********************************

dummy
=====

dummy
-----

A very looooooooooooooooooooooooooooooooooooooooooooooooong
title
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

**************************
Item gives an extra bullet
**************************

- \*

 This should not make an extra bullet. pod2pdf/pod2man does not do so.

***************************************
Back quotes are not converted correctly
***************************************

\ **Bold back quotes: \\`-i\\`**\ 

***************************************************
The items starting with - are converted incorrectly
***************************************************

- A B C

- A - C

- - C

- - -

*****************
Backslash ignored
*****************

\n is newline

*******************************
Bold at end of line merges line
*******************************

\ **word**\ 
other word

Expected output:

********************************
Long title converted incorrectly
********************************

dummy
=====

dummy
-----

A very looooooooooooooooooooooooooooooooooooooooooooooooong title
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

**************************
Item gives an extra bullet
**************************

- 

 This should not make an extra bullet. pod2pdf/pod2man does not do so.

***************************************
Back quotes are not converted correctly
***************************************

\ **Bold back quotes: \`-i\`**\ 

***************************************************
The items starting with - are converted incorrectly
***************************************************

- A B C

- A - C

- \- \- C

- \- \- \-

*****************
Backslash ignored
*****************

\\n is newline

*******************************
Bold at end of line merges line
*******************************

**word**
other word

The example include #9 and #10.

alexm commented 3 years ago

In summary, if I got it right, these are the issues reported above:

Thanks for bringing them up.

ole-tange commented 2 years ago

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);