texinfo-commits
[Top][All Lists]
Advanced

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

texinfo/tp Texinfo/Convert/XML.pm t/fix_texinfo...


From: Patrice Dumas
Subject: texinfo/tp Texinfo/Convert/XML.pm t/fix_texinfo...
Date: Fri, 24 Aug 2012 23:03:50 +0000

CVSROOT:        /sources/texinfo
Module name:    texinfo
Changes by:     Patrice Dumas <pertusus>        12/08/24 23:03:50

Modified files:
        tp/Texinfo/Convert: XML.pm 
        tp/t           : fix_texinfo.t xml_tests.t 
Added files:
        tp/t/results/xml_tests: commands_and_spaces.pl 

Log message:
        Keep spaces/line formatting information for 'special' misc commands.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/XML.pm?cvsroot=texinfo&r1=1.70&r2=1.71
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/fix_texinfo.t?cvsroot=texinfo&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/xml_tests.t?cvsroot=texinfo&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/results/xml_tests/commands_and_spaces.pl?cvsroot=texinfo&rev=1.1

Patches:
Index: Texinfo/Convert/XML.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/XML.pm,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -b -r1.70 -r1.71
--- Texinfo/Convert/XML.pm      24 Aug 2012 16:43:26 -0000      1.70
+++ Texinfo/Convert/XML.pm      24 Aug 2012 23:03:49 -0000      1.71
@@ -378,6 +378,20 @@
   }
 }
 
+sub _arg_line($)
+{
+  my $self = shift;
+  my $root = shift;
+  if ($root->{'extra'} and defined($root->{'extra'}->{'arg_line'})) {
+    my $line = $root->{'extra'}->{'arg_line'};
+    chomp($line);
+    if ($line ne '') {
+      return " line=\"".$self->xml_protect_text($line)."\"";
+    }
+  } 
+  return '';
+}
+
 my @node_directions = ('Next', 'Prev', 'Up');
 
 sub _convert($$;$);
@@ -641,7 +655,17 @@
           $self->{'pending_bye'} = "<$command></$command>\n";
           return '';
         }
-        return "<$command></$command>\n";
+        my $line;
+        if ($root->{'args'} and $root->{'args'}->[0] 
+            and defined($root->{'args'}->[0]->{'text'})) {
+          $line = $root->{'args'}->[0]->{'text'};
+          chomp($line);
+          $line = " line=\"".$self->xml_protect_text($line)."\""
+             if ($line ne '');
+        } else {
+          $line = '';
+        }
+        return "<$command${line}></$command>\n";
       } elsif ($type eq 'noarg' or $type eq 'skipspace') {
         return "<$command></$command>";
       } elsif ($type eq 'special') {
@@ -657,7 +681,8 @@
               and defined($root->{'args'}->[1]->{'text'})) {
             $value = $self->xml_protect_text($root->{'args'}->[1]->{'text'});
           }
-          return "<${command}value${attribute}>$value</${command}value>\n";
+          return "<${command}${attribute}".$self->_arg_line($root)
+                                        .">$value</${command}>\n";
         } elsif ($root->{'cmdname'} eq 'clickstyle') {
           my $attribute = '';
           my $value = '';
@@ -668,7 +693,8 @@
             $attribute = " 
command=\"".$self->xml_protect_text($click_command)."\"";
             $value = $self->xml_protect_text($root->{'args'}->[0]->{'text'});
           };
-          return "<${command}${attribute}>$value</${command}>\n";
+          return "<${command}${attribute}".$self->_arg_line($root).
+                                         ">$value</${command}>\n";
         }
       } elsif ($type eq 'lineraw') {
         if ($root->{'cmdname'} eq 'c' or $root->{'cmdname'} eq 'comment') {
@@ -845,12 +871,8 @@
             $prepended_elements .= "<formalarg>".
                 $self->xml_protect_text($formal_arg->{'text'})."</formalarg>";
           }
-          if ($root->{'extra'} and defined($root->{'extra'}->{'arg_line'})) {
-            my $line = $root->{'extra'}->{'arg_line'};
-            chomp($line);
-            $attribute .= " line=\"".$self->xml_protect_text($line)."\"";
-          }
         }
