texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

texinfo/Pod-Simple-Texinfo lib/Pod/Simple/Texin...


From: Patrice Dumas
Subject: texinfo/Pod-Simple-Texinfo lib/Pod/Simple/Texin...
Date: Sun, 29 Jan 2012 00:21:08 +0000

CVSROOT:        /sources/texinfo
Module name:    texinfo
Changes by:     Patrice Dumas <pertusus>        12/01/29 00:21:08

Modified files:
        Pod-Simple-Texinfo/lib/Pod/Simple: Texinfo.pm 
        Pod-Simple-Texinfo/t: Pod-Simple-Texinfo.t 

Log message:
        Normalize also generated @section lines to avoid bad texinfo production,
        for instance with ref on section lines.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/Pod-Simple-Texinfo/lib/Pod/Simple/Texinfo.pm?cvsroot=texinfo&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/texinfo/Pod-Simple-Texinfo/t/Pod-Simple-Texinfo.t?cvsroot=texinfo&r1=1.3&r2=1.4

Patches:
Index: lib/Pod/Simple/Texinfo.pm
===================================================================
RCS file: 
/sources/texinfo/texinfo/Pod-Simple-Texinfo/lib/Pod/Simple/Texinfo.pm,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- lib/Pod/Simple/Texinfo.pm   28 Jan 2012 17:53:25 -0000      1.6
+++ lib/Pod/Simple/Texinfo.pm   29 Jan 2012 00:21:08 -0000      1.7
@@ -31,6 +31,7 @@
 use Texinfo::Convert::NodeNameNormalization qw(normalize_node);
 use Texinfo::Parser qw(parse_texi_line parse_texi_text);
 use Texinfo::Convert::Texinfo;
+use Texinfo::Convert::TextContent;
 use Texinfo::Common qw(protect_comma_in_tree);
 
 use vars qw(
@@ -277,6 +278,35 @@
   }
 }
 
+sub _normalize_texinfo_name($$)
+{
+  # Pod may be more forgiven than Texinfo, so we go through
+  # a normalization, by parsing and converting back to Texinfo
+  my $name = shift;
+  my $command = shift;
+  my $texinfo_text;
+  if ($command eq 'anchor') {
+    $texinfo_text = "address@hidden";
+  } else {
+    # item is not correct since it cannot happen outside of a table
+    # context, so we use @center which accepts the same on the line
+    if ($command eq 'item') {
+      $command = 'center';
+    }
+    $texinfo_text = "address@hidden $name\n";
+  }
+  my $tree = parse_texi_text(undef, $texinfo_text);
+  my $fixed_text = Texinfo::Convert::Texinfo::convert($tree, 1);
+  my $result = $fixed_text;
+  if ($command eq 'anchor') {
+    $result =~ s/address@hidden(.*)\}$/$1/s;
+  } else {
+    chomp($result);
+    $result =~ s/address@hidden (.*)$/$1/s;
+  }
+  return $result;
+}
+
 sub _prepare_anchor($$)
 {
   my $self = shift;
@@ -288,12 +318,7 @@
                                           $texinfo_node_name,
                                           
$self->texinfo_sectioning_base_level);
 
-  # Pod may be more forgiven than Texinfo, so we go through
-  # a normalization, by parsing and converting back to Texinfo
-  my $anchor_tree = parse_texi_text(undef, "address@hidden");
-  my $anchor = Texinfo::Convert::Texinfo::convert($anchor_tree, 1);
-  my $node = $anchor;
-  $node =~ s/address@hidden(.*)\}$/$1/s;
+  my $node = _normalize_texinfo_name($texinfo_node_name, 'anchor');
 
   if ($node !~ /\S/) {
     return '';
@@ -309,7 +334,7 @@
   }
   my $node_name;
   if ($number_appended) {
-    $texinfo_node_name = "$texinfo_node_name $number_appended";
+    $texinfo_node_name = "$node $number_appended";
     $node_tree = parse_texi_line(undef, $texinfo_node_name);
   }
   $node_tree = protect_comma_in_tree(undef, $node_tree);
@@ -501,7 +526,8 @@
       if ($context_tags{$tagname}) {
         my ($result, $out) = _end_context(address@hidden);
         if ($line_commands{$tagname}) {
-          my $command;
+
+          my ($command, $command_argument);
           if ($head_commands_level{$tagname}) {
             $command = $self->{'texinfo_head_commands'}->{$tagname};
           } elsif ($line_commands{$tagname}) {
@@ -513,6 +539,15 @@
             $result =~ s/\n/ /g;
             $result =~ s/^\s*//;
             $result =~ s/\s*$//;
+
+            $command_argument = _normalize_texinfo_name($result, $command);
+            if ($result =~ /\S/ and $command_argument !~ /\S/) {
+              # use some raw text if the expansion lead to an empty section
+              my $tree = parse_texi_line(undef, $result);
+              my $converter = Texinfo::Convert::TextContent->converter();
+              $command_argument = 
_protect_text($converter->convert_tree($tree));
+            }
+
             my $node_name = _prepare_anchor ($self, $result);
             #print $fh "address@hidden $node_name\n";
             my $anchor;
@@ -521,9 +556,12 @@
             } else {
               $anchor = '';
             }
-            $result .= "\n$anchor";
+            $command_argument .= "\n$anchor";
+          } else {
+            $command_argument = $result;
           }
-          _output($fh, address@hidden, "address@hidden $result\n$out\n");
+          _output($fh, address@hidden, 
+                  "address@hidden $command_argument\n$out\n");
         } elsif ($tagname eq 'Para') {
           _output($fh, address@hidden, "$out$result\n\n");
         } elsif ($tagname eq 'L') {

Index: t/Pod-Simple-Texinfo.t
===================================================================
RCS file: /sources/texinfo/texinfo/Pod-Simple-Texinfo/t/Pod-Simple-Texinfo.t,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- t/Pod-Simple-Texinfo.t      28 Jan 2012 17:53:25 -0000      1.3
+++ t/Pod-Simple-Texinfo.t      29 Jan 2012 00:21:08 -0000      1.4
@@ -6,7 +6,7 @@
 # change 'tests => 1' to 'tests => last_test_to_print';
 
 use Test::More;
-BEGIN { plan tests => 7 };
+BEGIN { plan tests => 9 };
 use Pod::Simple::Texinfo;
 ok(1); # If we made it this far, we're ok.
 
@@ -130,6 +130,28 @@
 
 ', 'head with new line');
 
+run_test('=head1 L</somewhere>
+', '@chapter somewhere
+
+
+', 'ref in section');
+
+run_test('=over
+
+=item a L<pod2text|pod2text>
+
+=item a L<pod2latex|pod2latex>
+
+', '@table @asis
address@hidden a @ref{Top, pod2text,, pod2text}
address@hidden }
+
address@hidden a @ref{Top, pod2latex,, pod2latex}
address@hidden  1}
+
address@hidden table
+
+', 'duplicate anchors ref');
 
 1;
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]