texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Mon, 20 Nov 2023 18:30:19 -0500 (EST)

branch: master
commit 7c60ae3e794e7ea723a2a71f47cba19e1cdb5a2d
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Tue Nov 21 00:28:08 2023 +0100

    HTML css functions API change, split information and selector rules
    
    * doc/texi2any_api.texi (Simple Customization of CSS),
    tp/Texinfo/Convert/HTML.pm (css_add_info, css_set_selector_style)
    (css_get_info, css_selector_style), tp/init/sc_formatting_with_css.pm,
    tp/init/documentation_examples.pm: split css_set_selector_style out of
    css_add_info for setting of selector CSS style.  Split
    css_selector_style out of css_get_info to get selector CSS style.
    Also css_get_info returns the list of selectors, not a hash.  Update
    callers.
---
 ChangeLog                         | 13 ++++++++
 doc/texi2any_api.texi             | 50 +++++++++++++++--------------
 tp/Texinfo/Convert/HTML.pm        | 67 +++++++++++++++++++++++----------------
 tp/init/documentation_examples.pm | 14 ++++----
 tp/init/sc_formatting_with_css.pm |  2 +-
 5 files changed, 88 insertions(+), 58 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 770f01322c..1158d3446b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2023-11-20  Patrice Dumas  <pertusus@free.fr>
+
+       HTML css functions API change, split information and selector rules
+
+       * doc/texi2any_api.texi (Simple Customization of CSS),
+       tp/Texinfo/Convert/HTML.pm (css_add_info, css_set_selector_style)
+       (css_get_info, css_selector_style), tp/init/sc_formatting_with_css.pm,
+       tp/init/documentation_examples.pm: split css_set_selector_style out of
+       css_add_info for setting of selector CSS style.  Split
+       css_selector_style out of css_get_info to get selector CSS style.
+       Also css_get_info returns the list of selectors, not a hash.  Update
+       callers.
+
 2023-11-20  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/convert/build_html_perl_state.c (build_html_target)
diff --git a/doc/texi2any_api.texi b/doc/texi2any_api.texi
index 865f684724..61e991132e 100644
--- a/doc/texi2any_api.texi
+++ b/doc/texi2any_api.texi
@@ -707,31 +707,35 @@ rules selectors are, classically, 
@code{@var{element}.@var{class}} strings with
 @var{element} an HTML element and @var{class} an attribute class associated to
 that element.
 
-The function used are @code{css_get_info} to get information and
-@code{css_add_info} to modify:
+The function used are @code{css_get_info} and @code{css_selector_style}
+to get information and @code{css_add_info} and @code{css_set_selector_style}
+to modify:
 
-@defun @var{$converter}->css_get_info ($specification, $css_info)
-@defunx @var{$converter}->css_add_info ($specification, $css_info, $css_style)
+@defun @var{$converter}->css_get_info ($specification)
+@defunx @var{$converter}->css_selector_style ($selector)
+@defunx @var{$converter}->css_add_info ($specification, $css_info)
+@defunx @var{$converter}->css_set_selector_style ($selector, $css_style)
 
 Those functions can only be used on a converter @var{$converter}, from
 functions registered and called with a converter.  @var{$specification} is
 @code{'rules'} to get information on or set information for CSS rules lines and
 @code{'imports'} to get information on or set information for CSS import lines.
-Any other value for @var{$specification} corresponds to CSS style rules
-associated with HTML elements and class attributes selectors.
+Any other value for @var{$specification} corresponds to HTML elements and
+class attributes selectors, and can be used to get the list of selectors.
 
-With @code{css_get_info}, if @var{$specification} is set to @code{'rules'} or
-@code{'imports'}, the corresponding arrays are returned.  Otherwise,
-if @var{$css_info} is @code{undef}, a hash reference with all the CSS rules 
selector as keys
-and the corresponding rules as values is returned.  If @var{$css_info} is 
defined,
-it is considered to be a CSS rule selector and the corresponding CSS style is 
returned,
-or @code{undef} if not found.
+With @code{css_get_info}, array references corresponding to 
@var{$specification}
+are returned.
+
+@code{css_selector_style} returns the CSS style corresponding to the HTML
+element and class attribute selector @var{$selector}, or @code{undef} if not
+found.
 
 With @code{css_add_info}, @var{$css_info} is an additional entry added to
 CSS rules lines if @var{$specification} is set to @code{'rules'} or an 
additional
 entry added to CSS import lines if @var{$specification} is set to 
@code{'imports'}.
-Otherwise, @var{$css_info} is a CSS rule selector and the associated
-style rule is set to @var{$css_style}.
+
+With @code{css_set_selector_style}, @var{$selector} is a CSS rule selector and 
the
+associated style rule is set to @var{$css_style}.
 @end defun
 
 Some examples of use:
