texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/Convert/TexinfoMarkup.pm (_convert):


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/Convert/TexinfoMarkup.pm (_convert): on block command lines, output empty elements for all the variadic elements, including the last non variadic element, which has the same name as the variadic element, to have a correct count on elements, as the element name appearing last cannot be used to add commas for empty elements. Keep the last non-variadic empty argument to be able to prepend it to be able to reconstitute trailing empty arguments in the original Texinfo code.
Date: Sat, 01 Oct 2022 17:19:15 -0400

This is an automated email from the git hooks/post-receive script.

pertusus pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new 1a72f46883 * tp/Texinfo/Convert/TexinfoMarkup.pm (_convert): on block 
command lines, output empty elements for all the variadic elements, including 
the last non variadic element, which has the same name as the variadic element, 
to have a correct count on elements, as the element name appearing last cannot 
be used to add commas for empty elements. Keep the last non-variadic empty 
argument to be able to prepend it to be able to reconstitute trailing empty 
arguments in the original  [...]
1a72f46883 is described below

commit 1a72f468836a56a4efc2ee3b7101eed65bd3834b
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Oct 1 23:17:00 2022 +0200

    * tp/Texinfo/Convert/TexinfoMarkup.pm (_convert): on block command
    lines, output empty elements for all the variadic elements, including
    the last non variadic element, which has the same name as the variadic
    element, to have a correct count on elements, as the element name
    appearing last cannot be used to add commas for empty elements.
    Keep the last non-variadic empty argument to be able to prepend it to
    be able to reconstitute trailing empty arguments in the original
    Texinfo code.
---
 ChangeLog                                          | 11 +++++
 tp/Texinfo/Convert/TexinfoMarkup.pm                | 56 ++++++++++++++--------
 .../res_parser/formatting_xml/formatting.xml       | 16 +++----
 3 files changed, 54 insertions(+), 29 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 466a61e1fa..e3c7dbf1cb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2022-10-01  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Convert/TexinfoMarkup.pm (_convert): on block command
+       lines, output empty elements for all the variadic elements, including
+       the last non variadic element, which has the same name as the variadic
+       element, to have a correct count on elements, as the element name
+       appearing last cannot be used to add commas for empty elements.
+       Keep the last non-variadic empty argument to be able to prepend it to
+       be able to reconstitute trailing empty arguments in the original
+       Texinfo code.
+
 2022-10-01  Gavin Smith  <gavinsmith0123@gmail.com>
 
        * tp/Texinfo/Convert/LaTeX.pm (_latex_header):
