texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/Transformations.pm (_new_node): buil


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/Transformations.pm (_new_node): build a tree for a node in line with the current nodes Texinfo tree.
Date: Sun, 18 Sep 2022 12:11:45 -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 e23d141d80 * tp/Texinfo/Transformations.pm (_new_node): build a tree 
for a node in line with the current nodes Texinfo tree.
e23d141d80 is described below

commit e23d141d807ebe5c6eed5490b75d2b4afa536c71
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Sep 18 18:11:33 2022 +0200

    * tp/Texinfo/Transformations.pm (_new_node): build a tree
    for a node in line with the current nodes Texinfo tree.
---
 ChangeLog                     |  5 +++++
 tp/Texinfo/Transformations.pm | 47 ++++++++++++++++++++++++++-----------------
 tp/t/automatic_nodes.t        |  2 +-
 3 files changed, 35 insertions(+), 19 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 97b3cf94f8..fb3d1022f8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2022-09-18  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Transformations.pm (_new_node): build a tree
+       for a node in line with the current nodes Texinfo tree.
+
 2022-09-18  Patrice Dumas  <pertusus@free.fr>
 
        * Pod-Simple-Texinfo/lib/Pod/Simple/Texinfo.pm
diff --git a/tp/Texinfo/Transformations.pm b/tp/Texinfo/Transformations.pm
index 22c4255b1e..b17cef0b46 100644
--- a/tp/Texinfo/Transformations.pm
+++ b/tp/Texinfo/Transformations.pm
@@ -227,14 +227,20 @@ sub _new_node($$$$)
     $empty_node = 1;
   }
 
-  unless (($node_tree->{'contents'}->[-1]->{'cmdname'}
-       and ($node_tree->{'contents'}->[-1]->{'cmdname'} eq 'c'
-            or $node_tree->{'contents'}->[-1]->{'cmdname'} eq 'comment'))
-      or (defined($node_tree->{'contents'}->[-1]->{'text'})
-          and $node_tree->{'contents'}->[-1]->{'text'} =~ /\n/)) {
-    push @{$node_tree->{'contents'}},
-           {'type' => 'spaces_at_end', 'text' => "\n"};
+  my $comment_at_end;
+  if ($node_tree->{'contents'}->[-1]->{'cmdname'}
+      and ($node_tree->{'contents'}->[-1]->{'cmdname'} eq 'c'
+           or $node_tree->{'contents'}->[-1]->{'cmdname'} eq 'comment')) {
+    $comment_at_end = pop @{$node_tree->{'contents'}};
   }
+  my $spaces_after_argument = '';
+  if (scalar(@{$node_tree->{'contents'}}) > 0
+             and $node_tree->{'contents'}->[-1]->{'text'}
+             and $node_tree->{'contents'}->[-1]->{'text'} =~ s/(\s+)$//) {
+    $spaces_after_argument = $1;
+  }
+  $spaces_after_argument .= "\n" unless ($spaces_after_argument =~ /\n/
+                                         or $comment_at_end);
 
   my $appended_number = 0 +$empty_node;
   my ($node, $parsed_node);
@@ -242,28 +248,33 @@ sub _new_node($$$$)
   while (!defined($node)
          or ($labels
             and $labels->{$parsed_node->{'normalized'}})) {
-    $node = {'cmdname' => 'node', 'args' => [{}],
+    $node = {'cmdname' => 'node',
+             'args' => [
+               {'type' => 'line_arg',
+                'extra' =>
+                    {'spaces_after_argument' => $spaces_after_argument}}
+             ],
              'extra' => {'spaces_before_argument' => ' '}};
-    my $node_arg = $node->{'args'}->[0];
-    $node_arg->{'parent'} = $node;
-    @{$node_arg->{'contents'}} = (
-        @{$node_tree->{'contents'}});
+    my $node_line_arg = $node->{'args'}->[0];
+    $node_line_arg->{'parent'} = $node;
+    $node_line_arg->{'extra'}->{'comment_at_end'} = $comment_at_end
+      if (defined($comment_at_end));
+    @{$node_line_arg->{'contents'}} = (@{$node_tree->{'contents'}});
     if ($appended_number) {
-      splice (@{$node_arg->{'contents'}}, -1, 0,
-                  {'text' => " $appended_number"});
+      push @{$node_line_arg->{'contents'}}, {'text' => " $appended_number"};
     }
-    foreach my $content (@{$node_arg->{'contents'}}) {
-      $content->{'parent'} = $node_arg;
+    foreach my $content (@{$node_line_arg->{'contents'}}) {
+      $content->{'parent'} = $node_line_arg;
     }
     my $modified_node_content;
     ($parsed_node, $modified_node_content)
-       = Texinfo::Common::parse_node_manual($node_arg);
+       = Texinfo::Common::parse_node_manual($node_line_arg);
     if ($parsed_node and $parsed_node->{'node_content'}) {
       $parsed_node->{'normalized'} =
        Texinfo::Convert::NodeNameNormalization::normalize_node(
         { 'contents' => $parsed_node->{'node_content'} });
     }
-    $node_arg->{'contents'} = $modified_node_content;
+    $node_line_arg->{'contents'} = $modified_node_content;
     if (!defined($parsed_node) or !$parsed_node->{'node_content'}
         or $parsed_node->{'normalized'} !~ /[^-]/) {
       if ($appended_number) {
diff --git a/tp/t/automatic_nodes.t b/tp/t/automatic_nodes.t
index 756544e98e..ec9b2f099f 100644
--- a/tp/t/automatic_nodes.t
+++ b/tp/t/automatic_nodes.t
@@ -58,7 +58,7 @@ sub test_new_node($$$$)
 test_new_node ('a node', 'a-node', '@node a node
 ', 'simple');
 test_new_node ('a node @code{in code} @c comment
-', 'a-node-in-code-', '@node a node @code{in code} @c comment
+', 'a-node-in-code', '@node a node @code{in code} @c comment
 ', 'complex');
 test_new_node ('a ,, node @code{a,b,}', 'a-_002c_002c-node-a_002cb_002c',
 '@node a @comma{}@comma{} node @code{a@comma{}b@comma{}}



reply via email to

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