texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/Convert/DocBook.pm (convert, output,


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/Convert/DocBook.pm (convert, output, _convert): close sectioning command where the tree element is closed, not based on the unit element, in order to have the top level elements processed in the right order. Fix and simplify the code related to in_skipped_node_top, to not output Top node.
Date: Sat, 12 Mar 2022 12:10:44 -0500

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 0dbbf6ac76 * tp/Texinfo/Convert/DocBook.pm (convert, output, 
_convert): close sectioning command where the tree element is closed, not based 
on the unit element, in order to have the top level elements processed in the 
right order. Fix and simplify the code related to in_skipped_node_top, to not 
output Top node.
0dbbf6ac76 is described below

commit 0dbbf6ac762ff4d87b08557e64c73b57981cd3a6
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Mar 12 18:10:33 2022 +0100

    * tp/Texinfo/Convert/DocBook.pm (convert, output, _convert): close
    sectioning command where the tree element is closed, not based on
    the unit element, in order to have the top level elements processed
    in the right order.
    Fix and simplify the code related to in_skipped_node_top, to not
    output Top node.
---
 ChangeLog                                          |  9 ++++
 tp/Texinfo/Convert/DocBook.pm                      | 55 +++++++++++-----------
 .../sectioning/node_sectop_before_lone_node_Top.pl |  4 --
 .../section_before_after_top_node_last_node.pl     |  1 -
 tp/t/results/sectioning/section_before_top.pl      |  4 --
 .../sectioning/section_chapter_before_top_nodes.pl |  5 --
 .../sectioning/unnumbered_before_top_node.pl       |  6 ++-
 7 files changed, 42 insertions(+), 42 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 953c5ee9df..fc2560c1f1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2022-03-12  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Convert/DocBook.pm (convert, output, _convert): close
+       sectioning command where the tree element is closed, not based on
+       the unit element, in order to have the top level elements processed
+       in the right order.
+       Fix and simplify the code related to in_skipped_node_top, to not
+       output Top node.
+
 2022-03-12  Patrice Dumas  <pertusus@free.fr>
 
        Do not output Top node in DocBook
diff --git a/tp/Texinfo/Convert/DocBook.pm b/tp/Texinfo/Convert/DocBook.pm
index 01afb55ca9..c0d8f073b8 100644
--- a/tp/Texinfo/Convert/DocBook.pm
+++ b/tp/Texinfo/Convert/DocBook.pm
@@ -282,6 +282,10 @@ sub convert($$)
   if (! defined($self->{'lang_stack'})) {
     $self->{'lang_stack'} = [''];
   }
+  # could even set to 0 if defined?
+  $self->{'in_skipped_node_top'} = 0
+    if (! defined($self->{'in_skipped_node_top'}));
+
   return $self->convert_document_sections($root);
 }
 
@@ -345,7 +349,7 @@ sub output($$)
   }
 
   $self->{'lang_stack'} = [];
-  $self->{'in_skipped_node_top'} = undef;
+  $self->{'in_skipped_node_top'} = 0;
   my $lang = $DEFAULT_LANG;
   $self->set_global_document_commands('preamble', ['documentlanguage']);
   if (defined($self->get_conf('documentlanguage'))) {
@@ -623,6 +627,7 @@ sub _convert_argument_and_end_line($$)
   return ($converted, $end_line);
 }
 
+my $debug_global_element_nr = 0;
 
 
 sub _convert($$;$);
@@ -632,14 +637,19 @@ sub _convert($$;$)
   my $self = shift;
   my $element = shift;
 
+  my $debug_element_nr;
   #if (1) {
-  if (0) { # too verbose even for debugging, but for the bottom line ...
-    warn "root\n";
-    warn "  Command: $element->{'cmdname'}\n" if ($element->{'cmdname'});
-    warn "  Type: $element->{'type'}\n" if ($element->{'type'});
-    warn "  Text: $element->{'text'}\n" if (defined($element->{'text'}));
-    #warn "  Special def_command: $element->{'extra'}->{'def_command'}\n"
-    #  if (defined($element->{'extra'}) and 
$element->{'extra'}->{'def_command'});
+  if (0) { # verbose even for debugging
+    $debug_element_nr = $debug_global_element_nr++;
+    print STDERR "element $debug_element_nr";
+    print STDERR " cmd: $element->{'cmdname'}," if ($element->{'cmdname'});
+    print STDERR " type: $element->{'type'}" if ($element->{'type'});
+    my $text = $element->{'text'};
+    if (defined($text)) {
+      $text =~ s/\n/\\n/;
+      print STDERR " text: $text";
+    }
+    print STDERR "\n";
   }
 
   return '' if ($element->{'type'} and $ignored_types{$element->{'type'}});
