texinfo-commits
[Top][All Lists]
Advanced

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

texinfo/tp Texinfo/Convert/Plaintext.pm t/info_...


From: Patrice Dumas
Subject: texinfo/tp Texinfo/Convert/Plaintext.pm t/info_...
Date: Sat, 05 Feb 2011 21:41:49 +0000

CVSROOT:        /sources/texinfo
Module name:    texinfo
Changes by:     Patrice Dumas <pertusus>        11/02/05 21:41:48

Modified files:
        tp/Texinfo/Convert: Plaintext.pm 
        tp/t           : info_tests.t 
        tp/t/results/raw: braces_in_tex.pl raw_in_example.pl 
Added files:
        tp/t/results/info_tests: empty_line_in_example_end.pl 

Log message:
        Avoid empty lines added in preformatted blocks.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Plaintext.pm?cvsroot=texinfo&r1=1.68&r2=1.69
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/info_tests.t?cvsroot=texinfo&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/results/info_tests/empty_line_in_example_end.pl?cvsroot=texinfo&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/results/raw/braces_in_tex.pl?cvsroot=texinfo&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/results/raw/raw_in_example.pl?cvsroot=texinfo&r1=1.1&r2=1.2

Patches:
Index: Texinfo/Convert/Plaintext.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Plaintext.pm,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -b -r1.68 -r1.69
--- Texinfo/Convert/Plaintext.pm        5 Feb 2011 20:16:15 -0000       1.68
+++ Texinfo/Convert/Plaintext.pm        5 Feb 2011 21:41:48 -0000       1.69
@@ -977,7 +977,6 @@
     $self->{'count_context'}->[-1]->{'bytes'} -= $self->count_bytes($chomped);
     $self->{'count_context'}->[-1]->{'lines'} -= 1;
   }
-  $self->{'empty_lines_count'} = 0 unless ($text eq '');
   $text .= "\n";
   $self->_add_text_count("\n");
   $self->_add_lines_count(1);
@@ -1070,7 +1069,7 @@
     $is_top_formatter = 1 if ($formatter->{'_top_formatter'});
     my $empty_lines_count = '';
     $empty_lines_count = $self->{'empty_lines_count'} if 
defined($self->{'empty_lines_count'});
-    print STDERR "ROOT (".join('|',@{$self->{'context'}})."), formatters 
".scalar(@{$self->{'formatters'}}) . " ->";
+    print STDERR "ROOT:$root (".join('|',@{$self->{'context'}})."), formatters 
".scalar(@{$self->{'formatters'}}) . " ->";
     print STDERR " cmd: $root->{'cmdname'}," if ($root->{'cmdname'});
     print STDERR " type: $root->{'type'}" if ($root->{'type'});
     my $text = $root->{'text'}; 
@@ -1102,7 +1101,28 @@
   }
   my $result = '';
 
+  # First handle empty lines. This has to be done before the handling
+  # of text below to be sure that an empty line is always processed
+  # especially
+  if ($root->{'type'} and $root->{'type'} eq 'empty_line') {
+    my $count = $self->{'empty_lines_count'};
+    $count = '' if (!defined($count));
+    print STDERR "EMPTY_LINE ($count)\n"
+      if ($self->{'DEBUG'});
+    delete $self->{'format_context'}->[-1]->{'counter'};
+    $self->{'empty_lines_count'}++;
+    if ($self->{'empty_lines_count'} <= 1
+        or $preformatted_context_commands{$self->{'context'}->[-1]}) {
+      $result = "\n";
+      $self->_add_text_count($result);
+      $self->_add_lines_count(1);
+      return $result;
+    } else {
+      return '';
+    }
+  }
 