@@ -739,10 +743,9 @@ Some examples of use:
 @example
 my @@all_included_rules = $converter->css_get_info('rules');
 my $all_default_selector_styles = $converter->css_get_info('styles');
-my $titlefont_header_style = $converter->css_get_info('styles',
-                                                      'h1.titlefont');
+my $titlefont_header_style = $converter->css_selector_style('h1.titlefont');
 
-$converter->css_add_info('styles', 'h1.titlefont', 'text-align:center');
+$converter->css_set_selector_style('h1.titlefont', 'text-align:center');
 $converter->css_add_info('imports', "\@@import \"special.css\";\n");
 @end example
 
@@ -753,16 +756,16 @@ document. @xref{Customizing CSS}.
 
 How to run code during the conversion process is described later
 (@pxref{Init File Calling at Different Stages}). The simplest way to
-use the @code{css_add_info} function would be to use a function
+modify CSS rules would be to use a function
 registered for the @samp{structure} stage:
 
 @example
 sub my_function_set_some_css @{
   my $converter = shift;
 
-  $converter->css_add_info('styles', 'h1.titlefont',
-                           'text-align:center');
-  # ... more calls to  $converter->css_add_info();
+  $converter->css_set_selector_style('h1.titlefont',
+                                     'text-align:center');
+  # ... calls to  $converter->css_add_info();
 @}
 
 texinfo_register_handler('structure', \&my_function_set_some_css);
@@ -4312,8 +4315,9 @@ This function returns the CSS lines and @code{<script>} 
HTML element
 for @var{$file_name}.
 
 In the default case, the function reference uses @code{CSS_REFS} corresponding
-to command-line @option{--css-ref}, @code{html_get_css_elements_classes} and
-@code{css_get_info} (@pxref{Simple Customization of CSS}) to determine the CSS
+to command-line @option{--css-ref}, @code{html_get_css_elements_classes},
+@code{css_get_info} and @code{css_element_class_rule}
+(@pxref{Simple Customization of CSS}) to determine the CSS
 lines.
 @end deftypefn
 
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index eb6e31dd10..7a32ddce63 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -420,7 +420,7 @@ sub html_image_file_location_name($$$$)
           $image_path_encoding);
 }
 
-sub css_add_info($$$;$)
+sub css_add_info($$$)
 {
   my $self = shift;
   my $spec = shift;
@@ -431,38 +431,51 @@ sub css_add_info($$$;$)
     push @{$self->{'css_rule_lines'}}, $css_info;
   } elsif ($spec eq 'imports') {
     push @{$self->{'css_import_lines'}}, $css_info;
-  } else {
-    $self->{'css_element_class_styles'}->{$css_info} = $css_style;
   }
 }
 