+        $attribute .= $self->_arg_line($root);
       }
       if ($self->{'expanded_formats_hash'}->{$root->{'cmdname'}}) {
         $self->{'document_context'}->[-1]->{'raw'} = 1;

Index: t/fix_texinfo.t
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/fix_texinfo.t,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- t/fix_texinfo.t     13 Feb 2012 00:22:41 -0000      1.2
+++ t/fix_texinfo.t     24 Aug 2012 23:03:49 -0000      1.3
@@ -1,7 +1,7 @@
 use strict;
 
 use Test::More;
-BEGIN { plan tests => 3 };
+BEGIN { plan tests => 4 };
 use lib 'maintain/lib/Unicode-EastAsianWidth/lib/';
 use lib 'maintain/lib/libintl-perl/lib/';
 use lib 'maintain/lib/Text-Unidecode/lib/';
@@ -37,3 +37,7 @@
 
 run_test ('@address@hidden', '@anchor{}', 'ref in anchor');
 
+run_test ('@page on page line
+', 
+'@page
+', 'garbage on page line');

Index: t/xml_tests.t
===================================================================
RCS file: /sources/texinfo/texinfo/tp/t/xml_tests.t,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- t/xml_tests.t       22 Nov 2011 00:34:58 -0000      1.6
+++ t/xml_tests.t       24 Aug 2012 23:03:49 -0000      1.7
@@ -140,7 +140,16 @@
 
 @macro bad { ggg"@@^_ ff, nnn_b, ccc v}
 @end macro
-']
+'],
+['commands_and_spaces',
+'@set  foo   some @value
+
address@hidden  ggg
+
address@hidden  @arrow
+
address@hidden  after  cropmarks.
+'],
 );
 
 foreach my $test (@test_cases) {

Index: t/results/xml_tests/commands_and_spaces.pl
===================================================================
RCS file: t/results/xml_tests/commands_and_spaces.pl
diff -N t/results/xml_tests/commands_and_spaces.pl
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ t/results/xml_tests/commands_and_spaces.pl  24 Aug 2012 23:03:49 -0000      
1.1
@@ -0,0 +1,138 @@
+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_elements %result_directions_text);
+
+use utf8;
+
+$result_trees{'commands_and_spaces'} = {
+  'contents' => [
+    {
+      'args' => [
+        {
+          'parent' => {},
+          'text' => 'foo',
+          'type' => 'misc_arg'
+        },
+        {
+          'parent' => {},
+          'text' => 'some @value',
+          'type' => 'misc_arg'
+        }
+      ],
+      'cmdname' => 'set',
+      'extra' => {
+        'arg_line' => '  foo   some @value
+'
+      },
+      'parent' => {}
+    },
+    {
+      'parent' => {},
+      'text' => '
+',
+      'type' => 'empty_line'
+    },
+    {
+      'args' => [
+        {
+          'parent' => {},
+          'text' => 'ggg',
+          'type' => 'misc_arg'
+        }
+      ],
+      'cmdname' => 'unmacro',
+      'extra' => {
+        'arg_line' => '  ggg
+'
+      },
+      'parent' => {}
+    },
+    {
+      'parent' => {},
+      'text' => '
+',
+      'type' => 'empty_line'
+    },
+    {
+      'args' => [
+        {
+          'parent' => {},
+          'text' => '@arrow',
+          'type' => 'misc_arg'
+        }
+      ],
+      'cmdname' => 'clickstyle',
+      'extra' => {
+        'arg_line' => '  @arrow
+'
+      },
+      'line_nr' => {
+        'file_name' => '',
+        'line_nr' => 5,
+        'macro' => ''
+      },
+      'parent' => {}
+    },
+    {
+      'parent' => {},
+      'text' => '
+',
+      'type' => 'empty_line'
+    },
+    {
+      'args' => [
+        {
+          'parent' => {},
+          'text' => '  after  cropmarks.
+',
+          'type' => 'misc_arg'
+        }
+      ],
+      'cmdname' => 'cropmarks',
+      'parent' => {}
+    }
+  ],
+  'type' => 'text_root'
+};
+$result_trees{'commands_and_spaces'}{'contents'}[0]{'args'}[0]{'parent'} = 
$result_trees{'commands_and_spaces'}{'contents'}[0];
+$result_trees{'commands_and_spaces'}{'contents'}[0]{'args'}[1]{'parent'} = 
$result_trees{'commands_and_spaces'}{'contents'}[0];
+$result_trees{'commands_and_spaces'}{'contents'}[0]{'parent'} = 
$result_trees{'commands_and_spaces'};
+$result_trees{'commands_and_spaces'}{'contents'}[1]{'parent'} = 
$result_trees{'commands_and_spaces'};
+$result_trees{'commands_and_spaces'}{'contents'}[2]{'args'}[0]{'parent'} = 
$result_trees{'commands_and_spaces'}{'contents'}[2];
+$result_trees{'commands_and_spaces'}{'contents'}[2]{'parent'} = 
$result_trees{'commands_and_spaces'};
+$result_trees{'commands_and_spaces'}{'contents'}[3]{'parent'} = 
$result_trees{'commands_and_spaces'};
+$result_trees{'commands_and_spaces'}{'contents'}[4]{'args'}[0]{'parent'} = 
$result_trees{'commands_and_spaces'}{'contents'}[4];
+$result_trees{'commands_and_spaces'}{'contents'}[4]{'parent'} = 
$result_trees{'commands_and_spaces'};
+$result_trees{'commands_and_spaces'}{'contents'}[5]{'parent'} = 
$result_trees{'commands_and_spaces'};
+$result_trees{'commands_and_spaces'}{'contents'}[6]{'args'}[0]{'parent'} = 
$result_trees{'commands_and_spaces'}{'contents'}[6];
+$result_trees{'commands_and_spaces'}{'contents'}[6]{'parent'} = 
$result_trees{'commands_and_spaces'};
+
+$result_texis{'commands_and_spaces'} = '@set  foo   some @value
+
address@hidden  ggg
+
address@hidden  @arrow
+
address@hidden  after  cropmarks.
+';
+
+
+$result_texts{'commands_and_spaces'} = '
+
+
+';
+
+$result_errors{'commands_and_spaces'} = [];
+
+
+
+$result_converted{'xml'}->{'commands_and_spaces'} = '<set name="foo" line="  
foo   some @value">some @value</set>
+
+
+<clickstyle command="arrow" line="  @arrow">@arrow</clickstyle>
+
+<cropmarks line="  after  cropmarks."></cropmarks>
+';
+
+1;



reply via email to

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