@@ -779,11 +789,11 @@ sub _convert($$;$)
         if ($Texinfo::Common::root_commands{$element->{'cmdname'}}) {
           if ($self->get_conf('NO_TOP_NODE_OUTPUT')) {
             if ($element->{'cmdname'} eq 'node') {
-              if (not defined($self->{'in_skipped_node_top'})
-                  and $element->{'extra'}
+              if ($element->{'extra'}
                   and $element->{'extra'}->{'normalized'} eq 'Top') {
                 $self->{'in_skipped_node_top'} = 1;
-              } else {
+              } elsif (defined($self->{'in_skipped_node_top'})
+                       and $self->{'in_skipped_node_top'} == 1) {
                 $self->{'in_skipped_node_top'} = -1;
               }
             }
@@ -795,7 +805,7 @@ sub _convert($$;$)
               $result .= "<anchor 
id=\"$element->{'extra'}->{'normalized'}\"/>\n";
             }
           } else {
-            # start the section at the associated or at the sectioning command
+            # start the section at the associated node or at the sectioning 
command
             # if there is no associated node
             my $section_element;
             if ($element->{'cmdname'} eq 'node') {
@@ -1546,7 +1556,10 @@ sub _convert($$;$)
       $result .= $self->{'pending_prepend'};
       delete $self->{'pending_prepend'};
     }
+    #my $nr = -1;
     foreach my $content (@{$element->{'contents'}}) {
+      #$nr++;
+      #print STDERR "C$debug_element_nr[$nr] 
".Texinfo::Common::debug_print_element_short($content)."\n";
       $result .= $self->_convert($content);
     }
     pop @{$self->{'document_context'}->[-1]->{'monospace'}}
@@ -1589,21 +1602,9 @@ sub _convert($$;$)
     my $format = pop 
@{$self->{'document_context'}->[-1]->{'preformatted_stack'}};
     die "BUG $format ne $docbook_preformatted_formats{$element->{'type'}}"
       if ($format ne $docbook_preformatted_formats{$element->{'type'}});
-
-  # The command is closed either when the corresponding tree element
-  # is done, and the command is not associated to an element, or when
-  # the element is closed.
-  } elsif (($element->{'type'} and $element->{'type'} eq 'unit'
-            and $element->{'extra'} and $element->{'extra'}->{'unit_command'})
-           or ($element->{'cmdname'}
-               and $Texinfo::Common::root_commands{$element->{'cmdname'}}
-               and $element->{'cmdname'} ne 'node'
-               and !($element->{'structure'}->{'associated_unit'}
-                     and 
$element->{'structure'}->{'associated_unit'}->{'extra'}
-                     and 
$element->{'structure'}->{'associated_unit'}->{'extra'}->{'unit_command'} eq 
$element))) {
-    if ($element->{'type'} and $element->{'type'} eq 'unit') {
-      $element = $element->{'extra'}->{'unit_command'};
-    }
+  # close sectioning command
+  } elsif ($element->{'cmdname'} and $element->{'cmdname'} ne 'node'
+           and $Texinfo::Common::root_commands{$element->{'cmdname'}}) {
     my $docbook_sectioning_element = $self->_docbook_section_element($element);
     if ($docbook_sectioning_element eq 'part'
         and !Texinfo::Common::is_content_empty($element)) {
diff --git a/tp/t/results/sectioning/node_sectop_before_lone_node_Top.pl 
b/tp/t/results/sectioning/node_sectop_before_lone_node_Top.pl
index ed35e9d737..1fd3d45372 100644
--- a/tp/t/results/sectioning/node_sectop_before_lone_node_Top.pl
+++ b/tp/t/results/sectioning/node_sectop_before_lone_node_Top.pl
@@ -560,10 +560,6 @@ 
$result_converted{'docbook'}->{'node_sectop_before_lone_node_Top'} = '<chapter l
 
 <para>in node before
 </para>
-<anchor id="Top"/>
-
-<para>in node Top
-</para>
 </chapter>
 <chapter label="1" id="chap">
 <title>chap</title>
diff --git a/tp/t/results/sectioning/section_before_after_top_node_last_node.pl 
b/tp/t/results/sectioning/section_before_after_top_node_last_node.pl
index 9066ecdb04..0b9ccdc080 100644
--- a/tp/t/results/sectioning/section_before_after_top_node_last_node.pl
+++ b/tp/t/results/sectioning/section_before_after_top_node_last_node.pl
@@ -519,7 +519,6 @@ 
$result_converted{'docbook'}->{'section_before_after_top_node_last_node'} = '<ch
 
 </chapter>
 <anchor id="node-after"/>
-</chapter>
 ';
 
 
diff --git a/tp/t/results/sectioning/section_before_top.pl 
b/tp/t/results/sectioning/section_before_top.pl
index 1a36d5c325..ac7acd8cfb 100644
--- a/tp/t/results/sectioning/section_before_top.pl
+++ b/tp/t/results/sectioning/section_before_top.pl
@@ -590,10 +590,6 @@ $result_converted{'xml'}->{'section_before_top'} = '<node 
name="section-node" sp
 $result_converted{'docbook'}->{'section_before_top'} = '<sect1 label="1" 
id="section-node">
 <title>section</title>
 
-</sect1>
-<sect1 label="" id="Top">
-<title>top</title>
-
 </sect1>
 ';
 
diff --git a/tp/t/results/sectioning/section_chapter_before_top_nodes.pl 
b/tp/t/results/sectioning/section_chapter_before_top_nodes.pl
index 68bd81e861..a40ada9ec0 100644
--- a/tp/t/results/sectioning/section_chapter_before_top_nodes.pl
+++ b/tp/t/results/sectioning/section_chapter_before_top_nodes.pl
@@ -952,11 +952,6 @@ 
$result_converted{'docbook'}->{'section_chapter_before_top_nodes'} = '<sect1 lab
 <title>chapter</title>
 
 
-</sect1>
-<sect1 label="" id="Top">
-<title>top</title>
-
-
 </sect1>
 ';
 
diff --git a/tp/t/results/sectioning/unnumbered_before_top_node.pl 
b/tp/t/results/sectioning/unnumbered_before_top_node.pl
index cf1885e727..3076594e9c 100644
--- a/tp/t/results/sectioning/unnumbered_before_top_node.pl
+++ b/tp/t/results/sectioning/unnumbered_before_top_node.pl
@@ -369,6 +369,10 @@ $result_converted{'html'}->{'unnumbered_before_top_node'} 
= '<!DOCTYPE html>
 ';
 
 
-$result_converted{'docbook'}->{'unnumbered_before_top_node'} = '';
+$result_converted{'docbook'}->{'unnumbered_before_top_node'} = '<chapter 
label="">
+<title>before nodes</title>
+
+</chapter>
+';
 
 1;



reply via email to

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