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_tab_comman


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/Convert/HTML.pm (_convert_tab_command): reorder code. Rename $fraction as $percent.
Date: Sun, 31 Dec 2023 19:41:08 -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 0b9ff7bae1 * tp/Texinfo/Convert/HTML.pm (_convert_tab_command): 
reorder code. Rename $fraction as $percent.
0b9ff7bae1 is described below

commit 0b9ff7bae134b669e33bc9d5b0686646cdaa6e51
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon Jan 1 01:41:07 2024 +0100

    * tp/Texinfo/Convert/HTML.pm (_convert_tab_command): reorder code.
    Rename $fraction as $percent.
    
    * tp/Texinfo/XS/convert/convert_html.c (convert_tab_command)
    (commands_internal_conversion_table): implement convert_tab_command.
---
 ChangeLog                            |  8 ++++
 tp/Texinfo/Convert/HTML.pm           | 21 +++++-----
 tp/Texinfo/XS/convert/convert_html.c | 78 ++++++++++++++++++++++++++++++++++++
 3 files changed, 97 insertions(+), 10 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1a41c167a4..17e5078ecb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-12-31  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Convert/HTML.pm (_convert_tab_command): reorder code.
+       Rename $fraction as $percent.
+
+       * tp/Texinfo/XS/convert/convert_html.c (convert_tab_command)
+       (commands_internal_conversion_table): implement convert_tab_command.
+
 2023-12-31  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/main/utils.c (width_multibyte): start counting from
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 7a02696a5f..d60c46d5d6 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -5829,6 +5829,15 @@ sub _convert_tab_command($$$$$)
   my $args = shift;
   my $content = shift;
 
+  $content = '' if (!defined($content));
+
+  $content =~ s/^\s*//;
+  $content =~ s/\s*$//;
+
+  if (in_string($self)) {
+    return $content;
+  }
+
   my $cell_nr = $command->{'extra'}->{'cell_number'};
   my $row = $command->{'parent'};
   my $row_cmdname = $row->{'contents'}->[0]->{'cmdname'};
@@ -5838,20 +5847,12 @@ sub _convert_tab_command($$$$$)
   my $cf = $multitable->{'extra'}->{'columnfractions'};
   if ($cf) {
     if (exists($cf->{'extra'}->{'misc_args'}->[$cell_nr-1])) {
-      my $fraction = sprintf('%d',
+      my $percent = sprintf('%d',
                              100*$cf->{'extra'}->{'misc_args'}->[$cell_nr-1]);
-      $fractions = " width=\"$fraction%\"";
+      $fractions = " width=\"$percent%\"";
     }
   }
 
-  $content = '' if (!defined($content));
-
-  $content =~ s/^\s*//;
-  $content =~ s/\s*$//;
-
-  if (in_string($self)) {
-    return $content;
-  }
   if ($row_cmdname eq 'headitem') {
     return "<th${fractions}>" . $content . '</th>';
   } else {
diff --git a/tp/Texinfo/XS/convert/convert_html.c 
b/tp/Texinfo/XS/convert/convert_html.c
index 84a9401b55..bf4e3e9ffa 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -11310,6 +11310,83 @@ convert_item_command (CONVERTER *self, const enum 
command_id cmd,
     }
 }
 
+void
+convert_tab_command (CONVERTER *self, const enum command_id cmd,
+                    const ELEMENT *element,
+                    const HTML_ARGS_FORMATTED *args_formatted,
+                    const char *content, TEXT *result)
+{
+  char *trimmed_content;
+  int cell_nr;
+  int status;
+  ELEMENT *row;
+  ELEMENT *multitable;
+  ELEMENT *columnfractions;
+  const char *html_element = "td";
+
+  if (content)
+    {
+      const char *p = content;
+      size_t str_len;
+      p += strspn (p, whitespace_chars);
+      trimmed_content = strdup (p);
+      str_len = strlen (trimmed_content);
+      if (str_len > 0)
+        {
+          char *q = trimmed_content + str_len - 1;
+          while (q > trimmed_content)
+            {
+              if (!strchr (whitespace_chars, *q))
+                {
+                  break;
+                }
+              q--;
+            }
+          *(q +1) = '\0';
+        }
+    }
+  else
+    trimmed_content = strdup ("");
+
+  if (html_in_string (self))
+    {
+      text_append (result, trimmed_content);
+      free (trimmed_content);
+      return;
+    }
+
+  row = element->parent;
+  if (row->contents.list[0]->cmd == CM_headitem)
+    html_element = "th";
+
+  text_append_n (result, "<", 1);
+  text_append_n (result, html_element, 2);
+
+  cell_nr = lookup_extra_integer (element, "cell_number", &status);
+  multitable = row->parent->parent;
+
+  columnfractions = lookup_extra_element (multitable, "columnfractions");
+
+  if (columnfractions)
+    {
+      ELEMENT *cf_misc_args = lookup_extra_element (columnfractions,
+                                                     "misc_args");
+      if (cf_misc_args->contents.number >= cell_nr)
+        {
+          char *fraction_str
+            = cf_misc_args->contents.list[cell_nr -1]->text.text;
+          double fraction = strtod (fraction_str, NULL);
+          text_printf (result, " width=\"%0.f%%\"", 100 * fraction);
+        }
+    }
+  text_append_n (result, ">", 1);
+  text_append (result, trimmed_content);
+  free (trimmed_content);
+  text_append_n (result, "</", 2);
+  text_append_n (result, html_element, 2);
+  text_append_n (result, ">", 1);
+}
+
 void
 convert_xref_commands (CONVERTER *self, const enum command_id cmd,
                     const ELEMENT *element,
@@ -12024,6 +12101,7 @@ static COMMAND_INTERNAL_CONVERSION 
commands_internal_conversion_table[] = {
   {CM_item, &convert_item_command},
   {CM_headitem, &convert_item_command},
   {CM_itemx, &convert_item_command},
+  {CM_tab, &convert_tab_command},
 
   {CM_insertcopying, &convert_insertcopying_command},
   {CM_listoffloats, &convert_listoffloats_command},



reply via email to

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