texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * doc/texi2any_api.texi (Conversion in Preformatt


From: Patrice Dumas
Subject: branch master updated: * doc/texi2any_api.texi (Conversion in Preformatted Context), tp/Texinfo/Convert/HTML.pm (in_preformatted_context), tp/Texinfo/Convert/HTML.pm (inside_preformatted): rename in_preformatted as in_preformatted_context and _in_preformatted_in_menu as inside_preformatted.
Date: Wed, 15 Nov 2023 17:57:43 -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 d170aa3d48 * doc/texi2any_api.texi (Conversion in Preformatted 
Context), tp/Texinfo/Convert/HTML.pm (in_preformatted_context), 
tp/Texinfo/Convert/HTML.pm (inside_preformatted): rename in_preformatted as 
in_preformatted_context and _in_preformatted_in_menu as inside_preformatted.
d170aa3d48 is described below

commit d170aa3d48975478742fc0e51d6f013b092cd145
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed Nov 15 23:57:16 2023 +0100

    * doc/texi2any_api.texi (Conversion in Preformatted Context),
    tp/Texinfo/Convert/HTML.pm (in_preformatted_context),
    tp/Texinfo/Convert/HTML.pm (inside_preformatted): rename
    in_preformatted as in_preformatted_context and
    _in_preformatted_in_menu as inside_preformatted.
    
    * tp/Texinfo/XS/convert/build_html_perl_state.c
    (build_html_formatting_state), tp/Texinfo/XS/convert/convert_html.c
    (html_new_document_context, convert_to_html_internal),
    tp/Texinfo/XS/main/build_perl_info.c (build_integer_stack),
    tp/Texinfo/XS/main/command_stack.c (push_integer_stack_integer)
    (pop_integer_stack, top_integer_context),
    tp/Texinfo/XS/main/converter_types.h (INTEGER_STACK, CONVERTER):
    replace the monospace stack by a generic integer stack with the same
    functionalities.  Remove enum monospace_context.
    
    * tp/Texinfo/Convert/HTML.pm (in_preformatted_context)
    (inside_preformatted, _new_document_context)
    (_reset_unset_no_arg_commands_formatting_context, _convert),
    tp/Texinfo/XS/convert/build_html_perl_state.c
    (build_html_document_context, build_html_formatting_state),
    tp/Texinfo/XS/convert/convert_html.c (html_new_document_context)
    (html_pop_document_context)
    (reset_unset_no_arg_commands_formatting_context)
    (convert_to_html_internal), tp/Texinfo/XS/main/converter_types.h
    (CONVERTER): add states for preformatted_context and
    inside_preformatted, set together with preformatted_classes and
    composition_context, in order to access faster to the context.
    
    * tp/Texinfo/XS/convert/convert_html.c (in_preformatted_context)
    (inside_preformatted): add.
---
 ChangeLog                                     | 34 ++++++++++
 doc/texi2any_api.texi                         | 17 ++++-
 tp/Texinfo/Convert/HTML.pm                    | 89 +++++++++++++++------------
 tp/Texinfo/XS/convert/build_html_perl_state.c | 52 +++++++++-------
 tp/Texinfo/XS/convert/convert_html.c          | 83 +++++++++++++++++++------
 tp/Texinfo/XS/main/build_perl_info.c          | 18 ++++++
 tp/Texinfo/XS/main/build_perl_info.h          |  2 +
 tp/Texinfo/XS/main/command_stack.c            | 35 ++++-------
 tp/Texinfo/XS/main/command_stack.h            |  7 +--
 tp/Texinfo/XS/main/converter_types.h          | 13 ++--
 tp/init/book.pm                               |  2 +-
 tp/init/html32.pm                             |  2 +-
 12 files changed, 231 insertions(+), 123 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b368e07bc5..e28379f95c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,40 @@
        (xspara_add_text): Avoid a warning about a variable possibly
        being undefined.
 
+2023-11-15  Patrice Dumas  <pertusus@free.fr>
+
+       * doc/texi2any_api.texi (Conversion in Preformatted Context),
+       tp/Texinfo/Convert/HTML.pm (in_preformatted_context),
+       tp/Texinfo/Convert/HTML.pm (inside_preformatted): rename
+       in_preformatted as in_preformatted_context and
+       _in_preformatted_in_menu as inside_preformatted.
+
+       * tp/Texinfo/XS/convert/build_html_perl_state.c
+       (build_html_formatting_state), tp/Texinfo/XS/convert/convert_html.c
+       (html_new_document_context, convert_to_html_internal),
+       tp/Texinfo/XS/main/build_perl_info.c (build_integer_stack),
+       tp/Texinfo/XS/main/command_stack.c (push_integer_stack_integer)
+       (pop_integer_stack, top_integer_context),
+       tp/Texinfo/XS/main/converter_types.h (INTEGER_STACK, CONVERTER):
+       replace the monospace stack by a generic integer stack with the same
+       functionalities.  Remove enum monospace_context.
+
+       * tp/Texinfo/Convert/HTML.pm (in_preformatted_context)
+       (inside_preformatted, _new_document_context)
+       (_reset_unset_no_arg_commands_formatting_context, _convert),
+       tp/Texinfo/XS/convert/build_html_perl_state.c
+       (build_html_document_context, build_html_formatting_state),
+       tp/Texinfo/XS/convert/convert_html.c (html_new_document_context)
+       (html_pop_document_context)
+       (reset_unset_no_arg_commands_formatting_context)
+       (convert_to_html_internal), tp/Texinfo/XS/main/converter_types.h
+       (CONVERTER): add states for preformatted_context and
+       inside_preformatted, set together with preformatted_classes and
+       composition_context, in order to access faster to the context.
+
+       * tp/Texinfo/XS/convert/convert_html.c (in_preformatted_context)
+       (inside_preformatted): add.
+
 2023-11-15  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/convert/convert_html.c (TYPE_INTERNAL_CONVERSION)
diff --git a/doc/texi2any_api.texi b/doc/texi2any_api.texi
index 4f69f6256f..320c735962 100644
--- a/doc/texi2any_api.texi
+++ b/doc/texi2any_api.texi
@@ -2678,12 +2678,22 @@ if ($converter->in_string()) @{
 Conversion and formatting functions should test if in preformatted
 context to convert accordingly. @xref{Init File Expansion Contexts}.
 
-To determine if in preformatted context, the functions is 
@code{in_preformatted}:
+To determine if in preformatted context, the functions is
+@code{in_preformatted_context}:
 
-@deftypefun {@var{$in_preformatted} =} @var{$converter}->in_preformatted ()
+@deftypefun {@var{$in_preformatted} =} 
@var{$converter}->in_preformatted_context ()
 Return true if in preformatted context.
 @end deftypefun
 
+Another function tells if within a preformatted command:
+@deftypefun {@var{$inside_preformatted} =} 
@var{$converter}->inside_preformatted ()
+Return true if within a preformatted block command such as
+@code{@@preformatted}, @code{@@format}.
+
+It is not exactly the same as preformatted context, for instance menu comments
+are in preformatted context even if not in a preformatted block command.
+@end deftypefun
+
 If in preformatted context, it is possible to get preformatted @@-commands and
 preformatted types nesting with @code{preformatted_classes_stack}:
 
@@ -2708,7 +2718,8 @@ foreach my $pre_class (@@pre_classes) @{
 @}
 @end example
 
-@xref{Simple Customization of Containers} on customizing containers 
preformatted class.
+@xref{Simple Customization of Containers} on customizing containers
+preformatted class.
 
 
 @node Text Formatting Context
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 3aa0782ef9..e83eb06c5a 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -25,7 +25,7 @@
 # and formatted content, such that users can overrides them independently
 # without risking unwanted results.  Also in formatting functions, the state of
 # the converter should only be accessed through functions, such as in_math,
-# in_preformatted, preformatted_classes_stack and similar functions.
+# in_preformatted_context, preformatted_classes_stack and similar functions.
 #
 # Original author: Patrice Dumas <pertusus@free.fr>
 
@@ -542,19 +542,16 @@ sub in_math($)
 }
 
 # set if in menu or preformatted command
-sub in_preformatted($)
+sub in_preformatted_context($)
 {
   my $self = shift;
-  my $context = 
$self->{'document_context'}->[-1]->{'composition_context'}->[-1];
-  if ($preformatted_commands{$context}
-      or $self->{'pre_class_types'}->{$context}
-      or ($block_commands{$context}
-          and $block_commands{$context} eq 'menu'
-          and $self->_in_preformatted_in_menu())) {
-    return $context;
-  } else {
-    return undef;
-  }
+  return $self->{'document_context'}->[-1]->{'preformatted_context'}->[-1];
+}
+
+sub inside_preformatted($)
+{
+  my $self = shift;
+  return $self->{'document_context'}->[-1]->{'inside_preformatted'};
 }
 
 sub in_upper_case($)
@@ -2803,7 +2800,7 @@ sub _convert_no_arg_command($$$)
   if ($cmdname eq 'click' and $command->{'extra'}
       and exists($command->{'extra'}->{'clickstyle'})) {
     my $click_cmdname = $command->{'extra'}->{'clickstyle'};
-    if (($self->in_preformatted() or $self->in_math()
+    if (($self->in_preformatted_context() or $self->in_math()
          and $self->{'no_arg_commands_formatting'}->{$click_cmdname}
                                                         ->{'preformatted'})
         or ($self->in_string() and
@@ -2819,7 +2816,7 @@ sub _convert_no_arg_command($$$)
 
   my $result;
 
-  if ($self->in_preformatted() or $self->in_math()) {
+  if ($self->in_preformatted_context() or $self->in_math()) {
     $result = $self->_text_element_conversion(
       $self->{'no_arg_commands_formatting'}->{$cmdname}->{'preformatted'},
       $cmdname);
@@ -3007,7 +3004,7 @@ sub _convert_style_command($$$$)
     my $style_formatting
        = $self->{'style_commands_formatting'}->{$style_cmdname};
     my $formatting_spec;
-    if ($self->in_preformatted()) {
+    if ($self->in_preformatted_context()) {
       $formatting_spec = $style_formatting->{'preformatted'};
     } else {
       $formatting_spec = $style_formatting->{'normal'};
@@ -3291,7 +3288,7 @@ sub _convert_footnote_command($$$$)
                     $self->get_info('current_filename'), 
$multi_expanded_region);
 
   my $footnote_number_text;
-  if ($self->in_preformatted()) {
+  if ($self->in_preformatted_context()) {
     $footnote_number_text = "($number_in_doc)";
   } else {
     $footnote_number_text = "<sup>$number_in_doc</sup>";
@@ -4463,7 +4460,7 @@ sub _convert_heading_command($$$$$)
 
     my $heading_class = $level_corrected_cmdname;
     unshift @heading_classes, $heading_class;
-    if ($self->in_preformatted()) {
+    if ($self->in_preformatted_context()) {
       my $id_str = '';
       if (defined($heading_id)) {
         $id_str = " id=\"$heading_id\"";
@@ -4768,7 +4765,7 @@ sub _convert_sp_command($$$$)
       and defined($command->{'extra'}->{'misc_args'})
       and defined($command->{'extra'}->{'misc_args'}->[0])) {
     my $sp_nr = $command->{'extra'}->{'misc_args'}->[0];
-    if ($self->in_preformatted() or $self->in_string()) {
+    if ($self->in_preformatted_context() or $self->in_string()) {
       return "\n" x $sp_nr;
     } else {
       return ($self->get_info('line_break_element')."\n") x $sp_nr;
@@ -4794,7 +4791,7 @@ sub _convert_exdent_command($$$$)
 
   # FIXME do something with CSS?  Currently nothing is defined for exdent
 
-  if ($self->in_preformatted()) {
+  if ($self->in_preformatted_context()) {
     return $self->html_attribute_class('pre', [$cmdname]).'>'.$arg ."\n</pre>";
   } else {
     return $self->html_attribute_class('p', [$cmdname]).'>'.$arg ."\n</p>";
@@ -4951,16 +4948,6 @@ sub _convert_listoffloats_command($$$$)
 }
 $default_commands_conversion{'listoffloats'} = \&_convert_listoffloats_command;
 
-sub _in_preformatted_in_menu($)
-{
-  my $self = shift;
-  my @pre_classes = $self->preformatted_classes_stack();
-  foreach my $pre_class (@pre_classes) {
-    return 1 if ($preformatted_commands{$pre_class});
-  }
-  return 0;
-}
-
 sub _convert_menu_command($$$$$)
 {
   my $self = shift;
@@ -4989,7 +4976,7 @@ sub _convert_menu_command($$$$$)
 
   my $begin_row = '';
   my $end_row = '';
-  if ($self->_in_preformatted_in_menu()) {
+  if ($self->inside_preformatted()) {
     $begin_row = '<tr><td>';
     $end_row = '</td></tr>';
   }
@@ -5341,7 +5328,7 @@ sub _convert_item_command($$$$$)
                                                 [$args->[0]->{'tree'}]);
       my $result = $self->convert_tree($table_item_tree,
                                        'convert table_item_tree');
-      if ($self->in_preformatted()) {
+      if ($self->in_preformatted_context()) {
         my @pre_classes = $self->preformatted_classes_stack();
         foreach my $pre_class (@pre_classes) {
           if ($preformatted_code_commands{$pre_class}) {
@@ -5503,7 +5490,7 @@ sub _convert_xref_commands($$$$)
         }
       } elsif (!$self->get_conf('XREF_USE_NODE_NAME_ARG')
                and (defined($self->get_conf('XREF_USE_NODE_NAME_ARG'))
-                    or !$self->in_preformatted())) {
+                    or !$self->in_preformatted_context())) {
         $name = $self->command_text($command, 'text_nonumber');
         #die "$command $command->{'normalized'}" if (!defined($name));
       } elsif (defined($args->[0]->{'monospace'})) {
@@ -6448,7 +6435,7 @@ sub _convert_preformatted_type($$$$)
   # environment where spaces and newlines are preserved.
   if ($element->{'parent'}->{'type'}
       and $element->{'parent'}->{'type'} eq 'menu_entry_description') {
-    if (!$self->_in_preformatted_in_menu()) {
+    if (!$self->inside_preformatted()) {
       # If not in preformatted block command,
       # we don't preserve spaces and newlines in menu_entry_description,
       # instead the whole menu_entry is in a table, so no <pre> in that 
situation
@@ -6507,7 +6494,7 @@ sub _convert_index_entry_command_type($$$$)
       and !$self->in_string()) {
     my $result = &{$self->formatting_function('format_separate_anchor')}($self,
                                                    $index_id, 
'index-entry-id');
-    $result .= "\n" unless ($self->in_preformatted());
+    $result .= "\n" unless ($self->in_preformatted_context());
     return $result;
   }
   return '';
@@ -6607,7 +6594,7 @@ sub _convert_text($$$)
     }
   }
 
-  return $text if (in_preformatted($self));
+  return $text if (in_preformatted_context($self));
 
   # API info: in_non_breakable_space() API code conforming would be:
   #if ($self->in_non_breakable_space()) {
@@ -6839,7 +6826,7 @@ sub _convert_menu_entry_type($$$)
   my $MENU_ENTRY_COLON = $self->get_conf('MENU_ENTRY_COLON');
 
   my $in_string = $self->in_string();
-  if ($self->_in_preformatted_in_menu() or $in_string) {
+  if ($self->inside_preformatted() or $in_string) {
     my $leading_text = $menu_entry_leading_text->{'text'};
     $leading_text =~ s/\*/$MENU_SYMBOL/;
     my $result_name_node = $leading_text;
@@ -6975,7 +6962,7 @@ sub _convert_menu_comment_type($$$$)
 
   $content = '' if (!defined($content));
 
-  if ($self->_in_preformatted_in_menu() or $self->in_string()) {
+  if ($self->inside_preformatted() or $self->in_string()) {
     return $content;
   } else {
     return '<tr>'.$self->html_attribute_class('th', ['menu-comment'])
@@ -7601,6 +7588,8 @@ sub _new_document_context($$;$$)
           {'context' => $context,
            'formatting_context' => [{'context_name' => '_format'}],
            'composition_context' => [''],
+           'preformatted_context' => [0],
+           'inside_preformatted' => 0,
            'monospace' => [0],
            'document_global_context' => $document_global_context,
            'block_commands' => [],
@@ -7715,6 +7704,8 @@ sub 
_reset_unset_no_arg_commands_formatting_context($$$$;$)
       $self->_new_document_context($context_str);
       push @{$self->{'document_context'}->[-1]->{'composition_context'}},
           $preformatted_command_name;
+      push @{$self->{'document_context'}->[-1]->{'preformatted_context'}}, 1;
+      $self->{'document_context'}->[-1]->{'inside_preformatted'}++;
       # should not be needed for at commands no brace translation strings
       push @{$self->{'document_context'}->[-1]->{'preformatted_classes'}},
           $pre_class_commands{$preformatted_command_name};
@@ -12176,13 +12167,23 @@ sub _convert($$;$)
         push @{$self->{'document_context'}->[-1]->{'block_commands'}},
                                                           $command_name;
       }
-      if (exists ($composition_context_commands{$command_name})) {
-        push @{$self->{'document_context'}->[-1]->{'composition_context'}},
-                                                               $command_name;
-      }
+      my $preformatted = 0;
       if ($pre_class_commands{$command_name}) {
         push @{$self->{'document_context'}->[-1]->{'preformatted_classes'}},
           $pre_class_commands{$command_name};
+        if ($preformatted_commands{$command_name}) {
+          $self->{'document_context'}->[-1]->{'inside_preformatted'}++;
+          $preformatted = 1;
+        } elsif ($block_commands{$command_name} eq 'menu'
+                 and 
$self->{'document_context'}->[-1]->{'inside_preformatted'}) {
+          $preformatted = 1;
+        }
+      }
+      if (exists ($composition_context_commands{$command_name})) {
+        push @{$self->{'document_context'}->[-1]->{'composition_context'}},
+                                                               $command_name;
+        push @{$self->{'document_context'}->[-1]->{'preformatted_context'}},
+             $preformatted;
       }
       if ($format_raw_commands{$command_name}) {
         $self->{'document_context'}->[-1]->{'raw'}++;
@@ -12318,9 +12319,13 @@ sub _convert($$;$)
       }
       if (exists ($composition_context_commands{$command_name})) {
         pop @{$self->{'document_context'}->[-1]->{'composition_context'}};
+        pop @{$self->{'document_context'}->[-1]->{'preformatted_context'}};
       }
       if ($pre_class_commands{$command_name}) {
         pop @{$self->{'document_context'}->[-1]->{'preformatted_classes'}};
+        if ($preformatted_commands{$command_name}) {
+          $self->{'document_context'}->[-1]->{'inside_preformatted'}--;
+        }
       }
       if ($preformatted_code_commands{$command_name}
           or ($brace_commands{$command_name}
@@ -12404,6 +12409,7 @@ sub _convert($$;$)
     } elsif ($self->{'pre_class_types'}->{$type_name}) {
       push @{$self->{'document_context'}->[-1]->{'preformatted_classes'}},
         $self->{'pre_class_types'}->{$type_name};
+      push @{$self->{'document_context'}->[-1]->{'preformatted_context'}}, 1;
       push @{$self->{'document_context'}->[-1]->{'composition_context'}},
         $type_name;
     }
@@ -12446,6 +12452,7 @@ sub _convert($$;$)
     if ($self->{'pre_class_types'}->{$type_name}) {
       pop @{$self->{'document_context'}->[-1]->{'preformatted_classes'}};
       pop @{$self->{'document_context'}->[-1]->{'composition_context'}};
+      pop @{$self->{'document_context'}->[-1]->{'preformatted_context'}};
     }
     print STDERR "DO type ($type_name) => `$result'\n" if $debug;
     return $result;
diff --git a/tp/Texinfo/XS/convert/build_html_perl_state.c 
b/tp/Texinfo/XS/convert/build_html_perl_state.c
index b0d3e7551a..6fb83f309b 100644
--- a/tp/Texinfo/XS/convert/build_html_perl_state.c
+++ b/tp/Texinfo/XS/convert/build_html_perl_state.c
@@ -620,25 +620,6 @@ build_html_preformatted_classes_stack
   return preformatted_classes_av;
 }
 
-AV *
-build_html_monospace_stack (MONOSPACE_CONTEXT_STACK *monospace_stack)
-{
-  AV *monospace_av;
-  int i;
-
-  dTHX;
-
-  monospace_av = newAV ();
-
-  for (i = 0; i < monospace_stack->top; i++)
-    {
-      enum monospace_context context
-        = monospace_stack->stack[i];
-      av_push (monospace_av, newSViv (context));
-    }
-  return monospace_av;
-}
-
 AV *
 build_html_block_commands_stack (COMMAND_STACK *block_commands_stack)
 {
@@ -679,6 +660,7 @@ build_html_document_context (HTML_DOCUMENT_CONTEXT 
*document_context)
 {
   HV *hv;
   AV *monospace_av;
+  AV *preformatted_context_av;
   AV *composition_context_av;
   AV *block_commands_av;
   AV *formatting_context_av;
@@ -696,10 +678,14 @@ build_html_document_context (HTML_DOCUMENT_CONTEXT 
*document_context)
   STORE ("document_global_context",
          newSVpv_utf8 (document_context->document_global_context, 0));
 
-  monospace_av = build_html_monospace_stack (
+  monospace_av = build_integer_stack (
                                 &document_context->monospace);
   STORE ("monospace", newRV_noinc ((SV *) monospace_av));
 
+  preformatted_context_av = build_integer_stack (
+                                &document_context->preformatted_context);
+  STORE ("preformatted_context", newRV_noinc ((SV *) preformatted_context_av));
+
   composition_context_av = build_html_composition_context_stack (
                                 &document_context->composition_context);
   STORE ("composition_context", newRV_noinc ((SV *) composition_context_av));
@@ -865,6 +851,7 @@ build_html_formatting_state (CONVERTER *converter, unsigned 
long flags)
       AV *preformatted_classes_av;
       AV *block_commands_av;
       AV *monospace_av;
+      AV *preformatted_context_av;
 
       document_context_sv = hv_fetch (hv, "document_context",
                                       strlen ("document_context"), 0);
@@ -898,9 +885,32 @@ build_html_formatting_state (CONVERTER *converter, 
unsigned long flags)
   build_context(composition_context)
   build_context(preformatted_classes)
   build_context(block_commands)
-  build_context(monospace)
 #undef build_context
 
+#define STORE_DOC_CTX(key, value) hv_store (top_document_context_hv, \
+                                            key, strlen (key), value, 0)
+      if (flags & HMSF_monospace)
+        {
+          monospace_av = build_integer_stack (
+                    &top_document_ctx->monospace);
+          STORE_DOC_CTX("monospace",
+                        newRV_noinc ((SV *) monospace_av));
+        }
+      if (flags & HMSF_composition_context)
+        {
+          preformatted_context_av = build_integer_stack (
+                    &top_document_ctx->preformatted_context);
+          STORE_DOC_CTX("preformatted_context",
+                        newRV_noinc ((SV *) preformatted_context_av));
+        }
+
+      if (flags & HMSF_preformatted_classes)
+        {
+           STORE_DOC_CTX("inside_preformatted",
+            newSViv (top_document_ctx->inside_preformatted));
+        }
+#undef STORE_DOC_CTX
+
       if (flags & HMSF_top_document_ctx)
         build_html_document_context_ctx (top_document_context_hv,
                                          top_document_ctx);
diff --git a/tp/Texinfo/XS/convert/convert_html.c 
b/tp/Texinfo/XS/convert/convert_html.c
index b9a6b92a6f..5d9383f5ca 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -454,20 +454,38 @@ html_pgdt_tree (const char *translation_context, const 
char *string,
                         translation_context, in_lang);
 }
 
-int in_code (CONVERTER *self)
+int
+in_code (CONVERTER *self)
 {
   HTML_DOCUMENT_CONTEXT *top_document_ctx;
   top_document_ctx = html_top_document_context (self);
-  return top_monospace_context (&top_document_ctx->monospace);
+  return top_integer_stack (&top_document_ctx->monospace);
 }
 
-int in_math (CONVERTER *self)
+int
+in_math (CONVERTER *self)
 {
   HTML_DOCUMENT_CONTEXT *top_document_ctx;
   top_document_ctx = html_top_document_context (self);
   return top_document_ctx->math_ctx;
 }
 
+int
+in_preformatted_context (CONVERTER *self)
+{    
+  HTML_DOCUMENT_CONTEXT *top_document_ctx;               
+  top_document_ctx = html_top_document_context (self);
+  return top_integer_stack (&top_document_ctx->preformatted_context);
+}
+
+int
+inside_preformatted (CONVERTER *self)
+{
+  HTML_DOCUMENT_CONTEXT *top_document_ctx;
+  top_document_ctx = html_top_document_context (self);
+  return top_document_ctx->inside_preformatted;
+}
+
 int
 in_raw (CONVERTER *self)
 {
@@ -2579,7 +2597,8 @@ html_new_document_context (CONVERTER *self,
   doc_context->context = strdup (context_name);
   doc_context->document_global_context = document_global_context;
 
-  push_style_no_code (&doc_context->monospace);
+  push_integer_stack_integer (&doc_context->monospace, 0);
+  push_integer_stack_integer (&doc_context->preformatted_context, 0);
   push_command_or_type (&doc_context->composition_context, 0, 0);
   if (block_command)
     push_command (&doc_context->block_commands, block_command);
@@ -2616,6 +2635,7 @@ html_pop_document_context (CONVERTER *self)
 
   free (document_ctx->context);
   free (document_ctx->monospace.stack);
+  free (document_ctx->preformatted_context.stack);
   free (document_ctx->composition_context.stack);
   free (document_ctx->preformatted_classes.stack);
   if (document_ctx->block_commands.top > 0)
@@ -3224,9 +3244,14 @@ reset_unset_no_arg_commands_formatting_context 
(CONVERTER *self,
       /* should not be needed for at commands no brace translation strings */
           push_string_stack_string (&top_document_ctx->preformatted_classes,
                               html_commands_data[preformated_cmd].pre_class);
+          push_integer_stack_integer (&top_document_ctx->preformatted_context,
+                                      1);
+          top_document_ctx->inside_preformatted++;
 
           translation_result = html_convert_tree (self, translated_tree,
                                                   explanation);
+          top_document_ctx->inside_preformatted--;
+          pop_integer_stack (&top_document_ctx->preformatted_context);
           pop_command_or_type (&top_document_ctx->composition_context);
           pop_string_stack (&top_document_ctx->preformatted_classes);
           html_pop_document_context (self);
@@ -3599,6 +3624,7 @@ convert_to_html_internal (CONVERTER *self, const ELEMENT 
*element,
       if (self->current_commands_conversion_function[cmd])
         {
           int convert_to_latex = 0;
+          int preformatted = 0;
           HTML_ARGS_FORMATTED *args_formatted = 0;
           TEXT content_formatted;
 
@@ -3635,18 +3661,28 @@ convert_to_html_internal (CONVERTER *self, const 
ELEMENT *element,
               self->modified_state |= HMSF_block_commands;
             }
 
-          if (html_commands_data[data_cmd].flags & HF_composition_context)
-            {
-              push_command_or_type (&top_document_ctx->composition_context,
-                                    cmd, 0);
-              self->modified_state |= HMSF_composition_context;
-            }
-
           if (html_commands_data[data_cmd].flags & HF_pre_class)
             {
               push_string_stack_string 
(&top_document_ctx->preformatted_classes,
                                         
html_commands_data[data_cmd].pre_class);
               self->modified_state |= HMSF_preformatted_classes;
+              if (builtin_command_data[data_cmd].flags & CF_preformatted)
+                {
+                  preformatted = 1;
+                  top_document_ctx->inside_preformatted++;
+                }
+              else if (builtin_command_data[data_cmd].data == BLOCK_menu
+                       && top_document_ctx->inside_preformatted)
+                preformatted = 1;
+            }
+
+          if (html_commands_data[data_cmd].flags & HF_composition_context)
+            {
+              push_command_or_type (&top_document_ctx->composition_context,
+                                    cmd, 0);
+              push_integer_stack_integer 
(&top_document_ctx->preformatted_context,
+                                        preformatted);
+              self->modified_state |= HMSF_composition_context;
             }
 
           if (html_commands_data[data_cmd].flags & HF_format_raw)
@@ -3663,13 +3699,13 @@ convert_to_html_internal (CONVERTER *self, const 
ELEMENT *element,
           if (builtin_command_data[data_cmd].other_flags & CF_brace_code
               || builtin_command_data[data_cmd].flags & CF_preformatted_code)
             {
-              push_monospace (&top_document_ctx->monospace);
+              push_integer_stack_integer (&top_document_ctx->monospace, 1);
               self->modified_state |= HMSF_monospace;
             }
           else if (builtin_command_data[data_cmd].flags & CF_brace
                    && builtin_command_data[data_cmd].data == 
BRACE_style_no_code)
             {
-              push_style_no_code (&top_document_ctx->monospace);
+              push_integer_stack_integer (&top_document_ctx->monospace, 0);
               self->modified_state |= HMSF_monospace;
             }
           else if (self->upper_case[cmd])
@@ -3810,12 +3846,13 @@ convert_to_html_internal (CONVERTER *self, const 
ELEMENT *element,
                           text_reset (&formatted_arg);
                           xasprintf (&explanation, "%s A[%d]monospace",
                                                    command_type.text, arg_idx);
-                          push_monospace (&top_document_ctx->monospace);
+                          push_integer_stack_integer (
+                                          &top_document_ctx->monospace, 1);
                           self->modified_state |= HMSF_monospace;
 
                           convert_to_html_internal (self, arg, &formatted_arg,
                                                     explanation);
-                          pop_monospace_context
+                          pop_integer_stack
                               (&top_document_ctx->monospace);
                           self->modified_state |= HMSF_monospace;
 
@@ -3852,14 +3889,15 @@ convert_to_html_internal (CONVERTER *self, const 
ELEMENT *element,
                                                      0, 0);
                           string_document_ctx = html_top_document_context 
(self);
                           string_document_ctx->string_ctx++;
-                          push_monospace (&string_document_ctx->monospace);
+                          push_integer_stack_integer (
+                               &string_document_ctx->monospace, 1);
                           xasprintf (&explanation, "%s A[%d]monospacestring",
                                                    command_type.text, arg_idx);
                           convert_to_html_internal (self, arg, &formatted_arg,
                                                     explanation);
 
                           free (explanation);
-                          pop_monospace_context
+                          pop_integer_stack
                               (&string_document_ctx->monospace);
                           html_pop_document_context (self);
                           arg_formatted->formatted[AFT_type_monospacestring]
@@ -3933,12 +3971,15 @@ convert_to_html_internal (CONVERTER *self, const 
ELEMENT *element,
           if (html_commands_data[data_cmd].flags & HF_composition_context)
             {
               pop_command_or_type (&top_document_ctx->composition_context);
+              pop_integer_stack (&top_document_ctx->preformatted_context);
               self->modified_state |= HMSF_composition_context;
             }
 
           if (html_commands_data[data_cmd].flags & HF_pre_class)
             {
               pop_string_stack (&top_document_ctx->preformatted_classes);
+              if (builtin_command_data[data_cmd].flags & CF_preformatted)
+                top_document_ctx->inside_preformatted--;
               self->modified_state |= HMSF_preformatted_classes;
             }
 
@@ -3958,7 +3999,7 @@ convert_to_html_internal (CONVERTER *self, const ELEMENT 
*element,
                   && builtin_command_data[data_cmd].data == 
BRACE_style_no_code)
               || builtin_command_data[data_cmd].other_flags & CF_brace_code)
             {
-              pop_monospace_context (&top_document_ctx->monospace);
+              pop_integer_stack (&top_document_ctx->monospace);
               self->modified_state |= HMSF_monospace;
             }
           else if (self->upper_case[cmd])
@@ -4091,13 +4132,14 @@ convert_to_html_internal (CONVERTER *self, const 
ELEMENT *element,
                                     self->pre_class_types[type]);
           push_command_or_type (&top_document_ctx->composition_context,
                                 0, type);
+          push_integer_stack_integer (&top_document_ctx->preformatted_context, 
1);
           self->modified_state |= HMSF_preformatted_classes
                                   | HMSF_composition_context;
         }
 
       if (self->code_types[type])
         {
-          push_monospace (&top_document_ctx->monospace);
+          push_integer_stack_integer (&top_document_ctx->monospace, 1);
           self->modified_state |= HMSF_monospace;
         }
 
@@ -4153,7 +4195,7 @@ convert_to_html_internal (CONVERTER *self, const ELEMENT 
*element,
 
       if (self->code_types[type])
         {
-          pop_monospace_context (&top_document_ctx->monospace);
+          pop_integer_stack (&top_document_ctx->monospace);
           self->modified_state |= HMSF_monospace;
         }
 
@@ -4167,6 +4209,7 @@ convert_to_html_internal (CONVERTER *self, const ELEMENT 
*element,
         {
           pop_string_stack (&top_document_ctx->preformatted_classes);
           pop_command_or_type (&top_document_ctx->composition_context);
+          pop_integer_stack (&top_document_ctx->preformatted_context);
           self->modified_state |= HMSF_preformatted_classes
                                   | HMSF_composition_context;
         }
diff --git a/tp/Texinfo/XS/main/build_perl_info.c 
b/tp/Texinfo/XS/main/build_perl_info.c
index 0e9ebb76d2..d7bd35e13c 100644
--- a/tp/Texinfo/XS/main/build_perl_info.c
+++ b/tp/Texinfo/XS/main/build_perl_info.c
@@ -1550,6 +1550,24 @@ rebuild_output_units_list (SV *output_units_sv, size_t 
output_units_descriptor)
             newSViv (output_units_descriptor), 0);
 }
 
+AV *
+build_integer_stack (INTEGER_STACK *integer_stack)
+{
+  AV *av;
+  int i;
+
+  dTHX;
+
+  av = newAV ();
+
+  for (i = 0; i < integer_stack->top; i++)
+    {
+      int value = integer_stack->stack[i];
+      av_push (av, newSViv (value));
+    }
+  return av;
+}
+
 SV *
 build_filenames (FILE_NAME_PATH_COUNTER_LIST *output_unit_files)
 {
diff --git a/tp/Texinfo/XS/main/build_perl_info.h 
b/tp/Texinfo/XS/main/build_perl_info.h
index a5bc1ce6bc..81b27b9af7 100644
--- a/tp/Texinfo/XS/main/build_perl_info.h
+++ b/tp/Texinfo/XS/main/build_perl_info.h
@@ -39,6 +39,8 @@ SV *build_output_units_list (size_t output_units_descriptor);
 void rebuild_output_units_list (SV *output_units_sv,
                                 size_t output_units_descriptor);
 
+AV *build_integer_stack (INTEGER_STACK *integer_stack);
+
 void pass_output_unit_files (SV *converter_sv,
                         FILE_NAME_PATH_COUNTER_LIST *output_unit_files);
 
diff --git a/tp/Texinfo/XS/main/command_stack.c 
b/tp/Texinfo/XS/main/command_stack.c
index 2ae66f1c3c..42a5045980 100644
--- a/tp/Texinfo/XS/main/command_stack.c
+++ b/tp/Texinfo/XS/main/command_stack.c
@@ -152,48 +152,35 @@ top_string_stack (STRING_STACK *stack)
 }
 
 
-/* stack of monospace contexts */
-static void
-push_monospace_context (MONOSPACE_CONTEXT_STACK *stack,
-                        enum monospace_context mono_ctx)
+/* stack of integers */
+void
+push_integer_stack_integer (INTEGER_STACK *stack, int value)
 {
   if (stack->top >= stack->space)
     {
       stack->stack
         = realloc (stack->stack,
-                   (stack->space += 5) * sizeof (enum monospace_context));
+                   (stack->space += 5) * sizeof (int));
     }
 
-  stack->stack[stack->top] = mono_ctx;
+  stack->stack[stack->top] = value;
   stack->top++;
 }
 
-void
-push_monospace (MONOSPACE_CONTEXT_STACK *stack)
-{
-  push_monospace_context (stack, MONO_ctx_on);
-}
-
-void
-push_style_no_code (MONOSPACE_CONTEXT_STACK *stack)
-{
-  push_monospace_context (stack, MONO_ctx_off);
-}
-
-enum monospace_context
-pop_monospace_context (MONOSPACE_CONTEXT_STACK *stack)
+int
+pop_integer_stack (INTEGER_STACK *stack)
 {
   if (stack->top == 0)
-    fatal ("monospace stack empty for top");
+    fatal ("integer stack empty for top");
 
   return stack->stack[--stack->top];
 }
 
-enum monospace_context
-top_monospace_context (MONOSPACE_CONTEXT_STACK *stack)
+int
+top_integer_context (INTEGER_STACK *stack)
 {
   if (stack->top == 0)
-    fatal ("monospace stack empty for top");
+    fatal ("integer stack empty for top");
 
   return stack->stack[stack->top - 1];
 }
diff --git a/tp/Texinfo/XS/main/command_stack.h 
b/tp/Texinfo/XS/main/command_stack.h
index f689f07a67..c36eb40af7 100644
--- a/tp/Texinfo/XS/main/command_stack.h
+++ b/tp/Texinfo/XS/main/command_stack.h
@@ -36,10 +36,9 @@ void push_string_stack_string (STRING_STACK *stack, char 
*string);
 void pop_string_stack (STRING_STACK *stack);
 char *top_string_stack (STRING_STACK *stack);
 
-void push_monospace (MONOSPACE_CONTEXT_STACK *stack);
-void push_style_no_code (MONOSPACE_CONTEXT_STACK *stack);
-enum monospace_context pop_monospace_context (MONOSPACE_CONTEXT_STACK *stack);
-enum monospace_context top_monospace_context (MONOSPACE_CONTEXT_STACK *stack);
+void push_integer_stack_integer (INTEGER_STACK *stack, int value);
+int pop_integer_stack (INTEGER_STACK *stack);
+int top_integer_stack (INTEGER_STACK *stack);
 
 HTML_DOCUMENT_CONTEXT *html_top_document_context (CONVERTER *self);
 
diff --git a/tp/Texinfo/XS/main/converter_types.h 
b/tp/Texinfo/XS/main/converter_types.h
index 66319edab5..49182a8f6f 100644
--- a/tp/Texinfo/XS/main/converter_types.h
+++ b/tp/Texinfo/XS/main/converter_types.h
@@ -44,11 +44,6 @@ enum command_type_variety {
    CTV_type_type,
 };
 
-enum monospace_context {
-   MONO_ctx_off,
-   MONO_ctx_on,
-};
-
 #define HCC_CONTEXT_TYPES_LIST \
   cctx_type(normal) \
   cctx_type(preformatted) \
@@ -181,10 +176,10 @@ typedef struct {
 } STRING_STACK;
 
 typedef struct {
-    enum monospace_context *stack;
+    int *stack;
     size_t top;   /* One above last pushed. */
     size_t space;
-} MONOSPACE_CONTEXT_STACK;
+} INTEGER_STACK;
 
 typedef struct VARIETY_DIRECTION_INDEX {
     char *special_unit_variety;
@@ -337,8 +332,10 @@ typedef struct HTML_DOCUMENT_CONTEXT {
     int raw_ctx;
     int verbatim_ctx;
     int math_ctx;
+    int inside_preformatted;
     char *document_global_context;
-    MONOSPACE_CONTEXT_STACK monospace;
+    INTEGER_STACK monospace;
+    INTEGER_STACK preformatted_context;
     COMMAND_OR_TYPE_STACK composition_context;
     COMMAND_STACK block_commands;
     HTML_FORMATTING_CONTEXT_STACK formatting_context;
diff --git a/tp/init/book.pm b/tp/init/book.pm
index f2785f88e4..d91ff824b8 100644
--- a/tp/init/book.pm
+++ b/tp/init/book.pm
@@ -411,7 +411,7 @@ sub book_convert_heading_command($$$$$)
 
     my $heading_class = $level_corrected_cmdname;
     unshift @heading_classes, $heading_class;
-    if ($self->in_preformatted()) {
+    if ($self->in_preformatted_context()) {
       my $id_str = '';
       if (defined($heading_id)) {
         $id_str = " id=\"$heading_id\"";
diff --git a/tp/init/html32.pm b/tp/init/html32.pm
index dc482f11fd..5b304d0393 100644
--- a/tp/init/html32.pm
+++ b/tp/init/html32.pm
@@ -162,7 +162,7 @@ sub html32_convert_text($$$$)
     $text =~ s/--/-/g;
     $text =~ s/\x{1F}/--/g;
   }
-  if (!$self->in_preformatted()
+  if (!$self->in_preformatted_context()
       and ($self->in_non_breakable_space()
              or $self->in_space_protected())) {
     $text .= '&nbsp;' if (chomp($text));



reply via email to

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