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 (_convert_quotation_


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/Convert/HTML.pm (_convert_quotation_command): rearrange for clearer code and to avoid intermediary variable.
Date: Sun, 31 Dec 2023 10:47:50 -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 fcf632f775 * tp/Texinfo/Convert/HTML.pm (_convert_quotation_command): 
rearrange for clearer code and to avoid intermediary variable.
fcf632f775 is described below

commit fcf632f775d1214077c6d876c4533e9c8ea9dd7e
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Dec 31 16:45:38 2023 +0100

    * tp/Texinfo/Convert/HTML.pm (_convert_quotation_command): rearrange
    for clearer code and to avoid intermediary variable.
    
    * tp/Texinfo/XS/convert/convert_html.c (convert_quotation_command)
    (commands_internal_conversion_table): implement
    convert_quotation_command.
---
 ChangeLog                            |  9 +++++
 tp/Texinfo/Convert/HTML.pm           | 26 ++++++------
 tp/Texinfo/XS/convert/convert_html.c | 78 ++++++++++++++++++++++++++++++++++++
 3 files changed, 99 insertions(+), 14 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a29c552159..9b235275dc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,15 @@
        * doc/texinfo.texi (Info Format Local Variables): update
        * NEWS: mention
 
+2023-12-31  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Convert/HTML.pm (_convert_quotation_command): rearrange
+       for clearer code and to avoid intermediary variable.
+
+       * tp/Texinfo/XS/convert/convert_html.c (convert_quotation_command)
+       (commands_internal_conversion_table): implement
+       convert_quotation_command.
+
 2023-12-31  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Convert/Converter.pm (float_name_caption): rename
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 8ae88c599e..93d4eb210e 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -5525,18 +5525,21 @@ sub _convert_quotation_command($$$$$)
 
   $self->cancel_pending_formatted_inline_content($cmdname);
 
-  my @classes;
+  my $result;
+  if (!in_string($self)) {
+    my @classes;
 
-  my $main_cmdname;
-  if ($small_block_associated_command{$cmdname}) {
+    if ($small_block_associated_command{$cmdname}) {
+      push @classes, $small_block_associated_command{$cmdname};
+    }
     push @classes, $cmdname;
-    $main_cmdname = $small_block_associated_command{$cmdname};
+
+    $result = $self->html_attribute_class('blockquote', \@classes).">\n"
+                           . $content . "</blockquote>\n";
   } else {
-    $main_cmdname = $cmdname;
+    $result = $content;
   }
-  unshift @classes, $main_cmdname;
 
-  my $attribution = '';
   if ($command->{'extra'} and $command->{'extra'}->{'authors'}) {
     # FIXME there is no easy way to mark with a class the @author
     # @-command.  Add a span or a div (@center is in a div)?
@@ -5547,18 +5550,13 @@ sub _convert_quotation_command($$$$$)
         my $centered_author = $self->gdt("\@center --- \@emph{{author}}",
            {'author' => $author->{'args'}->[0]});
         $centered_author->{'parent'} = $command;
-        $attribution .= $self->convert_tree($centered_author,
+        $result .= $self->convert_tree($centered_author,
                                             'convert quotation author');
       }
     }
   }
 
-  if (!in_string($self)) {
-    return $self->html_attribute_class('blockquote', \@classes).">\n"
-                           . $content . "</blockquote>\n" . $attribution;
-  } else {
-    return $content.$attribution;
-  }
+  return $result;
 }
 $default_commands_conversion{'quotation'} = \&_convert_quotation_command;
 
diff --git a/tp/Texinfo/XS/convert/convert_html.c 
b/tp/Texinfo/XS/convert/convert_html.c
index 88382426d4..a63c2c4d2a 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -10796,6 +10796,82 @@ convert_float_command (CONVERTER *self, const enum 
command_id cmd,
   destroy_strings_list (classes);
 }
 
+void
+convert_quotation_command (CONVERTER *self, const enum command_id cmd,
+                    const ELEMENT *element,
+                    const HTML_ARGS_FORMATTED *args_formatted,
+                    const char *content, TEXT *result)
+{
+  ELEMENT_LIST *authors;
+
+  html_cancel_pending_formatted_inline_content (self,
+                                            builtin_command_name (cmd));
+
+  if (!html_in_string (self))
+    {
+      STRING_LIST *classes;
+      char *attribute_class;
+
+      classes = (STRING_LIST *) malloc (sizeof (STRING_LIST));
+      memset (classes, 0, sizeof (STRING_LIST));
+      if (html_commands_data[cmd].flags & HF_small_block_command)
+        {
+          int i;
+          for (i = 0; small_block_associated_command[i][0]; i++)
+            {
+              enum command_id small_cmd = small_block_associated_command[i][0];
+              if (small_cmd == cmd)
+                {
+                  enum command_id main_cmd = 
small_block_associated_command[i][1];
+                  add_string (builtin_command_name (main_cmd), classes);
+                  break;
+                }
+            }
+        }
+      add_string (builtin_command_name (cmd), classes);
+      attribute_class = html_attribute_class (self, "blockquote", classes);
+      destroy_strings_list (classes);
+      text_append (result, attribute_class);
+      free (attribute_class);
+      text_append_n (result, ">\n", 2);
+      if (content)
+        text_append (result, content);
+      text_append_n (result, "</blockquote>\n", 14);
+    }
+  else
+    {
+      if (content)
+        text_append (result, content);
+    }
+
+  /* the cast is here to discard const */
+  authors = lookup_extra_contents ((ELEMENT *) element, "authors", 0);
+  if (authors)
+    {
+      int i;
+      for (i = 0; i < authors->number; i++)
+        {
+          ELEMENT *author = authors->list[i];
+          if (author->args.number > 0
+              && author->args.list[0]->contents.number > 0)
+            {
+              NAMED_STRING_ELEMENT_LIST *substrings
+                                       = new_named_string_element_list ();
+              ELEMENT *author_arg_copy = copy_tree (author->args.list[0]);
+              add_element_to_named_string_element_list (substrings,
+                                      "author", author_arg_copy);
+
+              /* TRANSLATORS: quotation author */
+              translate_convert_to_html_internal (
+                             "@center --- @emph{{author}}", self->document,
+                             self, substrings, 0, 0, result,
+                             "convert quotation author");
+              destroy_named_string_element_list (substrings);
+            }
+        }
+    }
+}
+
 void
 convert_xref_commands (CONVERTER *self, const enum command_id cmd,
                     const ELEMENT *element,
@@ -11656,6 +11732,8 @@ static COMMAND_INTERNAL_CONVERSION 
commands_internal_conversion_table[] = {
   {CM_menu, &convert_menu_command},
   {CM_detailmenu, &convert_menu_command},
   {CM_float, &convert_float_command},
+  {CM_quotation, &convert_quotation_command},
+  {CM_smallquotation, &convert_quotation_command},
 
   {CM_verbatiminclude, &convert_verbatiminclude_command},
   {CM_sp, &convert_sp_command},



reply via email to

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