+  # process text
   if (defined($root->{'text'})) {
     if (!$formatter->{'_top_formatter'}) {
       $result = $self->_count_added($formatter->{'container'},
@@ -1553,7 +1573,10 @@
       $result = $self->convert_line({'contents' => $contents},
                   {'indent_level'
                     => $self->{'format_context'}->[-1]->{'indent_level'} -1});
+      if ($result ne '') {
       $result = $self->ensure_end_of_line($result);
+        $self->{'empty_lines_count'} = 0;
+      }
       
     } elsif ($root->{'cmdname'} eq 'item' and $root->{'parent'}->{'cmdname'}
              and $item_container_commands{$root->{'parent'}->{'cmdname'}}) {
@@ -1613,19 +1636,23 @@
       $result = $self->convert_line (
                        {'contents' => $root->{'extra'}->{'misc_content'}},
                        {'indent_length' => 0});
+      if ($result ne '') {
       $result = $self->ensure_end_of_line($result);
 
       $result = $self->_align_environment ($result, 
              $self->{'format_context'}->[-1]->{'max'}, 'center'); 
-
-      $self->{'empty_lines_count'} = 0 unless ($result eq '');
+        $self->{'empty_lines_count'} = 0;
+      }
       $self->{'format_context'}->[-1]->{'paragraph_count'}++;
       return $result;
     } elsif ($root->{'cmdname'} eq 'exdent') {
       $result = $self->convert_line ({'contents' => 
$root->{'extra'}->{'misc_content'}},
          {'indent_level' 
           => $self->{'format_context'}->[-1]->{'indent_level'} -1});
-      $result = $self->ensure_end_of_line ($result);
+      if ($result ne '') {
+        $result = $self->ensure_end_of_line($result);
+        $self->{'empty_lines_count'} = 0;
+      }
       return $result;
     } elsif ($root->{'cmdname'} eq 'verbatiminclude') {
       my $expansion = $self->Texinfo::Parser::expand_verbatiminclude($root);
@@ -1810,29 +1837,12 @@
         push @{$self->{'count_context'}}, {'lines' => 0, 'bytes' => 0,
                                                    'locations' => []};
       }
-    } elsif ($root->{'type'} eq 'empty_line') {
-      my $count = $self->{'empty_lines_count'};
-      $count = '' if (!defined($count));
-      print STDERR "EMPTY_LINE ($count)\n"
-        if ($self->{'DEBUG'});
-      delete $self->{'format_context'}->[-1]->{'counter'};
-      $self->{'empty_lines_count'}++;
-      if ($self->{'empty_lines_count'} <= 1
-          or $preformatted_context_commands{$self->{'context'}->[-1]}) {
-        $result = "\n";
-        $self->_add_text_count($result);
-        $self->_add_lines_count(1);
-        return $result;
-      } else {
-        return '';
-      }
     } elsif ($root->{'type'} eq 'preformatted') {
         $preformatted = $self->new_formatter('unfilled');
         push @{$self->{'formatters'}}, $preformatted;
     } elsif ($root->{'type'} eq 'def_line') {
       if ($root->{'extra'} and $root->{'extra'}->{'def_args'}
              and @{$root->{'extra'}->{'def_args'}}) {
-    #print STDERR "$root->{'extra'}->{'def_command'}\n";
         my $parsed_definition_category = $self->_definition_category ($root, 
                 $root->{'extra'}->{'def_parsed_hash'}->{'category'},
                 $root->{'extra'}->{'def_parsed_hash'}->{'class'});
@@ -1874,7 +1884,6 @@
         print STDERR "     --> $result" if ($self->{'DEBUG'});
       }
     } elsif ($root->{'type'} eq 'menu_entry') {
-      # FIXME node name should be in code.
       foreach my $arg (@{$root->{'args'}}) {
         if ($arg->{'type'} eq 'menu_entry_node') {
           $result .= $self->_convert({'type' => 'code',
@@ -1899,6 +1908,7 @@
     }
   }
 
+  # The processing of contents is done here.
   if ($root->{'contents'}) {
     my @contents = @{$root->{'contents'}};
     push @{$self->{'current_contents'}}, address@hidden;
@@ -1906,13 +1916,13 @@
       my $content = shift @contents;
       my $text = $self->_convert($content);
       $self->{'empty_lines_count'} = 0 
-        if ($preformatted_context_commands{$self->{'context'}->[-1]} and $text 
ne '');
+        if ($preformatted and $text =~ /\S/);
       $result .= $text;
     }
     pop @{$self->{'current_contents'}};
   }
 
-  # now closing
+  # now closing. First, close types.
   if ($root->{'type'}) {
     if ($root->{'type'} eq 'frenchspacing') {
       pop @{$formatter->{'frenchspacing_stack'}};
@@ -2058,7 +2068,9 @@
   } elsif ($preformatted) {
     $result .= $self->_count_added($preformatted->{'container'},
                                    $preformatted->{'container'}->end());
+    if ($result ne '') {
     $result = $self->ensure_end_of_line($result);
+    }
     pop @{$self->{'formatters'}};
     # We assume that, upon closing the preformatted we are at the 
     # beginning of a line.

Index: t/info_tests.t
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/info_tests.t,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- t/info_tests.t      5 Feb 2011 13:31:04 -0000       1.4
+++ t/info_tests.t      5 Feb 2011 21:41:48 -0000       1.5
@@ -35,9 +35,6 @@
 @node chapter node
 @chapter chapter'
 ],
-#);
-
-#my @new_tests = (
 ['ref_tests',
 '
 @node Top
@@ -69,7 +66,15 @@
 
 @node Top
 @top Double contents
-']
+'],
+['empty_line_in_example_end',
+'@example
+in example
+
address@hidden example
+
+After line
+'],
 
 );
 

Index: t/results/raw/braces_in_tex.pl
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/results/raw/braces_in_tex.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- t/results/raw/braces_in_tex.pl      2 Feb 2011 22:17:37 -0000       1.1
+++ t/results/raw/braces_in_tex.pl      5 Feb 2011 21:41:48 -0000       1.2
@@ -210,8 +210,6 @@
 
 
 $result_converted{'plaintext'}->{'braces_in_tex'} = '
-
-
 ';
 
 1;

Index: t/results/raw/raw_in_example.pl
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/results/raw/raw_in_example.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- t/results/raw/raw_in_example.pl     2 Feb 2011 22:17:37 -0000       1.1
+++ t/results/raw/raw_in_example.pl     5 Feb 2011 21:41:48 -0000       1.2
@@ -78,7 +78,6 @@
 
 
 
-$result_converted{'plaintext'}->{'raw_in_example'} = '
-';
+$result_converted{'plaintext'}->{'raw_in_example'} = '';
 
 1;

Index: t/results/info_tests/empty_line_in_example_end.pl
===================================================================
RCS file: t/results/info_tests/empty_line_in_example_end.pl
diff -N t/results/info_tests/empty_line_in_example_end.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ t/results/info_tests/empty_line_in_example_end.pl   5 Feb 2011 21:41:48 
-0000       1.1
@@ -0,0 +1,108 @@
+use vars qw(%result_texis %result_texts %result_trees %result_errors 
+   %result_indices %result_sectioning %result_nodes %result_menus
+   %result_floats %result_converted %result_converted_errors);
+
+$result_trees{'empty_line_in_example_end'} = {
+  'contents' => [
+    {
+      'cmdname' => 'example',
+      'contents' => [
+        {
+          'parent' => {},
+          'text' => '
+',
+          'type' => 'empty_line_after_command'
+        },
+        {
+          'contents' => [
+            {
+              'parent' => {},
+              'text' => 'in example
+'
+            },
+            {
+              'parent' => {},
+              'text' => '
+',
+              'type' => 'empty_line'
+            }
+          ],
+          'parent' => {},
+          'type' => 'preformatted'
+        }
+      ],
+      'parent' => {}
+    },
+    {
+      'parent' => {},
+      'text' => '
+',
+      'type' => 'empty_line_after_command'
+    },
+    {
+      'parent' => {},
+      'text' => '
+',
+      'type' => 'empty_line'
+    },
+    {
+      'contents' => [
+        {
+          'parent' => {},
+          'text' => 'After line
+'
+        }
+      ],
+      'parent' => {},
+      'type' => 'paragraph'
+    }
+  ],
+  'type' => 'text_root'
+};
+$result_trees{'empty_line_in_example_end'}{'contents'}[0]{'contents'}[0]{'parent'}
 = $result_trees{'empty_line_in_example_end'}{'contents'}[0];
+$result_trees{'empty_line_in_example_end'}{'contents'}[0]{'contents'}[1]{'contents'}[0]{'parent'}
 = $result_trees{'empty_line_in_example_end'}{'contents'}[0]{'contents'}[1];
+$result_trees{'empty_line_in_example_end'}{'contents'}[0]{'contents'}[1]{'contents'}[1]{'parent'}
 = $result_trees{'empty_line_in_example_end'}{'contents'}[0]{'contents'}[1];
+$result_trees{'empty_line_in_example_end'}{'contents'}[0]{'contents'}[1]{'parent'}
 = $result_trees{'empty_line_in_example_end'}{'contents'}[0];
+$result_trees{'empty_line_in_example_end'}{'contents'}[0]{'parent'} = 
$result_trees{'empty_line_in_example_end'};
+$result_trees{'empty_line_in_example_end'}{'contents'}[1]{'parent'} = 
$result_trees{'empty_line_in_example_end'};
+$result_trees{'empty_line_in_example_end'}{'contents'}[2]{'parent'} = 
$result_trees{'empty_line_in_example_end'};
+$result_trees{'empty_line_in_example_end'}{'contents'}[3]{'contents'}[0]{'parent'}
 = $result_trees{'empty_line_in_example_end'}{'contents'}[3];
+$result_trees{'empty_line_in_example_end'}{'contents'}[3]{'parent'} = 
$result_trees{'empty_line_in_example_end'};
+
+$result_texis{'empty_line_in_example_end'} = '@example
+in example
+
address@hidden example
+
+After line
+';
+
+
+$result_texts{'empty_line_in_example_end'} = 'in example
+
+
+After line
+';
+
+$result_errors{'empty_line_in_example_end'} = [];
+
+
+
+$result_converted{'info'}->{'empty_line_in_example_end'} = 'This is , produced 
by makeinfo version 4.13 from .
+
+     in example
+
+After line
+';
+
+$result_converted_errors{'info'}->{'empty_line_in_example_end'} = [
+  {
+    'error_line' => 'warning: Document without nodes.
+',
+    'text' => 'Document without nodes.',
+    'type' => 'warning'
+  }
+];
+
+
+1;



reply via email to

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