texinfo-commits
[Top][All Lists]
Advanced

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

[6118] prevent line breaks in xref in multitable


From: Gavin D. Smith
Subject: [6118] prevent line breaks in xref in multitable
Date: Wed, 11 Feb 2015 17:53:37 +0000

Revision: 6118
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=6118
Author:   gavin
Date:     2015-02-11 17:53:36 +0000 (Wed, 11 Feb 2015)
Log Message:
-----------
prevent line breaks in xref in multitable

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/tp/Texinfo/Convert/Plaintext.pm
    trunk/tp/t/21multitable.t

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2015-02-11 10:06:15 UTC (rev 6117)
+++ trunk/ChangeLog     2015-02-11 17:53:36 UTC (rev 6118)
@@ -1,3 +1,19 @@
+2015-02-11  Gavin Smith  <address@hidden>, and
+            Patrice Dumas  <address@hidden>
+
+       * tp/Texinfo/Convert/Plaintext.pm (push_top_formatter): Add
+       to 'document_context' stack.
+       (_convert) <multitable>: Increment 'in_multitable' on hash on
+       top of document_context stack.
+       <end of multitable>: Decrement 'in_multitable'.
+       <$ref_commands>: Check if in multitable context by checking top 
+       of 'document_context' stack, and if so suppress line breaks for 
+       output of cross-reference.
+       (_footnotes): Pop 'document_context' along with the other 
+       context stacks.
+
+       * tp/t/21multitable.t (ref_in_multitable): New test.
+
 2015-02-11  Gavin Smith  <address@hidden>
 
        * tp/Texinfo/Convert/Plaintext.pm (_convert) <empty line>: Pass 

Modified: trunk/tp/Texinfo/Convert/Plaintext.pm
===================================================================
--- trunk/tp/Texinfo/Convert/Plaintext.pm       2015-02-11 10:06:15 UTC (rev 
6117)
+++ trunk/tp/Texinfo/Convert/Plaintext.pm       2015-02-11 17:53:36 UTC (rev 
6118)
@@ -109,7 +109,7 @@
   $formatting_misc_commands{$def_command} = 1 if 
($misc_commands{$def_command});
 }
 
-# There are 5 stacks that define the context.
+# There are 6 stacks that define the context.
 # context:   relevant for alignement of text.  Set in math, footnote, 
 #            listoffloats, flush_commands, preformatted_context_commands 
 #            (preformatted + menu + verbatim), and raw commands if 
@@ -134,6 +134,7 @@
 #            counting some converted text, but it is also set when it has
 #            to be modified afterwards, for aligned commands or multitable
 #            cells for example.
+# document_context: Used to keep track if we are in a multitable.
 
 # formatters have their own stack
 # in container
@@ -330,6 +331,10 @@
   push @{$self->{'text_element_context'}}, {
                                      'max' => $self->{'fillcolumn'}
                                    };
+  push @{$self->{'document_context'}}, {
+                                     'in_multitable' => 0
+                                   };
+
   # This is not really meant to be used, as contents should open 
   # their own formatters, however it happens that there is some text
   # outside any content that needs to be formatted, as @sp for example.
@@ -840,7 +845,8 @@
                                     'normalized' => $normalized}
                        });
       }
-      # this pushes on 'context', 'format_context' and 'formatters'
+      # this pushes on 'context', 'formatters', 'format_context',
+      # 'text_element_context' and 'document_context'
       $self->push_top_formatter('footnote');
       my $formatted_footnote_number;
       if ($self->get_conf('NUMBER_FOOTNOTES')) {
@@ -861,9 +867,10 @@
       
       my $old_context = pop @{$self->{'context'}};
       die if ($old_context ne 'footnote');
+      pop @{$self->{'formatters'}};
       pop @{$self->{'format_context'}};
-      pop @{$self->{'formatters'}};
       pop @{$self->{'text_element_context'}};
+      pop @{$self->{'document_context'}};
     }
   }
   $self->{'footnote_index'} = 0;
@@ -2015,6 +2022,20 @@
           $args[3] = $args[2];
           $args[2] = undef;
         }
+
+        # Treat cross-reference commands in a multitable cell as if they
+        # were surrounded by @w{ ... }, so the output will not be split across
+        # lines, leading text from other columns appearing to be part of the
+        # cross-reference.
+        my $in_multitable = 0;
+        if ($self->{'document_context'}->[-1]->{'in_multitable'}) {
+          $in_multitable = 1;
+          $formatter->{'w'}++;
+          $result .= $self->_count_added($formatter->{'container'},
+            $formatter->{'container'}->set_space_protection(1,undef))
+          if ($formatter->{'w'} == 1);
+        }
+
         if ($command eq 'xref') {
           $result = $self->_convert({'contents' => [{'text' => '*Note '}]});
         } else {
@@ -2114,6 +2135,13 @@
             unshift @{$self->{'current_contents'}->[-1]}, @added;
           }
         }
