texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/Convert/HTML.pm (_set_root_commands_


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/Convert/HTML.pm (_set_root_commands_targets_node_files): handle undef returned by user defined node_file_name by reusing the default file name.
Date: Tue, 11 Oct 2022 04:41:23 -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 d8250ab640 * tp/Texinfo/Convert/HTML.pm 
(_set_root_commands_targets_node_files): handle undef returned by user defined 
node_file_name by reusing the default file name.
d8250ab640 is described below

commit d8250ab640d7244a7cef59c7022779b42b74f11a
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Tue Oct 11 10:41:08 2022 +0200

    * tp/Texinfo/Convert/HTML.pm (_set_root_commands_targets_node_files):
    handle undef returned by user defined node_file_name by reusing
    the default file name.
    
    * tp/Texinfo/Convert/HTML.pm (_html_set_pages_files): always use
    targets node_filename to determine a node file name.
    
    * tp/Texinfo/Convert/Converter.pm (_set_tree_units_files): use
    a variable in code for clarity.
---
 ChangeLog                                          |  12 ++
 tp/Makefile.am                                     |  13 +-
 tp/TODO                                            |   6 +
 tp/Texinfo/Convert/Converter.pm                    |   8 +-
 tp/Texinfo/Convert/HTML.pm                         |  26 +--
 tp/t/init/undef_node_file_name.init                |  22 +++
 tp/t/init_files_tests.t                            |   6 +
 .../init_files_tests/undefined_node_filename.pl    | 177 +++++++++++++++++++++
 .../undefined_node_filename/res_html/Other.html    |  31 ++++
 .../undefined_node_filename/res_html/index.html    |  37 +++++
 10 files changed, 319 insertions(+), 19 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8ed843cf9f..d75e6dca99 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2022-10-11  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Convert/HTML.pm (_set_root_commands_targets_node_files):
+       handle undef returned by user defined node_file_name by reusing
+       the default file name.
+
+       * tp/Texinfo/Convert/HTML.pm (_html_set_pages_files): always use
+       targets node_filename to determine a node file name.
+
+       * tp/Texinfo/Convert/Converter.pm (_set_tree_units_files): use
+       a variable in code for clarity.
+
 2022-10-10  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Common.pm: add code (not active) to check
diff --git a/tp/Makefile.am b/tp/Makefile.am
index 4392834c75..be13eb9c6d 100644
--- a/tp/Makefile.am
+++ b/tp/Makefile.am
@@ -162,19 +162,20 @@ test_files = \
  t/include/incl-incl.txi \
  t/include/macro_included.texi \
  t/include/section_file.texi \
+ t/init/command_translation_modified.init \
  t/init/cvs.init \
+ t/init/icons.init \
+ t/init/ignore_and_comments_output.init \
+ t/init/l2h.init \
+ t/init/mini_ker_t2h.init \
+ t/init/misc_file_collision.init \
  t/init/only_toc_out.init \
  t/init/redefine_need.init \
- t/init/icons.init \
  t/init/t2h_singular.init \
- t/init/ignore_and_comments_output.init \
  t/init/test_directions.init \
- t/init/mini_ker_t2h.init \
  t/init/test_renamed_nodes.init \
- t/init/misc_file_collision.init \
- t/init/l2h.init \
- t/init/command_translation_modified.init \
  t/init/translate_txiinternalvalue_macro.init \
+ t/init/undef_node_file_name.init \
  t/test_utils.pl \
  t/input_files/all_spaces.texi \
  t/input_files/bib-example.texi \
diff --git a/tp/TODO b/tp/TODO
index 32614de65d..5c06820117 100644
--- a/tp/TODO
+++ b/tp/TODO
@@ -12,6 +12,12 @@ Before next release
 
 Add in_math (for /)?
 
+set_tree_unit_file should also only be called once per file. HTML
+needs to be changed and a check added to set_tree_unit_file.
+Also maybe do not set $tree_unit->{'structure'}->{'unit_filename'}
+in set_tree_unit_file and change the name of the function.  Maybe
+split in two.
+
 Bugs
 ====
 
diff --git a/tp/Texinfo/Convert/Converter.pm b/tp/Texinfo/Convert/Converter.pm
index 5b486993bb..a1902bc291 100644
--- a/tp/Texinfo/Convert/Converter.pm
+++ b/tp/Texinfo/Convert/Converter.pm
@@ -894,11 +894,11 @@ sub _set_tree_units_files($$$$$$)
       # For Top node.
       next if ($tree_unit->{'structure'}
                and defined($tree_unit->{'structure'}->{'unit_filename'}));
-      if (!$tree_unit->{'extra'}->{'first_in_page'}) {
+      my $file_tree_unit = $tree_unit->{'extra'}->{'first_in_page'};
+      if (!$file_tree_unit) {
         cluck ("No first_in_page for $tree_unit\n");
       }
-      if 
(!defined($tree_unit->{'extra'}->{'first_in_page'}->{'structure'}->{'unit_filename'}))
 {
-        my $file_tree_unit = $tree_unit->{'extra'}->{'first_in_page'};
+      if (!defined($file_tree_unit->{'structure'}->{'unit_filename'})) {
         foreach my $root_command (@{$file_tree_unit->{'contents'}}) {
           if ($root_command->{'cmdname'}
               and $root_command->{'cmdname'} eq 'node') {
@@ -947,7 +947,7 @@ sub _set_tree_units_files($$$$$$)
         }
       }
       $tree_unit->{'structure'}->{'unit_filename'}
-        = 
$tree_unit->{'extra'}->{'first_in_page'}->{'structure'}->{'unit_filename'};
+        = $file_tree_unit->{'structure'}->{'unit_filename'};
     }
   }
 
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 773cfef13f..c523e53920 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -7659,8 +7659,22 @@ sub _set_root_commands_targets_node_files($$)
         = $self->_normalized_label_id_file($label_element->{'extra'});
       $node_filename .= $extension;
       if (defined($self->{'file_id_setting'}->{'node_file_name'})) {
-        $node_filename = &{$self->{'file_id_setting'}->{'node_file_name'}}(
+        # a non defined filename is ok if called with convert, but not
+        # if output in files.  We reset if undef, silently unless verbose
+        # in case called by convert.
+        my $user_node_filename
+              = &{$self->{'file_id_setting'}->{'node_file_name'}}(
                                        $self, $label_element, $node_filename);
+        if (defined($user_node_filename)) {
+          $node_filename = $user_node_filename;
+        } elsif ($self->get_conf('VERBOSE')) {
+          $self->document_warn($self, sprintf(__(
+              "user-defined node file name not set for `%s'"),
+              $node_filename));
+
+        } elsif ($self->get_conf('DEBUG')) {
+          warn "user-defined node file name undef for `$node_filename'\n";
+        }
       }
       if ($self->get_conf('DEBUG')) {
         print STDERR "Label($label_element) \@$label_element->{'cmdname'} 
$target, $node_filename\n";
@@ -7823,14 +7837,8 @@ sub _html_set_pages_files($$$$$$$$)
               $node_filename = 'unknown_node';
               $node_filename .= $extension;
             } else {
-              if (!defined($self->{'targets'}->{$root_command})
-                  or 
!defined($self->{'targets'}->{$root_command}->{'node_filename'})) {
-                # Could have been a double node, thus use equivalent node.
-                # However since double nodes are not normalized, in fact it
-                # never happens.
-                $root_command
-                  = 
$self->{'labels'}->{$root_command->{'extra'}->{'normalized'}};
-              }
+              # Nodes with {'extra'}->{'normalized'} should always be in
+              # 'labels', and thus in targets.  It is a bug otherwise.
               $node_filename
                 = $self->{'targets'}->{$root_command}->{'node_filename'};
             }
diff --git a/tp/t/init/undef_node_file_name.init 
b/tp/t/init/undef_node_file_name.init
new file mode 100644
index 0000000000..bd85102554
--- /dev/null
+++ b/tp/t/init/undef_node_file_name.init
@@ -0,0 +1,22 @@
+use strict;
+
+sub _undef_node_file_name($$$)
+{
+  my $self = shift;
+  my $element = shift;
+  my $filename = shift;
+
+  if ($element->{'extra'}
+      and $element->{'extra'}->{'normalized'}) {
+    my $normalized_node_name
+       = $element->{'extra'}->{'normalized'};
+    if ($normalized_node_name eq 'Other') {
+      return undef;
+    }
+  }
+  return $filename;
+}
+
+texinfo_register_file_id_setting_function('node_file_name', 
\&_undef_node_file_name);
+
+1;
diff --git a/tp/t/init_files_tests.t b/tp/t/init_files_tests.t
index 0c44709c93..129e049a66 100644
--- a/tp/t/init_files_tests.t
+++ b/tp/t/init_files_tests.t
@@ -31,6 +31,12 @@ pt @error{}.
 );
 
 my @file_tests = (
+['undefined_node_filename',
+'@node Top
+
+@node Other
+',{'init_files' => ['undef_node_file_name.init'],
+}, {'VERBOSE' => 1}],
 ['documentation_examples',
 '
 @settitle @email{someone@@example.com, me} @sansserif{in--title} @error{}
diff --git a/tp/t/results/init_files_tests/undefined_node_filename.pl 
b/tp/t/results/init_files_tests/undefined_node_filename.pl
new file mode 100644
index 0000000000..3adf40c769
--- /dev/null
+++ b/tp/t/results/init_files_tests/undefined_node_filename.pl
@@ -0,0 +1,177 @@
+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 %result_indices_sort_strings);
+
+use utf8;
+
+$result_trees{'undefined_node_filename'} = {
+  'contents' => [
+    {
+      'parent' => {},
+      'type' => 'before_node_section'
+    },
+    {
+      'args' => [
+        {
+          'contents' => [
+            {
+              'parent' => {},
+              'text' => 'Top'
+            }
+          ],
+          'extra' => {
+            'spaces_after_argument' => '
+'
+          },
+          'parent' => {},
+          'type' => 'line_arg'
+        }
+      ],
+      'cmdname' => 'node',
+      'contents' => [
+        {
+          'parent' => {},
+          'text' => '
+',
+          'type' => 'empty_line'
+        }
+      ],
+      'extra' => {
+        'node_content' => [
+          {}
+        ],
+        'nodes_manuals' => [
+          {
+            'node_content' => [
+              {}
+            ],
+            'normalized' => 'Top'
+          }
+        ],
+        'normalized' => 'Top',
+        'spaces_before_argument' => ' '
+      },
+      'parent' => {},
+      'source_info' => {
+        'file_name' => '',
+        'line_nr' => 1,
+        'macro' => ''
+      }
+    },
+    {
+      'args' => [
+        {
+          'contents' => [
+            {
+              'parent' => {},
+              'text' => 'Other'
+            }
+          ],
+          'extra' => {
+            'spaces_after_argument' => '
+'
+          },
+          'parent' => {},
+          'type' => 'line_arg'
+        }
+      ],
+      'cmdname' => 'node',
+      'extra' => {
+        'node_content' => [
+          {}
+        ],
+        'nodes_manuals' => [
+          {
+            'node_content' => [
+              {}
+            ],
+            'normalized' => 'Other'
+          }
+        ],
+        'normalized' => 'Other',
+        'spaces_before_argument' => ' '
+      },
+      'parent' => {},
+      'source_info' => {
+        'file_name' => '',
+        'line_nr' => 3,
+        'macro' => ''
+      }
+    }
+  ],
+  'type' => 'document_root'
+};
+$result_trees{'undefined_node_filename'}{'contents'}[0]{'parent'} = 
$result_trees{'undefined_node_filename'};
+$result_trees{'undefined_node_filename'}{'contents'}[1]{'args'}[0]{'contents'}[0]{'parent'}
 = $result_trees{'undefined_node_filename'}{'contents'}[1]{'args'}[0];
+$result_trees{'undefined_node_filename'}{'contents'}[1]{'args'}[0]{'parent'} = 
$result_trees{'undefined_node_filename'}{'contents'}[1];
+$result_trees{'undefined_node_filename'}{'contents'}[1]{'contents'}[0]{'parent'}
 = $result_trees{'undefined_node_filename'}{'contents'}[1];
+$result_trees{'undefined_node_filename'}{'contents'}[1]{'extra'}{'node_content'}[0]
 = 
$result_trees{'undefined_node_filename'}{'contents'}[1]{'args'}[0]{'contents'}[0];
+$result_trees{'undefined_node_filename'}{'contents'}[1]{'extra'}{'nodes_manuals'}[0]{'node_content'}[0]
 = 
$result_trees{'undefined_node_filename'}{'contents'}[1]{'args'}[0]{'contents'}[0];
+$result_trees{'undefined_node_filename'}{'contents'}[1]{'parent'} = 
$result_trees{'undefined_node_filename'};
+$result_trees{'undefined_node_filename'}{'contents'}[2]{'args'}[0]{'contents'}[0]{'parent'}
 = $result_trees{'undefined_node_filename'}{'contents'}[2]{'args'}[0];
+$result_trees{'undefined_node_filename'}{'contents'}[2]{'args'}[0]{'parent'} = 
$result_trees{'undefined_node_filename'}{'contents'}[2];
+$result_trees{'undefined_node_filename'}{'contents'}[2]{'extra'}{'node_content'}[0]
 = 
$result_trees{'undefined_node_filename'}{'contents'}[2]{'args'}[0]{'contents'}[0];
+$result_trees{'undefined_node_filename'}{'contents'}[2]{'extra'}{'nodes_manuals'}[0]{'node_content'}[0]
 = 
$result_trees{'undefined_node_filename'}{'contents'}[2]{'args'}[0]{'contents'}[0];
+$result_trees{'undefined_node_filename'}{'contents'}[2]{'parent'} = 
$result_trees{'undefined_node_filename'};
+
+$result_texis{'undefined_node_filename'} = '@node Top
+
+@node Other
+';
+
+
+$result_texts{'undefined_node_filename'} = '
+';
+
+$result_nodes{'undefined_node_filename'} = {
+  'cmdname' => 'node',
+  'extra' => {
+    'normalized' => 'Top'
+  },
+  'structure' => {
+    'node_next' => {
+      'cmdname' => 'node',
+      'extra' => {
+        'normalized' => 'Other'
+      },
+      'structure' => {
+        'node_prev' => {}
+      }
+    }
+  }
+};
+$result_nodes{'undefined_node_filename'}{'structure'}{'node_next'}{'structure'}{'node_prev'}
 = $result_nodes{'undefined_node_filename'};
+
+$result_menus{'undefined_node_filename'} = {
+  'cmdname' => 'node',
+  'extra' => {
+    'normalized' => 'Top'
+  },
+  'structure' => {}
+};
+
+$result_errors{'undefined_node_filename'} = [];
+
+
+$result_floats{'undefined_node_filename'} = {};
+
+
+$result_converted_errors{'file_html'}->{'undefined_node_filename'} = [
+  {
+    'error_line' => 'warning: user-defined node file name not set for 
`Other.html\'
+',
+    'text' => 'user-defined node file name not set for `Other.html\'',
+    'type' => 'warning'
+  },
+  {
+    'error_line' => 'warning: must specify a title with a title command or @top
+',
+    'file_name' => 'undefined_node_filename.texi',
+    'text' => 'must specify a title with a title command or @top',
+    'type' => 'warning'
+  }
+];
+
+
+1;
diff --git 
a/tp/t/results/init_files_tests/undefined_node_filename/res_html/Other.html 
b/tp/t/results/init_files_tests/undefined_node_filename/res_html/Other.html
new file mode 100644
index 0000000000..7cae516a4b
--- /dev/null
+++ b/tp/t/results/init_files_tests/undefined_node_filename/res_html/Other.html
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html>
+<!-- Created by texinfo, http://www.gnu.org/software/texinfo/ -->
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<title>Other (Untitled Document)</title>
+
+<meta name="description" content="Other (Untitled Document)">
+<meta name="keywords" content="Other (Untitled Document)">
+<meta name="resource-type" content="document">
+<meta name="distribution" content="global">
+<meta name="viewport" content="width=device-width,initial-scale=1">
+
+<link href="index.html" rel="start" title="Top">
+<link href="index.html" rel="prev" title="Top">
+
+
+</head>
+
+<body lang="en">
+<a class="node-id" id="Other"></a><div class="nav-panel">
+<p>
+Previous: <a href="index.html" accesskey="p" rel="prev">Top</a> &nbsp; </p>
+</div>
+<hr>
+<h4 class="node">Other</h4>
+
+
+
+</body>
+</html>
diff --git 
a/tp/t/results/init_files_tests/undefined_node_filename/res_html/index.html 
b/tp/t/results/init_files_tests/undefined_node_filename/res_html/index.html
new file mode 100644
index 0000000000..ecb96dd23d
--- /dev/null
+++ b/tp/t/results/init_files_tests/undefined_node_filename/res_html/index.html
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<!-- Created by texinfo, http://www.gnu.org/software/texinfo/ -->
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<title>Top (Untitled Document)</title>
+
+<meta name="description" content="Top (Untitled Document)">
+<meta name="keywords" content="Top (Untitled Document)">
+<meta name="resource-type" content="document">
+<meta name="distribution" content="global">
+<meta name="viewport" content="width=device-width,initial-scale=1">
+
+<link href="#Top" rel="start" title="Top">
+<link href="Other.html" rel="next" title="Other">
+
+
+</head>
+
+<body lang="en">
+<a class="node-id" id="Top"></a><div class="nav-panel">
+<p>
+Next: <a href="Other.html" accesskey="n" rel="next">Other</a> &nbsp; </p>
+</div>
+<hr>
+<h1 class="node">Top</h1>
+
+<hr>
+<div class="nav-panel">
+<p>
+Next: <a href="Other.html" accesskey="n" rel="next">Other</a> &nbsp; </p>
+</div>
+
+
+
+</body>
+</html>



reply via email to

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