texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Thu, 21 Dec 2023 16:36:59 -0500 (EST)

branch: master
commit aa16e42a144b5d0534445badddef29a0923225df
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Thu Dec 21 16:25:20 2023 +0100

    * tp/Texinfo/Convert/HTML.pm (_convert_xref_commands): remove
    file_arg_tree intermediary variable.
    
    * tp/Texinfo/Convert/HTML.pm (_convert_xref_commands): if @*ref
    book argument is set, do not use the node name as section name.
    
    * tp/Texinfo/Convert/HTML.pm (_convert_xref_commands): do not set
    $reference to $name for a clearer code.
    
    * tp/t/30sectioning.t (novalidate): move to @tests_info.
---
 ChangeLog                                   | 13 +++++
 doc/texi2any_api.texi                       |  4 +-
 tp/Texinfo/Convert/HTML.pm                  | 74 +++++++++++++------------
 tp/t/30sectioning.t                         | 26 ++++-----
 tp/t/results/converters_tests/top_in_ref.pl |  4 +-
 tp/t/results/sectioning/novalidate.pl       | 83 +++++++++++++++++++++++++++++
 6 files changed, 153 insertions(+), 51 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d1315a08db..5bf3f5070d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2023-12-21  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Convert/HTML.pm (_convert_xref_commands): remove
+       file_arg_tree intermediary variable.
+
+       * tp/Texinfo/Convert/HTML.pm (_convert_xref_commands): if @*ref
+       book argument is set, do not use the node name as section name.
+
+       * tp/Texinfo/Convert/HTML.pm (_convert_xref_commands): do not set
+       $reference to $name for a clearer code.
+
+       * tp/t/30sectioning.t (novalidate): move to @tests_info.
+
 2023-12-21  Patrice Dumas  <pertusus@free.fr>
 
        * doc/texi2any_api.texi, tp/Texinfo/Convert/HTML.pm (command_href)
diff --git a/doc/texi2any_api.texi b/doc/texi2any_api.texi
index 2c504c3900..014a13f3c2 100644
--- a/doc/texi2any_api.texi
+++ b/doc/texi2any_api.texi
@@ -3397,7 +3397,8 @@ Returns the file name of the @var{\%target_element} tree 
element.
 
 @deftypefun {@var{$href} =} @var{$converter}->command_href 
(@var{\%target_element}, @
        @var{$source_filename}, @var{$source_command}, @var{$specified_target})
-Return string for linking to @var{\%target_element} with @code{<a href>}.
+Return string for linking to @var{\%target_element} with @code{<a href>}
+or @code{undef} if not found or empty.
 @var{$source_filename} is the file the link comes from. If not set, the current
 file name is used.  @var{$source_command} is an optional argument, the
 @@-command the link comes from.  It is only used for messages.
@@ -3508,6 +3509,7 @@ location in the table of contents, if 
@var{$contents_or_shortcontents} is
 @var{$contents_or_shortcontents} is set to @samp{shortcontents} or
 @samp{summarycontents}.  @var{$source_filename} is the file the link comes
 from. If not set, the current file name is used.
+Returns @code{undef} if no string is found or the string is empty.
 @end deftypefun
 
 To determine if a output unit is associated to the top output unit, use
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 28d681559d..1ceb813451 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -5643,12 +5643,10 @@ sub _convert_xref_commands($$$$)
     $file_arg = $args->[3];
   }
 
-  my $file_arg_tree;
   my $file;
   if ($file_arg
       and defined($file_arg->{'filenametext'})
       and $file_arg->{'filenametext'} ne '') {
-    $file_arg_tree = $file_arg->{'tree'};
     $file = $file_arg->{'filenametext'};
   }
 
