texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Sun, 31 Dec 2023 18:26:40 -0500 (EST)

branch: master
commit 38748b0696165f1fba05f5b131666a4826e0047a
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Dec 31 21:20:21 2023 +0100

    * tp/Texinfo/Convert/HTML.pm (_get_copiable_anchor): return undef if
    there is no copiable anchor.  Update callers.
    
    * tp/Texinfo/Convert/HTML.pm (_default_format_heading_text): let
    _get_copiable_anchor determine if there is a copiable anchor or not.
    
    * tp/Texinfo/Convert/HTML.pm (_convert_item_command): reorganize code
    to set the result in order.
---
 ChangeLog                                          | 11 ++++
 tp/Texinfo/Convert/HTML.pm                         | 77 +++++++++++-----------
 .../results/sectioning/no_argument_and_contents.pl |  2 +-
 3 files changed, 52 insertions(+), 38 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 588ed8bcc7..36050c975a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -20,6 +20,17 @@
 
        No functional changes intended.
 
+2023-12-31  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Convert/HTML.pm (_get_copiable_anchor): return undef if
+       there is no copiable anchor.  Update callers.
+
+       * tp/Texinfo/Convert/HTML.pm (_default_format_heading_text): let
+       _get_copiable_anchor determine if there is a copiable anchor or not.
+
+       * tp/Texinfo/Convert/HTML.pm (_convert_item_command): reorganize code
+       to set the result in order.
+
 2023-12-31  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Convert/Converter.pm (table_item_content_tree): do not
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index dd65f96a57..0833f87afd 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -4073,14 +4073,13 @@ sub _default_format_heading_text($$$$$;$$$)
   }
   $result .= '>';
 
-  if (defined $target && $self->get_conf('COPIABLE_LINKS')) {
-    # Span-wrap this anchor, so that the existing span:hover a.copiable-link
-    # rule applies.
-    $result .= "<span>$text";
-    $result .= $self->_get_copiable_anchor($target);
-    $result .= '</span>';
-  } else {
-    $result .= $text;
+  my $anchor = $self->_get_copiable_anchor($target);
+  if (defined($anchor)) {
+    $result .= '<span>';
+  }
+  $result .= $text;
+  if (defined($anchor)) {
+    $result .= "$anchor</span>";
   }
   $result .= "</h$level>";
 
@@ -5770,39 +5769,44 @@ sub _convert_item_command($$$$$)
            and $command->{'parent'}->{'type'} eq 'table_term') {
     if ($command->{'args'} and scalar(@{$command->{'args'}})
         and $command->{'args'}->[0]->{'contents'}) {
-      my $table_item_tree = $self->table_item_content_tree($command);
-      $table_item_tree = $command->{'args'}->[0]
-        if (!defined($table_item_tree));
-      my $result = $self->convert_tree($table_item_tree,
-                                       'convert table_item_tree');
+
+      my $result = ($cmdname eq 'item') ? '' : '<dt>';
+
+      my $index_id = $self->command_id($command);
+      my $anchor;
+      if (defined($index_id)) {
+        $result .= "<a id=\"$index_id\"></a>";
+        $anchor = $self->_get_copiable_anchor($index_id);
+        if (defined($anchor)) {
+          $result .= '<span>';
+        }
+      }
+
+      my $pre_class_close;
       if (in_preformatted_context($self)) {
         my $pre_classes = $self->preformatted_classes_stack();
         foreach my $pre_class (@$pre_classes) {
           if ($preformatted_code_commands{$pre_class}) {
-            $result = $self->html_attribute_class('code',
-                                    ['table-term-preformatted-code']).'>'
-                        . $result . '</code>';
+            $result .= $self->html_attribute_class('code',
+                                    ['table-term-preformatted-code']).'>';
+            $pre_class_close = '</code>';
             last;
           }
         }
       }
-      my $open_tag = ($cmdname eq 'item') ? '' : '<dt>';
-      my $index_id = $self->command_id($command);
-      my $anchor;
-      my $anchor_span_open = '';
-      my $anchor_span_close = '';
-      if (defined($index_id)) {
-        $anchor = $self->_get_copiable_anchor($index_id);
-        $index_id = "<a id=\"$index_id\"></a>";
-        if ($anchor ne '') {
-          $anchor_span_open = '<span>';
-          $anchor_span_close = '</span>';
-        }
-      } else {
-        $anchor = '';
-        $index_id = '';
+      my $table_item_tree = $self->table_item_content_tree($command);
+      $table_item_tree = $command->{'args'}->[0]
+        if (!defined($table_item_tree));
+      my $converted_item = $self->convert_tree($table_item_tree,
+                                          'convert table_item_tree');
+      $result .= $converted_item;
+      if (defined($pre_class_close)) {
+        $result .= $pre_class_close;
+      }
+      if (defined($anchor)) {
+        $result .= $anchor . '</span>';
       }
-      return 
"$open_tag$index_id$anchor_span_open$result$anchor$anchor_span_close</dt>\n";
+      return $result . "</dt>\n";
     } else {
       return '';
     }
@@ -7581,11 +7585,11 @@ sub _convert_def_line_type($$$$)
   }
 
   my $anchor = $self->_get_copiable_anchor($index_id);
-  if ($anchor ne '') {
+  if (defined($anchor)) {
     $result .= '<span>';
   }
   $result .= $def_call;
-  if ($anchor ne '') {
+  if (defined($anchor)) {
     $result .= $anchor . '</span>';
   }
   $result .= "</dt>\n";
@@ -7595,13 +7599,12 @@ sub _convert_def_line_type($$$$)
 
 sub _get_copiable_anchor {
   my ($self, $id) = @_;
-  my $result = '';
   if (defined($id) and $id ne '' and $self->get_conf('COPIABLE_LINKS')) {
     my $paragraph_symbol = $self->get_info('paragraph_symbol');
-    $result = $self->html_attribute_class('a', ['copiable-link'])
+    return $self->html_attribute_class('a', ['copiable-link'])
         ." href=\"#$id\"> $paragraph_symbol</a>";
   }
-  return $result;
+  return undef;
 }
 
 $default_types_conversion{'def_line'} = \&_convert_def_line_type;
diff --git a/tp/t/results/sectioning/no_argument_and_contents.pl 
b/tp/t/results/sectioning/no_argument_and_contents.pl
index 105f256275..be61465c68 100644
--- a/tp/t/results/sectioning/no_argument_and_contents.pl
+++ b/tp/t/results/sectioning/no_argument_and_contents.pl
@@ -233,7 +233,7 @@ ul.toc-numbered-mark {list-style: none}
 </div>
 </div>
 <div class="chapter-level-extent">
-<h2 class="chapter"><span>1 </span></h2>
+<h2 class="chapter">1 </h2>
 
 </div>
 </div>



reply via email to

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