-sub css_get_info($$;$) {
+sub css_set_selector_style($$$)
+{
+  my $self = shift;
+  my $css_info = shift;
+  my $css_style = shift;
+
+  $self->{'css_element_class_styles'}->{$css_info} = $css_style;
+}
+
+sub css_get_info($$) {
   my $self = shift;
   my $spec = shift;
   my $css_info = shift;
+  my @empty_array;
 
   if ($spec eq 'rules') {
     if (defined($self->{'css_rule_lines'})) {
-      return @{$self->{'css_rule_lines'}};
+      return $self->{'css_rule_lines'};
     } else {
-      return ();
+      return \@empty_array;
     }
   } elsif ($spec eq 'imports') {
     if (defined($self->{'css_import_lines'})) {
-      return @{$self->{'css_import_lines'}};
+      return $self->{'css_import_lines'};
     } else {
-      return ();
+      return \@empty_array;
     }
   } else {
-    if (defined($css_info)) {
-      if ($self->{'css_element_class_styles'}->{$css_info}) {
-        return $self->{'css_element_class_styles'}->{$css_info};
-      } else {
-        return undef;
-      }
-    } else {
-      return { %{$self->{'css_element_class_styles'}} };
-    }
+    my @result = sort(keys(%{$self->{'css_element_class_styles'}}));
+    return \@result;
+  }
+}
+
+sub css_selector_style($$)
+{
+  my $self = shift;
+  my $css_info = shift;
+
+  if ($self->{'css_element_class_styles'}->{$css_info}) {
+    return $self->{'css_element_class_styles'}->{$css_info};
+  } else {
+    return undef;
   }
 }
 
@@ -5198,7 +5211,7 @@ sub _convert_itemize_command($$$$$)
   }
 
   if (defined($mark_class_name)
-      and defined($self->css_get_info('style', 'ul.mark-'.$mark_class_name))) {
+      and defined($self->css_selector_style('ul.mark-'.$mark_class_name))) {
     return $self->html_attribute_class('ul', [$cmdname,
                                               'mark-'.$mark_class_name])
         .">\n" . $content. "</ul>\n";
@@ -8630,23 +8643,23 @@ sub _default_format_css_lines($;$)
 
   my $css_refs = $self->get_conf('CSS_REFS');
   my @css_element_classes = $self->html_get_css_elements_classes($filename);
-  my @css_import_lines = $self->css_get_info('imports');
-  my @css_rule_lines = $self->css_get_info('rules');
+  my $css_import_lines = $self->css_get_info('imports');
+  my $css_rule_lines = $self->css_get_info('rules');
 
-  return '' if !@css_import_lines and !@css_element_classes
-                 and !@css_rule_lines
+  return '' if !@$css_import_lines and !@css_element_classes
+                 and !@$css_rule_lines
                  and (!defined($css_refs) or !@$css_refs);
 
   my $css_text = "<style type=\"text/css\">\n<!--\n";
-  $css_text .= join('', @css_import_lines) . "\n"
-    if (@css_import_lines);
+  $css_text .= join('', @$css_import_lines) . "\n"
+    if (@$css_import_lines);
   foreach my $element_class (@css_element_classes) {
-    my $css_style = $self->css_get_info('style', $element_class);
+    my $css_style = $self->css_selector_style($element_class);
     $css_text .= "$element_class {$css_style}\n"
       if defined($css_style );
   }
-  $css_text .= join('', @css_rule_lines) . "\n"
-    if (@css_rule_lines);
+  $css_text .= join('', @$css_rule_lines) . "\n"
+    if (@$css_rule_lines);
   $css_text .= "-->\n</style>\n";
   foreach my $ref (@$css_refs) {
     $css_text .= $self->close_html_lone_element(
diff --git a/tp/init/documentation_examples.pm 
b/tp/init/documentation_examples.pm
index fba1c57cb5..93a956a6d6 100644
--- a/tp/init/documentation_examples.pm
+++ b/tp/init/documentation_examples.pm
@@ -54,13 +54,13 @@ my $shown_styles;
 my $footnotestyle;
 sub my_function_set_some_css {
   my $converter = shift;
-  my @all_included_rules = $converter->css_get_info('rules');
-  my $all_default_selector_styles = $converter->css_get_info('styles');
-  my $titlefont_style = $all_default_selector_styles->{'h1.titlefont'};
+  my $all_included_rules = $converter->css_get_info('rules');
+  my $all_default_selectors = $converter->css_get_info('styles');
+  my $titlefont_style = $converter->css_selector_style('h1.titlefont');
   $titlefont_style = 'undefined' if (!defined($titlefont_style));
   $shown_styles = $titlefont_style.' '.
-              $all_default_selector_styles->{'h1.shorttitlepage'};
-  $converter->css_add_info('styles', 'h1.titlefont', 'text-align:center');
+            $converter->css_selector_style('h1.shorttitlepage');
+  $converter->css_set_selector_style('h1.titlefont', 'text-align:center');
 
   my $footnotestyle_before_setting = $converter->get_conf('footnotestyle');
   $footnotestyle_before_setting = 'UNDEF'
@@ -69,11 +69,11 @@ sub my_function_set_some_css {
   $footnotestyle = $main_program_footnotestyle
                     .'|'.$footnotestyle_before_setting
                     .'|'.$converter->get_conf('footnotestyle');
-  # there should be nothing in @all_included_rules for two reasons,
+  # there should be nothing in @$all_included_rules for two reasons,
   # first because it requires 'CSS_FILES' to be set to parseable
   # CSS files, and CSS files parsing is done after the setup handler
   # is called.
-  #print STDERR "all_included_rules: ".join('|', @all_included_rules)."\n";
+  #print STDERR "all_included_rules: ".join('|', @$all_included_rules)."\n";
   return 0;
 }
 
diff --git a/tp/init/sc_formatting_with_css.pm 
b/tp/init/sc_formatting_with_css.pm
index a01ffc4a47..d78111131e 100644
--- a/tp/init/sc_formatting_with_css.pm
+++ b/tp/init/sc_formatting_with_css.pm
@@ -9,7 +9,7 @@ foreach my $context ('normal', 'preformatted', 'string') {
 
 sub sc_formatting_with_css_set_css {
   my $converter = shift;
-  $converter->css_add_info('styles', 'span.sc', 'font-variant: small-caps');
+  $converter->css_set_selector_style('span.sc', 'font-variant: small-caps');
   return 0;
 }
 texinfo_register_handler('structure', \&sc_formatting_with_css_set_css);



reply via email to

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