@@ -5727,7 +5725,7 @@ sub _convert_xref_commands($$$$)
       $tree = $self->gdt('{reference_name}', $substrings);
     }
   } else {
-    # external reference
+    # external reference, including unknown node without file nor book
 
     # We setup a label_element based on the node argument and not directly the
     # node argument to be able to use the $file argument
@@ -5743,13 +5741,13 @@ sub _convert_xref_commands($$$$)
       }
     }
     # file argument takes precedence over the file in the node (file)node entry
-    if (defined($file_arg_tree)) {
+    if (defined($file)) {
       if (!$label_element) {
         $label_element = {'extra' => {}};
       } elsif (!$label_element->{'extra'}) {
         $label_element->{'extra'} = {};
       }
-      $label_element->{'extra'}->{'manual_content'} = $file_arg_tree;
+      $label_element->{'extra'}->{'manual_content'} = $file_arg->{'tree'};
     } elsif ($arg_node and $arg_node->{'extra'}
              and $arg_node->{'extra'}->{'manual_content'}) {
       my $manual_content = $arg_node->{'extra'}->{'manual_content'};
@@ -5763,41 +5761,47 @@ sub _convert_xref_commands($$$$)
                                  'contents' => [$manual_content]};
       $file = $self->convert_tree($file_with_node_tree, 'node file in ref');
     }
