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


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/Convert/HTML.pm (_default_format_element_footer): use an explicit list of characters to be considered as spaces to cope with all the perl versions.
Date: Thu, 25 Jan 2024 05:06:51 -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 ccadd69e52 * tp/Texinfo/Convert/HTML.pm 
(_default_format_element_footer): use an explicit list of characters to be 
considered as spaces to cope with all the perl versions.
ccadd69e52 is described below

commit ccadd69e52514dd3e869eebeba08c2702e2726fd
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Thu Jan 25 11:06:19 2024 +0100

    * tp/Texinfo/Convert/HTML.pm (_default_format_element_footer): use
    an explicit list of characters to be considered as spaces to cope with
    all the perl versions.
    
    * tp/Texinfo/XS/convert/convert_html.c (word_number_more_than_level)
    (html_default_format_element_footer): return the count by reference
    in word_number_more_than_level.
    
    * tp/Texinfo/XS/convert/convert_html.c (word_number_more_than_level):
    count words, not spaces.
---
 ChangeLog                            | 13 ++++++++++++
 tp/Texinfo/Convert/HTML.pm           | 14 ++++++++++--
 tp/Texinfo/XS/convert/convert_html.c | 41 ++++++++++++++++++++++--------------
 3 files changed, 50 insertions(+), 18 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 54f74cc105..2de8547ffd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2024-01-25  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Convert/HTML.pm (_default_format_element_footer): use
+       an explicit list of characters to be considered as spaces to cope with
+       all the perl versions.
+
+       * tp/Texinfo/XS/convert/convert_html.c (word_number_more_than_level)
+       (html_default_format_element_footer): return the count by reference
+       in word_number_more_than_level.
+
+       * tp/Texinfo/XS/convert/convert_html.c (word_number_more_than_level):
+       count words, not spaces.
+
 2024-01-24  Gavin Smith <gavinsmith0123@gmail.com>
 
        * tp/Texinfo/Convert/Plaintext.pm (add_newline_if_needed):
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 4dbe05f2ac..4153982a41 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -8052,12 +8052,22 @@ sub _default_format_element_footer($$$$;$)
         my $no_footer_word_count;
         if ($self->get_conf('WORDS_IN_PAGE')) {
           $content = '' if (!defined($content));
+          # NOTE it would have been better to skip a leading space, but
+          # it cannot happen as the content should start with an HTML element.
+          # splitting at [\h\v] may have been relevant, but then the result
+          # would be different from XS code result and could give different
+          # results in perl in some cases.
           # FIXME it seems that NO-BREAK SPACE and NEXT LINE (NEL) may
           # not be in \h and \v in some case, but not sure which case it is
           # It is supposed to be explained but it is not very clear
           # https://perldoc.perl.org/perlrecharclass#Whitespace
-          # TODO starting in Perl v5.18 [\h\v] could be replaced by \s
-          my @cnt = split(/[\h\v]+/, $content);
+          # [\h\v]+ does not match on solaris 11 with perl 5.10.1, not sure
+          # why.
+          #my @cnt = split(/[\h\v]+/, $content);
+          # Use an explicit list to match the same in all versions of perl.
+          # TODO starting in Perl v5.14 could be replaced by \s\cK (with /a)
+          # TODO starting in Perl v5.18 could be replaced by \s (with /a)
+          my @cnt = split(/[\t\n\f\r \cK]+/, $content);
           if (scalar(@cnt) < $self->get_conf('WORDS_IN_PAGE')) {
             $no_footer_word_count = 1;
           }
diff --git a/tp/Texinfo/XS/convert/convert_html.c 
b/tp/Texinfo/XS/convert/convert_html.c
index b3f38573a2..719ce3b4c6 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -7944,29 +7944,37 @@ format_element_header (CONVERTER *self,
 }
 
 static int
-word_number_more_than_level (const char *text, int level)
+word_number_more_than_level (const char *text, int level, int *count)
 {
   const char *p = text;
-  int count = 0;
+
+  p += strspn (p, whitespace_chars);
+
+  if (*p)
+    *count = 1;
 
   while (*p)
     {/* FIXME in perl unicode spaces are also matched */
       int n = strspn (p, whitespace_chars);
       if (n)
         {
-          count++;
-          if (count > level)
-            return 1;
           p += n;
+          /* if not followed by anything, ie at the end of the string,
+             do not count the space */
+          if (*p)
+            {
+              (*count)++;
+              if (*count >= level)
+                return 1;
+            }
+          else
+            return 0;
         }
-      if (*p)
-        {
-          /* skip a character */
-          int char_len = 1;
-          while ((p[char_len] & 0xC0) == 0x80)
-            char_len++;
-          p += char_len;
-        }
+      /* skip a character */
+      int char_len = 1;
+      while ((p[char_len] & 0xC0) == 0x80)
+        char_len++;
+      p += char_len;
     }
   return 0;
 }
@@ -8068,9 +8076,10 @@ html_default_format_element_footer (CONVERTER *self,
             {
               if (self->conf->WORDS_IN_PAGE.integer > 0)
                 {
-                  if (content
-                      && word_number_more_than_level (content,
-                                        self->conf->WORDS_IN_PAGE.integer))
+                  int count;
+                  int more_than_level = word_number_more_than_level (content,
+                                    self->conf->WORDS_IN_PAGE.integer, &count);
+                  if (content && more_than_level)
                     {
                       buttons = self->conf->NODE_FOOTER_BUTTONS.buttons;
                     }



reply via email to

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