diff --git a/tp/Texinfo/Convert/TexinfoMarkup.pm 
b/tp/Texinfo/Convert/TexinfoMarkup.pm
index 9018aa84e6..4479032ac6 100644
--- a/tp/Texinfo/Convert/TexinfoMarkup.pm
+++ b/tp/Texinfo/Convert/TexinfoMarkup.pm
@@ -1220,13 +1220,12 @@ sub _convert($$;$)
                                     $end_command_space])
                    .${prepended_elements};
         if ($element->{'args'}) {
+          my $variadic_element = undef;
+          my $last_empty_element;
           my $end_line = '';
           if ($commands_args_elements{$element->{'cmdname'}}) {
             my $arg_index = 0;
-            my $variadic_element = undef;
-            while (defined($commands_args_elements{$element->{'cmdname'}}
-                                                                ->[$arg_index])
-                   or defined($variadic_element)) {
+            foreach my $arg_element (@{$element->{'args'}}) {
               my $format_element;
               if (defined($variadic_element)) {
                 $format_element = $variadic_element;
@@ -1237,13 +1236,23 @@ sub _convert($$;$)
                         = $commands_args_elements{$element->{'cmdname'}}
                                                                
->[$arg_index-1];
                   $format_element = $variadic_element;
+                  # the last argument was empty, it is the same argument
+                  # as the variadic argument, it needs to be output to have
+                  # it count as the last non variadic argument.
+                  if ($last_empty_element) {
+                    $result .= $last_empty_element;
+                    $last_empty_element = undef;
+                  }
                 } else {
                   $format_element
                     = $commands_args_elements{$element->{'cmdname'}}
                                                         ->[$arg_index];
                 }
               }
-              if (defined($element->{'args'}->[$arg_index])) {
+              my $spaces = [];
+              my $arg = '';
+              my $end_space = '';
+              if (defined($arg_element)) {
                 my $in_code;
                  $in_code = 1
                   if (defined($default_args_code_style{$element->{'cmdname'}})
@@ -1251,34 +1260,39 @@ sub _convert($$;$)
                                                                ->[$arg_index]);
                 push @{$self->{'document_context'}->[-1]->{'monospace'}}, 1
                   if ($in_code);
-                my ($arg, $end_space);
                 if ($arg_index+1 eq scalar(@{$element->{'args'}})) {
                   # last argument
                   ($arg, $end_space, $end_line)
                     = $self->_convert_argument_and_end_line($element);
                 } else {
-                  $arg = $self->_convert($element->{'args'}->[$arg_index]);
-                  $end_space = '';
-                }
-                my $spaces = [];
-                if ($arg_index != 0) {
-                  push @$spaces, _leading_spaces_arg(
-                                              
$element->{'args'}->[$arg_index]);
-                }
-                if ($arg ne '' or scalar(@$spaces)) {
-                  $result .= $self->txi_markup_open_element($format_element, 
$spaces)
-                                     .$arg.$end_space
-                                     
.$self->txi_markup_close_element($format_element);
-                } else {
-                  $result .= $end_space;
+                  $arg = $self->_convert($arg_element);
                 }
                 pop @{$self->{'document_context'}->[-1]->{'monospace'}}
                   if ($in_code);
+                if ($arg_index != 0) {
+                  push @$spaces, _leading_spaces_arg($arg_element);
+                }
+              }
+              # must add every variadic argument even if empty to get the 
correct count
+              if ($arg ne '' or scalar(@$spaces) or $variadic_element) {
+                $result .= $self->txi_markup_open_element($format_element, 
$spaces)
+                                   .$arg.$end_space
+                                   
.$self->txi_markup_close_element($format_element);
+                $last_empty_element = undef;
               } else {
-                last;
+                $result .= $end_space;
+                if ($arg_index > 0) {
+                  # we keep the last empty argument to be able to prepend it 
to be able
+                  # to reconstitute trailing empty arguments in the original 
Texinfo code.
+                  $last_empty_element = 
$self->txi_markup_open_element($format_element)
+                                
.$self->txi_markup_close_element($format_element);
+                }
               }
               $arg_index++;
             }
+            if ($last_empty_element) {
+              $result .= $last_empty_element;
+            }
             $result .= $end_line;
           } else {
 
diff --git a/tp/tests/layout/res_parser/formatting_xml/formatting.xml 
b/tp/tests/layout/res_parser/formatting_xml/formatting.xml
index 712f2375b0..f9fc94dc41 100644
--- a/tp/tests/layout/res_parser/formatting_xml/formatting.xml
+++ b/tp/tests/layout/res_parser/formatting_xml/formatting.xml
@@ -1723,11 +1723,11 @@ quotation
 <example spaces=" " endspaces=" "><examplelanguage>&arobase; at the end of 
line <spacecmd type="nl"/></examplelanguage><pre xml:space="preserve">A 
&arobase; at the end of the &arobase;example line.
 </pre></example>
 
-<example spaces=" " endspaces=" ">
+<example spaces=" " endspaces=" 
"><examplearg></examplearg><examplearg></examplearg><examplearg></examplearg><examplearg></examplearg><examplearg></examplearg><examplearg></examplearg>
 <pre xml:space="preserve">example with empty args
 </pre></example>
 
-<example spaces=" " endspaces=" "><examplearg>nonempty</examplearg>
+<example spaces=" " endspaces=" 
"><examplearg></examplearg><examplearg></examplearg><examplearg>nonempty</examplearg><examplearg></examplearg><examplearg></examplearg><examplearg></examplearg>
 <pre xml:space="preserve">example with empty and non empty args mix
 </pre></example>
 
@@ -2862,11 +2862,11 @@ quotation
 <example spaces=" " endspaces=" "><examplelanguage>&arobase; at the end of 
line <spacecmd type="nl"/></examplelanguage><pre xml:space="preserve">A 
&arobase; at the end of the &arobase;example line.
 </pre></example>
 
-<example spaces=" " endspaces=" ">
+<example spaces=" " endspaces=" 
"><examplearg></examplearg><examplearg></examplearg><examplearg></examplearg><examplearg></examplearg><examplearg></examplearg><examplearg></examplearg>
 <pre xml:space="preserve">example with empty args
 </pre></example>
 
-<example spaces=" " endspaces=" "><examplearg>nonempty</examplearg>
+<example spaces=" " endspaces=" 
"><examplearg></examplearg><examplearg></examplearg><examplearg>nonempty</examplearg><examplearg></examplearg><examplearg></examplearg><examplearg></examplearg>
 <pre xml:space="preserve">example with empty and non empty args mix
 </pre></example>
 
@@ -4028,11 +4028,11 @@ quotation
 <example spaces=" " endspaces=" "><examplelanguage>&arobase; at the end of 
line <spacecmd type="nl"/></examplelanguage><pre xml:space="preserve">A 
&arobase; at the end of the &arobase;example line.
 </pre></example>
 
-<example spaces=" " endspaces=" ">
+<example spaces=" " endspaces=" 
"><examplearg></examplearg><examplearg></examplearg><examplearg></examplearg><examplearg></examplearg><examplearg></examplearg><examplearg></examplearg>
 <pre xml:space="preserve">example with empty args
 </pre></example>
 
-<example spaces=" " endspaces=" "><examplearg>nonempty</examplearg>
+<example spaces=" " endspaces=" 
"><examplearg></examplearg><examplearg></examplearg><examplearg>nonempty</examplearg><examplearg></examplearg><examplearg></examplearg><examplearg></examplearg>
 <pre xml:space="preserve">example with empty and non empty args mix
 </pre></example>
 
@@ -5162,11 +5162,11 @@ indent in quotation
 </pre><example spaces=" " endspaces=" "><examplelanguage>&arobase; at the end 
of line <spacecmd type="nl"/></examplelanguage><pre xml:space="preserve">A 
&arobase; at the end of the &arobase;example line.
 </pre></example>
 <pre xml:space="preserve">
-</pre><example spaces=" " endspaces=" ">
+</pre><example spaces=" " endspaces=" 
"><examplearg></examplearg><examplearg></examplearg><examplearg></examplearg><examplearg></examplearg><examplearg></examplearg><examplearg></examplearg>
 <pre xml:space="preserve">example with empty args
 </pre></example>
 <pre xml:space="preserve">
-</pre><example spaces=" " endspaces=" "><examplearg>nonempty</examplearg>
+</pre><example spaces=" " endspaces=" 
"><examplearg></examplearg><examplearg></examplearg><examplearg>nonempty</examplearg><examplearg></examplearg><examplearg></examplearg><examplearg></examplearg>
 <pre xml:space="preserve">example with empty and non empty args mix
 </pre></example>
 <pre xml:space="preserve">



reply via email to

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