-    my $href = $self->command_href($label_element, undef, $command);
 
     if (!defined($name)) {
-      if (!defined($book) and $label_element) {
-        $name = $self->command_text($label_element);
-      } elsif ($node_content) {
-        my $node_no_file_tree = {'type' => '_code',
-                                 'contents' => [$node_content]};
-        my $node_name = $self->convert_tree($node_no_file_tree, 'node in ref');
-        if (defined($node_name) and $node_name ne 'Top') {
-          $name = $node_name;
+      if ($book) {
+        if ($node_content) {
+          my $node_no_file_tree = {'type' => '_code',
+                                   'contents' => [$node_content]};
+          my $node_name = $self->convert_tree($node_no_file_tree, 'node in 
ref');
+          if (defined($node_name) and $node_name ne 'Top') {
+            $name = $node_name;
+          }
+        }
+      } else {
+        if ($label_element) {
+          $name = $self->command_text($label_element);
         }
-      }
-
-      # not exactly sure when it happens.  Something like 
@ref{(file),,,Manual}?
-      $name = $args->[0]->{'monospace'}
         if (!defined($name)
-          and defined($args->[0])
-          and defined($args->[0]->{'monospace'})
-          # FIXME could it really be Top?
-          and $args->[0]->{'monospace'} ne 'Top');
+            and defined($args->[0])
+            and defined($args->[0]->{'monospace'})
+            and $args->[0]->{'monospace'} ne ''
+            and $args->[0]->{'monospace'} ne 'Top') {
+          # unknown node (and no book nor file) or @inforef without file
+          $name = $args->[0]->{'monospace'};
+        }
+      }
+    }
 
+    my $href;
+    if ($label_element and !in_string($self)) {
+      $href = $self->command_href($label_element, undef, $command);
     }
 
-    my $reference = $name;
+    my $reference;
     my $book_reference;
-    if (!in_string($self) and defined($href)) {
+    if (defined($href)) {
       # attribute to distiguish links to Texinfo manuals from other links
       # and to provide manual name of target
       my $manual_name_attribute = '';
-      if (defined($file)) {
-        if (not $self->get_conf('NO_CUSTOM_HTML_ATTRIBUTE')) {
-          $manual_name_attribute = "data-manual=\"".
-           &{$self->formatting_function('format_protect_text')}($self, 
$file)."\" ";
-        }
+      if (defined($file)
+          and not $self->get_conf('NO_CUSTOM_HTML_ATTRIBUTE')) {
+        $manual_name_attribute = "data-manual=\"".
+         &{$self->formatting_function('format_protect_text')}($self, 
$file)."\" ";
       }
       if (defined($name)) {
         $reference = "<a ${manual_name_attribute}href=\"$href\">$name</a>";
@@ -5806,7 +5810,7 @@ sub _convert_xref_commands($$$$)
       }
     }
     my $substrings;
-    if (defined($book) and defined($href) and defined($reference)) {
+    if (defined($book) and defined($reference)) {
       $substrings = {'reference'
                        => {'type' => '_converted', 'text' => $reference},
                      'book' => {'type' => '_converted', 'text' => $book }};
@@ -5827,9 +5831,9 @@ sub _convert_xref_commands($$$$)
       } else { # @ref
         $tree = $self->gdt('@cite{{book_reference}}', $substrings);
       }
-    } elsif (defined($book) and defined($reference)) {
+    } elsif (defined($book) and defined($name)) {
       $substrings = {
-              'section' => {'type' => '_converted', 'text' => $reference},
+              'section' => {'type' => '_converted', 'text' => $name},
               'book' => {'type' => '_converted', 'text' => $book }};
       if ($cmdname eq 'pxref') {
         $tree = $self->gdt('see `{section}\' in @cite{{book}}', $substrings);
@@ -5847,7 +5851,7 @@ sub _convert_xref_commands($$$$)
       } else { # @ref
         $tree = $self->gdt('@cite{{book}}', $substrings);
       }
-    } elsif (defined($href)) {
+    } elsif (defined($reference)) {
       $substrings = { 'reference'
                         => {'type' => '_converted', 'text' => $reference} };
       if ($cmdname eq 'pxref') {
@@ -5857,9 +5861,9 @@ sub _convert_xref_commands($$$$)
       } else { # @ref
         $tree = $self->gdt('{reference}', $substrings);
       }
-    } elsif (defined($reference)) {
+    } elsif (defined($name)) {
       $substrings = { 'section'
-                        => {'type' => '_converted', 'text' => $reference} };
+                        => {'type' => '_converted', 'text' => $name} };
       if ($cmdname eq 'pxref') {
         $tree = $self->gdt('see `{section}\'', $substrings);
       } elsif ($cmdname eq 'xref' or $cmdname eq 'inforef') {
diff --git a/tp/t/30sectioning.t b/tp/t/30sectioning.t
index 23d8953e32..a553ad07ba 100644
--- a/tp/t/30sectioning.t
+++ b/tp/t/30sectioning.t
@@ -925,7 +925,19 @@ $unnumbered_top_without_node_text,
 
 @node section
 @section sec
-']
+'],
+['novalidate',
+'
+@novalidate
+
+@node first, unknown node
+
+@menu
+* not a node::
+@end menu
+
+@xref{unknown ref}.
+'],
 );
 
 
@@ -1111,18 +1123,6 @@ second node.
 
 @node no return,,, Top 
 '],
-['novalidate',
-'
-@novalidate
-
-@node first, unknown node
-
-@menu
-* not a node::
-@end menu
-
-@xref{unknown ref}.
-'],
 ['loop_nodes',
 '@node Top
 @top top
diff --git a/tp/t/results/converters_tests/top_in_ref.pl 
b/tp/t/results/converters_tests/top_in_ref.pl
index e7f421aaa7..f184afc640 100644
--- a/tp/t/results/converters_tests/top_in_ref.pl
+++ b/tp/t/results/converters_tests/top_in_ref.pl
@@ -3090,7 +3090,7 @@ $result_converted{'html_text'}->{'top_in_ref'} = '<a 
class="node-id" id="Top"></
 <p><code class="code">@ref{(pman)Top,cross ref name}</code> <a 
data-manual="pman" href="pman.html#Top">cross ref name</a>
 <code class="code">@ref{(pman)Top,,title}</code> <a data-manual="pman" 
href="pman.html#Top">title</a>
 <code class="code">@ref{(pman)Top,,,file name}</code> <a data-manual="file 
name" href="file%20name.html#Top">(file name)Top</a>
-<code class="code">@ref{(pman)Top,,,,manual}</code> <a data-manual="pman" 
href="pman.html#Top">(pman)Top</a> in <cite class="cite">manual</cite>
+<code class="code">@ref{(pman)Top,,,,manual}</code> <cite class="cite"><a 
data-manual="pman" href="pman.html#Top">manual</a></cite>
 <code class="code">@ref{(pman)Top,cross ref name,title,}</code> <a 
data-manual="pman" href="pman.html#Top">title</a>
 <code class="code">@ref{(pman)Top,cross ref name,,file name}</code> <a 
data-manual="file name" href="file%20name.html#Top">cross ref name</a>
 <code class="code">@ref{(pman)Top,cross ref name,,,manual}</code> <a 
data-manual="pman" href="pman.html#Top">cross ref name</a> in <cite 
class="cite">manual</cite>
@@ -3100,7 +3100,7 @@ $result_converted{'html_text'}->{'top_in_ref'} = '<a 
class="node-id" id="Top"></
 <code class="code">@ref{(pman)Top,,title,file name}</code> <a 
data-manual="file name" href="file%20name.html#Top">title</a>
 <code class="code">@ref{(pman)Top,,title,,manual}</code> <a data-manual="pman" 
href="pman.html#Top">title</a> in <cite class="cite">manual</cite>
 <code class="code">@ref{(pman)Top,,title, file name, manual}</code> <a 
data-manual="file name" href="file%20name.html#Top">title</a> in <cite 
class="cite">manual</cite>
-<code class="code">@ref{(pman)Top,,,file name,manual}</code> <a 
data-manual="file name" href="file%20name.html#Top">(pman)Top</a> in <cite 
class="cite">manual</cite>
+<code class="code">@ref{(pman)Top,,,file name,manual}</code> <cite 
class="cite"><a data-manual="file name" 
href="file%20name.html#Top">manual</a></cite>
 </p>
 <p><code class="code">@inforef{Top, cross ref name, file name}</code> See <a 
data-manual="file name" href="file%20name.html#Top">cross ref name</a>
 <code class="code">@inforef{Top}</code> 
diff --git a/tp/t/results/sectioning/novalidate.pl 
b/tp/t/results/sectioning/novalidate.pl
index 0f41f49fc1..fd80866a1c 100644
--- a/tp/t/results/sectioning/novalidate.pl
+++ b/tp/t/results/sectioning/novalidate.pl
@@ -279,4 +279,87 @@ $result_errors{'novalidate'} = [];
 $result_floats{'novalidate'} = {};
 
 
+
+$result_converted{'info'}->{'novalidate'} = 'This is , produced from .
+
+
+File: ,  Node: first
+
+* Menu:
+
+* not a node::
+
+*Note unknown ref::.
+
+
+Tag Table:
+Node: first27
+
+End Tag Table
+
+
+Local Variables:
+coding: utf-8
+End:
+';
+
+$result_converted_errors{'info'}->{'novalidate'} = [
+  {
+    'error_line' => 'warning: document without Top node
+',
+    'text' => 'document without Top node',
+    'type' => 'warning'
+  }
+];
+
+
+
+$result_converted{'html'}->{'novalidate'} = '<!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>Untitled Document</title>
+
+<meta name="description" content="Untitled Document">
+<meta name="keywords" content="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="#first" rel="start" title="first">
+<style type="text/css">
+<!--
+a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
+span:hover a.copiable-link {visibility: visible}
+-->
+</style>
+
+
+</head>
+
+<body lang="en">
+
+
+<h4 class="node" id="first"><span>first<a class="copiable-link" href="#first"> 
&para;</a></span></h4>
+
+
+<p>See &lsquo;unknown ref&rsquo;.
+</p>
+
+
+</body>
+</html>
+';
+
+$result_converted_errors{'html'}->{'novalidate'} = [
+  {
+    'error_line' => 'warning: must specify a title with a title command or @top
+',
+    'text' => 'must specify a title with a title command or @top',
+    'type' => 'warning'
+  }
+];
+
+
 1;



reply via email to

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