+
+        if ($in_multitable) {
+          $formatter->{'w'}--;
+          $result .= $self->_count_added($formatter->{'container'},
+              $formatter->{'container'}->set_space_protection(0,undef))
+            if ($formatter->{'w'} == 0);
+        }
         return $result;
       }
       return '';
@@ -2323,6 +2351,7 @@
         $self->{'format_context'}->[-1]->{'columns_size'} = $columnsize;
         $self->{'format_context'}->[-1]->{'row_empty_lines_count'} 
           = $self->{'empty_lines_count'};
+        $self->{'document_context'}->[-1]->{'in_multitable'}++;
       } elsif ($root->{'cmdname'} eq 'float') {
         $result .= $self->_add_newline_if_needed();
         if ($root->{'extra'} and $root->{'extra'}->{'normalized'}) {
@@ -3180,9 +3209,10 @@
                  $self->gdt("address@hidden --- address@hidden",
                     {'author' => $author->{'extra'}->{'misc_content'}}));
       }
+    } elsif (($root->{'cmdname'} eq 'multitable')) {
+      $self->{'document_context'}->[-1]->{'in_multitable'}--;
     }
-
-  
+ 
     # close the contexts and register the cells
     if ($self->{'preformatted_context_commands'}->{$root->{'cmdname'}}
         or $root->{'cmdname'} eq 'float') {

Modified: trunk/tp/t/21multitable.t
===================================================================
--- trunk/tp/t/21multitable.t   2015-02-11 10:06:15 UTC (rev 6117)
+++ trunk/tp/t/21multitable.t   2015-02-11 17:53:36 UTC (rev 6118)
@@ -1,3 +1,5 @@
+# Tests of some uses of @multitable
+
 use strict;
 
 use File::Spec;
@@ -11,6 +13,7 @@
 @item 1.3 @tab 5-6
 @end multitable
 '],
+
 ['paragraph_in_cells',
 '@multitable {AAA}  {BBB}
 @item truc @tab bidule
@@ -35,6 +38,7 @@
 new paragraph in tab. example
 @end multitable
 @end example'],
+
 ['w_in_multitable',
 '@multitable {aaaaaaaaa} {bbbbbbbbbbb}
 @item @w{aaaaaaaa
@@ -42,6 +46,7 @@
 @tab gg
 @end multitable
 '],
+
 ['inter_item_commands_in_multitable',
 '@multitable {truc}
 @c comment before first item
@@ -70,6 +75,7 @@
 @end multitable
 
 '],
+
 ['empty_item_tab',
 '@multitable @columnfractions 1.0
 @item
@@ -96,23 +102,48 @@
 @item not empty @tab tab not empty
 @end multitable
 '],
+
 ['prototype_brace_no_brace',
 '@multitable {aa} bb
 @end multitable
 '],
+
 ['prototype_brace_no_brace_comment',
 '@multitable {aa} address@hidden cc
 @end multitable
 '],
+
 ['prototype_no_brace',
 '@multitable address@hidden b    cc
 @end multitable
 '],
+
 ['multitable_with_empty_item_tab',
 '@multitable @columnfractions 0.3 0.7
 @item 1-1 @tab 1-2 @address@hidden@item 3-1 @tab 3-2
 @end multitable
 '],
+
+# Check xrefs in a multitable are treated as if surrounded in @w { ... }.
+['ref_in_multitable',
+'@novalidate
+
address@hidden XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XX XXX XXX XXX XXX 
+XXX XXX XXX XXX XXX XXX XXX XXX XX}.
+
address@hidden @columnfractions .35 .65
address@hidden XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XX
address@hidden See @ref{RRR RRR RRR RRR RRR RRR RRR RRR RRR RRRR}.
address@hidden XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XX
address@hidden See @ref{SSS SSS SSS SSS SSS SSS SSS SSS SSS SSS SSS SSS SSSSS}.
address@hidden address@hidden@ref{XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX 
XXX XX 
+XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XX}} @tab 
+second column
address@hidden multitable
+
address@hidden XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XX XXX XXX XXX XXX 
+XXX XXX XXX XXX XXX XXX XXX XXX XX}.
+'],
 );
 
 my @test_invalid = (




reply via email to

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