texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Patrice Dumas
Date: Sat, 2 Dec 2023 10:49:50 -0500 (EST)

branch: master
commit cb6fbd9ce36fc51ad5fed31c4e4fc6c7cec08ede
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Dec 2 16:49:34 2023 +0100

    * tp/Texinfo/Convert/HTML.pm (preformatted_classes_stack),
    doc/texi2any_api.texi (Conversion in Preformatted Context): return a
    reference on an array instead of an array.  Update callers.
    
    * tp/Texinfo/Convert/HTML.pm
    (_reset_unset_no_arg_commands_formatting_context): use
    _open_command_update_context to set the context of a preformatted
    command.
    
    * tp/Texinfo/Convert/HTML.pm (_set_code_context, _pop_code_context)
    (_set_string_context, _unset_string_context, _set_raw_context)
    (_unset_raw_context, _convert): add functions to encapsulate
    modification of document context to be able to override them with XS.
    
    * tp/Texinfo/Convert/HTML.pm (%XS_conversion_overrides),
    tp/Texinfo/XS/convert/ConvertXS.xs (html_new_document_context)
    (html_pop_document_context, html_open_command_update_context)
    (html_convert_command_update_context, html_open_type_update_context)
    (html_convert_type_update_context, html_set_code_context)
    (html_pop_code_context, html_set_string_context)
    (html_unset_string_context, html_set_raw_context)
    (html_unset_raw_context, html_debug_print_html_contexts)
    (html_in*, html_paragraph_number, html_preformatted_number)
    (html_top_block_command, html_preformatted_classes_stack),
    tp/Texinfo/XS/convert/build_html_perl_state.c
    (build_html_formatting_state), tp/Texinfo/XS/convert/convert_html.c
    (html_in*, html_paragraph_number html_preformatted_number)
    (html_top_block_command, html_preformatted_classes_stack)
    (html_in_align, html_set_code_context, html_pop_code_context)
    (html_set_string_context) (html_unset_string_context)
    (html_set_raw_context, html_unset_raw_context)
    (html_new_document_context, html_check_transfer_state_finalization)
    (html_open_command_update_context, html_open_type_update_context)
    (html_convert_command_update_context)
    (html_convert_type_update_context, convert_to_html_internal),
    tp/Texinfo/XS/main/converter_types.h (CONVERTER): override all
    the functions setting or accessing document context instead of
    keeping track of modifications to pass information to perl.
    Remove code and data related to the previous design, in particular
    remove build_html_document_context_ctx and build_html_document_context
---
 ChangeLog                                     |  43 +++
 doc/texi2any_api.texi                         |  13 +-
 tp/TODO                                       |  10 -
 tp/Texinfo/Convert/HTML.pm                    | 200 ++++++++++----
 tp/Texinfo/XS/convert/ConvertXS.xs            | 359 ++++++++++++++++++++++----
 tp/Texinfo/XS/convert/build_html_perl_state.c | 237 -----------------
 tp/Texinfo/XS/convert/build_html_perl_state.h |   2 -
 tp/Texinfo/XS/convert/convert_html.c          | 213 +++++++++------
 tp/Texinfo/XS/convert/convert_html.h          |  33 +++
 tp/Texinfo/XS/main/converter_types.h          |   4 -
 tp/Texinfo/XS/main/utils.h                    |  19 +-
 tp/ext/highlight_syntax.pm                    |   3 +-
 12 files changed, 693 insertions(+), 443 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index fe63eacdfa..44aaa1bcee 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,46 @@
+2023-12-02  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/Convert/HTML.pm (preformatted_classes_stack),
+       doc/texi2any_api.texi (Conversion in Preformatted Context): return a
+       reference on an array instead of an array.  Update callers.
+
+       * tp/Texinfo/Convert/HTML.pm
+       (_reset_unset_no_arg_commands_formatting_context): use
+       _open_command_update_context to set the context of a preformatted
+       command.
+
+       * tp/Texinfo/Convert/HTML.pm (_set_code_context, _pop_code_context)
+       (_set_string_context, _unset_string_context, _set_raw_context)
+       (_unset_raw_context, _convert): add functions to encapsulate
+       modification of document context to be able to override them with XS.
+
+       * tp/Texinfo/Convert/HTML.pm (%XS_conversion_overrides),
+       tp/Texinfo/XS/convert/ConvertXS.xs (html_new_document_context)
+       (html_pop_document_context, html_open_command_update_context)
+       (html_convert_command_update_context, html_open_type_update_context)
+       (html_convert_type_update_context, html_set_code_context)
+       (html_pop_code_context, html_set_string_context)
+       (html_unset_string_context, html_set_raw_context)
+       (html_unset_raw_context, html_debug_print_html_contexts)
+       (html_in*, html_paragraph_number, html_preformatted_number)
+       (html_top_block_command, html_preformatted_classes_stack),
+       tp/Texinfo/XS/convert/build_html_perl_state.c
+       (build_html_formatting_state), tp/Texinfo/XS/convert/convert_html.c
+       (html_in*, html_paragraph_number html_preformatted_number)
+       (html_top_block_command, html_preformatted_classes_stack)
+       (html_in_align, html_set_code_context, html_pop_code_context)
+       (html_set_string_context) (html_unset_string_context)
+       (html_set_raw_context, html_unset_raw_context)
+       (html_new_document_context, html_check_transfer_state_finalization)
+       (html_open_command_update_context, html_open_type_update_context)
+       (html_convert_command_update_context)
+       (html_convert_type_update_context, convert_to_html_internal),
+       tp/Texinfo/XS/main/converter_types.h (CONVERTER): override all
+       the functions setting or accessing document context instead of
+       keeping track of modifications to pass information to perl.
+       Remove code and data related to the previous design, in particular
+       remove build_html_document_context_ctx and build_html_document_context
+
 2023-12-01  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/Convert/HTML.pm: use non object oriented call when not
diff --git a/doc/texi2any_api.texi b/doc/texi2any_api.texi
index f12f049f12..45825bb4fc 100644
--- a/doc/texi2any_api.texi
+++ b/doc/texi2any_api.texi
@@ -2702,10 +2702,11 @@ are in preformatted context even if not in a 
preformatted block command.
 If in preformatted context, it is possible to get preformatted @@-commands and
 preformatted types nesting with @code{preformatted_classes_stack}:
 
-@deftypefun {@var{@@preformatted_nesting} =} 
@var{$converter}->preformatted_classes_stack ()
-Returns an array containing the block preformatted @@-commands such as
-@code{@@example}, @code{@@display} or @code{@@menu} names without the leading
-@@ and the HTML attribute class preformatted container names, in order of 
appearance.
+@deftypefun {@var{\@@preformatted_nesting} =} 
@var{$converter}->preformatted_classes_stack ()
+Returns an reference on an array containing the block preformatted @@-commands
+such as @code{@@example}, @code{@@display} or @code{@@menu} names without
+the leading @@ and the HTML attribute class preformatted container names,
+in order of appearance.
 @end deftypefun
 
 The @code{%Texinfo::Commands::preformatted_code_commands}
@@ -2714,8 +2715,8 @@ as code (@pxref{Texinfo::Commands 
%preformatted_code_commands,,,
 texi2any_internals}).
 
 @example
-my @@pre_classes = $converter->preformatted_classes_stack();
-foreach my $pre_class (@@pre_classes) @{
+my $pre_classes = $converter->preformatted_classes_stack();
+foreach my $pre_class (@@$pre_classes) @{
   if ($Texinfo::Commands::preformatted_code_commands@{$pre_class@}) @{
     $result = '<code>' .$result. '</code>';
     last;
diff --git a/tp/TODO b/tp/TODO
index 4d469f92dd..fae66ba51e 100644
--- a/tp/TODO
+++ b/tp/TODO
@@ -14,16 +14,6 @@ Document that Texinfo::Document::rebuild_document or
 Texinfo::Document::rebuild_tree should be called after tree modifications
 if the parser is XS but converters are perl.
 
-Add a comment/TODO somewhere that explains that the need to maintain
-perl and C HTML document contexts exactly in sync is probably a bug somewhere.
-Indeed, the change in perl HTML document context should not need to be
-transmitted to C (through overriding of _new_document_context
-and _pop_document_context) as perl does not call any XS/C formatting
-function -- with the exception of translate_names -- and therefore the
-contexts should be back to where they were before perl was called.  The code
-in C already registers what changed compared to last time perl was called,
-only applying that should be good.
-
 Bugs
 ====
 
diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
index 232ee484b5..85ddaf2ecf 100644
--- a/tp/Texinfo/Convert/HTML.pm
+++ b/tp/Texinfo/Convert/HTML.pm
@@ -118,10 +118,66 @@ my %XS_conversion_overrides = (
    => "Texinfo::Convert::ConvertXS::html_initialize_output_state",
   "Texinfo::Convert::HTML::_finalize_output_state"
    => "Texinfo::Convert::ConvertXS::html_finalize_output_state",
+
+  "Texinfo::Convert::HTML::_open_command_update_context"
+   => "Texinfo::Convert::ConvertXS::html_open_command_update_context",
+  "Texinfo::Convert::HTML::_convert_command_update_context",
+   => "Texinfo::Convert::ConvertXS::html_convert_command_update_context",
+  "Texinfo::Convert::HTML::_open_type_update_context",
+   => "Texinfo::Convert::ConvertXS::html_open_type_update_context",
+  "Texinfo::Convert::HTML::_convert_type_update_context"
+   => "Texinfo::Convert::ConvertXS::html_convert_type_update_context",
   "Texinfo::Convert::HTML::_new_document_context"
    => "Texinfo::Convert::ConvertXS::html_new_document_context",
   "Texinfo::Convert::HTML::_pop_document_context"
    => "Texinfo::Convert::ConvertXS::html_pop_document_context",
+  "Texinfo::Convert::HTML::_set_code_context"
+   => "Texinfo::Convert::ConvertXS::html_set_code_context",
+  "Texinfo::Convert::HTML::_pop_code_context"
+   => "Texinfo::Convert::ConvertXS::html_pop_code_context",
+  "Texinfo::Convert::HTML::_set_string_context"
+   => "Texinfo::Convert::ConvertXS::html_set_string_context",
+  "Texinfo::Convert::HTML::_unset_string_context"
+   => "Texinfo::Convert::ConvertXS::html_unset_string_context",
+  "Texinfo::Convert::HTML::_set_raw_context"
+   => "Texinfo::Convert::ConvertXS::html_set_raw_context",
+  "Texinfo::Convert::HTML::_unset_raw_context"
+   => "Texinfo::Convert::ConvertXS::html_unset_raw_context",
+
+  "Texinfo::Convert::HTML::_debug_print_html_contexts"
+   => "Texinfo::Convert::ConvertXS::html_debug_print_html_contexts",
+
+  "Texinfo::Convert::HTML::in_math"
+   => "Texinfo::Convert::ConvertXS::html_in_math",
+  "Texinfo::Convert::HTML::in_preformatted_context"
+   => "Texinfo::Convert::ConvertXS::html_in_preformatted_context",
+  "Texinfo::Convert::HTML::inside_preformatted"
+   => "Texinfo::Convert::ConvertXS::html_inside_preformatted",
+  "Texinfo::Convert::HTML::in_upper_case"
+   => "Texinfo::Convert::ConvertXS::html_in_upper_case",
+  "Texinfo::Convert::HTML::in_non_breakable_space"
+   => "Texinfo::Convert::ConvertXS::html_in_non_breakable_space",
+  "Texinfo::Convert::HTML::in_space_protected"
+   => "Texinfo::Convert::ConvertXS::html_in_space_protected",
+  "Texinfo::Convert::HTML::in_code"
+   => "Texinfo::Convert::ConvertXS::html_in_code",
+  "Texinfo::Convert::HTML::in_string"
+   => "Texinfo::Convert::ConvertXS::html_in_string",
+  "Texinfo::Convert::HTML::in_verbatim"
+   => "Texinfo::Convert::ConvertXS::html_in_verbatim",
+  "Texinfo::Convert::HTML::in_raw"
+   => "Texinfo::Convert::ConvertXS::html_in_raw",
+  "Texinfo::Convert::HTML::paragraph_number"
+   => "Texinfo::Convert::ConvertXS::html_paragraph_number",
+  "Texinfo::Convert::HTML::preformatted_number"
+   => "Texinfo::Convert::ConvertXS::html_preformatted_number",
+  "Texinfo::Convert::HTML::top_block_command"
+   => "Texinfo::Convert::ConvertXS::html_top_block_command",
+  "Texinfo::Convert::HTML::preformatted_classes_stack"
+   => "Texinfo::Convert::ConvertXS::html_preformatted_classes_stack",
+  "Texinfo::Convert::HTML::in_align"
+   => "Texinfo::Convert::ConvertXS::html_in_align",
+
   "Texinfo::Convert::HTML::register_opened_section_level"
    => "Texinfo::Convert::ConvertXS::html_register_opened_section_level",
   "Texinfo::Convert::HTML::close_registered_sections_level"
@@ -645,15 +701,6 @@ sub in_raw($)
   return $self->{'document_context'}->[-1]->{'raw'};
 }
 
-sub in_multi_expanded($)
-{
-  my $self = shift;
-  if (scalar(@{$self->{'multiple_pass'}})) {
-    return $self->{'multiple_pass'}->[-1];
-  }
-  return undef;
-}
-
 sub paragraph_number($)
 {
   my $self = shift;
@@ -668,6 +715,39 @@ sub preformatted_number($)
                                                   ->{'preformatted_number'};
 }
 
+sub top_block_command($)
+{
+  my $self = shift;
+  return $self->{'document_context'}->[-1]->{'block_commands'}->[-1];
+}
+
+sub preformatted_classes_stack($)
+{
+  my $self = shift;
+  return $self->{'document_context'}->[-1]->{'preformatted_classes'};
+}
+
+sub in_align($)
+{
+  my $self = shift;
+  my $context
+       = $self->{'document_context'}->[-1]->{'composition_context'}->[-1];
+  if ($HTML_align_commands{$context}) {
+    return $context;
+  } else {
+    return undef;
+  }
+}
+
+sub in_multi_expanded($)
+{
+  my $self = shift;
+  if (scalar(@{$self->{'multiple_pass'}})) {
+    return $self->{'multiple_pass'}->[-1];
+  }
+  return undef;
+}
+
 sub count_elements_in_filename($$$)
 {
   my $self = shift;
@@ -695,30 +775,6 @@ sub count_elements_in_filename($$$)
   return undef;
 }
 
-sub top_block_command($)
-{
-  my $self = shift;
-  return $self->{'document_context'}->[-1]->{'block_commands'}->[-1];
-}
-
-sub preformatted_classes_stack($)
-{
-  my $self = shift;
-  return @{$self->{'document_context'}->[-1]->{'preformatted_classes'}};
-}
-
-sub in_align($)
-{
-  my $self = shift;
-  my $context
-       = $self->{'document_context'}->[-1]->{'composition_context'}->[-1];
-  if ($HTML_align_commands{$context}) {
-    return $context;
-  } else {
-    return undef;
-  }
-}
-
 sub is_format_expanded($$)
 {
   my $self = shift;
@@ -5419,8 +5475,8 @@ sub _convert_item_command($$$$$)
       my $result = $self->convert_tree($table_item_tree,
                                        'convert table_item_tree');
       if (in_preformatted_context($self)) {
-        my @pre_classes = $self->preformatted_classes_stack();
-        foreach my $pre_class (@pre_classes) {
+        my $pre_classes = $self->preformatted_classes_stack();
+        foreach my $pre_class (@$pre_classes) {
           if ($preformatted_code_commands{$pre_class}) {
             $result = $self->html_attribute_class('code',
                                     ['table-term-preformatted-code']).'>'
@@ -6488,8 +6544,8 @@ sub _preformatted_class()
 {
   my $self = shift;
   my $pre_class;
-  my @pre_classes = $self->preformatted_classes_stack();
-  foreach my $class (@pre_classes) {
+  my $pre_classes = $self->preformatted_classes_stack();
+  foreach my $class (@$pre_classes) {
     # FIXME maybe add   or $pre_class eq 'menu'  to override
     # 'menu' with 'menu-comment'?
     $pre_class = $class unless ($pre_class
@@ -7168,10 +7224,10 @@ sub _convert_def_line_type($$$$)
           if ($arguments_formatted =~ /\S/);
     } else {
       # only metasyntactic variable arguments (deffn, defvr, deftp, defop, 
defcv)
-      # FIXME should not access directly 'document_context'
-      push @{$self->{'document_context'}->[-1]->{'monospace'}}, 0;
+      # FIXME not part of the API
+      _set_code_context($self, 0);
       my $arguments_formatted = $self->_convert({'contents' => [$arguments]});
-      pop @{$self->{'document_context'}->[-1]->{'monospace'}};
+      _pop_code_context($self);
       if ($arguments_formatted =~ /\S/) {
         $result_arguments = $self->html_attribute_class('var',
                                ['def-var-arguments']).'>'
@@ -7692,6 +7748,43 @@ sub _pop_document_context($)
   }
 }
 
+sub _set_code_context($$)
+{
+  my $self = shift;
+  my $code = shift;
+  push @{$self->{'document_context'}->[-1]->{'monospace'}}, $code;
+}
+
+sub _pop_code_context($)
+{
+  my $self = shift;
+  pop @{$self->{'document_context'}->[-1]->{'monospace'}};
+}
+
+sub _set_string_context($)
+{
+  my $self = shift;
+  $self->{'document_context'}->[-1]->{'string'}++;
+}
+
+sub _unset_string_context($)
+{
+  my $self = shift;
+  $self->{'document_context'}->[-1]->{'string'}--;
+}
+
+sub _set_raw_context($)
+{
+  my $self = shift;
+  $self->{'document_context'}->[-1]->{'raw'}++;
+}
+
+sub _unset_raw_context($)
+{
+  my $self = shift;
+  $self->{'document_context'}->[-1]->{'raw'}--;
+}
+
 # can be set through Texinfo::Config::texinfo_register_file_id_setting_function
 my %customizable_file_id_setting_references;
 foreach my $customized_reference ('external_target_split_name',
@@ -7781,15 +7874,10 @@ sub 
_reset_unset_no_arg_commands_formatting_context($$$$;$)
       # there does not seems to be anything simpler...
       my $preformatted_command_name = 'example';
       $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};
+      _open_command_update_context($self, 'example');
       $translation_result
         = $self->convert_tree($translated_tree, $explanation);
+      _convert_command_update_context($self, 'example');
       $self->_pop_document_context();
     } elsif ($reset_context eq 'string') {
       $translation_result
@@ -12498,20 +12586,22 @@ sub _convert($$;$)
                   $arg_formatted->{'normal'} = $self->_convert($arg, 
$explanation);
                 }
               } elsif ($arg_type eq 'monospace') {
-                push @{$self->{'document_context'}->[-1]->{'monospace'}}, 1;
+                _set_code_context($self, 1);
                 $arg_formatted->{$arg_type} = $self->_convert($arg, 
$explanation);
-                pop @{$self->{'document_context'}->[-1]->{'monospace'}};
+                _pop_code_context($self);
               } elsif ($arg_type eq 'string') {
                 $self->_new_document_context($command_type);
-                $self->{'document_context'}->[-1]->{'string'}++;
+                _set_string_context($self);
                 $arg_formatted->{$arg_type} = $self->_convert($arg, 
$explanation);
+                #_unset_string_context($self);
                 $self->_pop_document_context();
               } elsif ($arg_type eq 'monospacestring') {
                 $self->_new_document_context($command_type);
-                push @{$self->{'document_context'}->[-1]->{'monospace'}}, 1;
-                $self->{'document_context'}->[-1]->{'string'}++;
+                _set_code_context($self, 1);
+                _set_string_context($self);
                 $arg_formatted->{$arg_type} = $self->_convert($arg, 
$explanation);
-                pop @{$self->{'document_context'}->[-1]->{'monospace'}};
+                #_unset_string_context($self);
+                _pop_code_context($self);
                 $self->_pop_document_context();
               } elsif ($arg_type eq 'monospacetext') {
                 $arg_formatted->{$arg_type}
@@ -12534,9 +12624,9 @@ sub _convert($$;$)
                    = Texinfo::Convert::Text::convert_to_text($arg,
                                                    $text_conversion_options);
               } elsif ($arg_type eq 'raw') {
-                $self->{'document_context'}->[-1]->{'raw'}++;
+                _set_raw_context($self);
                 $arg_formatted->{$arg_type} = $self->_convert($arg, 
$explanation);
-                $self->{'document_context'}->[-1]->{'raw'}--;
+                _unset_raw_context($self);
               }
             }
             push @$args_formatted, $arg_formatted;
diff --git a/tp/Texinfo/XS/convert/ConvertXS.xs 
b/tp/Texinfo/XS/convert/ConvertXS.xs
index 724a5bde7c..870dfab5f2 100644
--- a/tp/Texinfo/XS/convert/ConvertXS.xs
+++ b/tp/Texinfo/XS/convert/ConvertXS.xs
@@ -32,6 +32,9 @@
 
 #include "ppport.h"
 
+#include "command_ids.h"
+#include "element_types.h"
+#include "converter_types.h"
 #include "builtin_commands.h"
 #include "convert_plain_texinfo.h"
 #include "convert_text.h"
@@ -244,36 +247,10 @@ html_new_document_context (SV *converter_in, char 
*context_name, ...)
 
          if (self)
            {
-             HV *document_context_hv;
-             HTML_DOCUMENT_CONTEXT *document_context;
-             HV *converter_hv = (HV *) SvRV (converter_in);
-             SV **document_context_sv = hv_fetch (converter_hv,
-                   "document_context", strlen("document_context"), 0);
-             AV *document_context_av = (AV *) SvRV (*document_context_sv);
-             /* should not be needed as we are calling from perl
-             if (self->modified_state)
-               {
-                 build_html_formatting_state (self, self->modified_state);
-                 self->modified_state = 0;
-               }
-              */
              html_new_document_context (self, context_name,
                                         document_global_context, 
block_command);
-             /* reset to ignore the HMSF_formatting_context flag just set */
-             self->modified_state = 0;
-             document_context = html_top_document_context (self);
-
-             document_context_hv = build_html_document_context
-                                                      (document_context);
-             av_push (document_context_av,
-                      newRV_noinc ((SV *) document_context_hv));
-             self->document_context_change--;
-             hv_store (converter_hv, "document_global_context",
-                       strlen ("document_global_context"),
-                       newSViv (self->document_global_context), 0);
            }
 
-
 void
 html_pop_document_context (SV *converter_in)
       PREINIT:
@@ -282,27 +259,321 @@ html_pop_document_context (SV *converter_in)
          self = get_sv_converter (converter_in, "html_new_document_context");
          if (self)
            {
-             HV *converter_hv = (HV *) SvRV (converter_in);
-             SV **document_context_sv = hv_fetch (converter_hv,
-                   "document_context", strlen("document_context"), 0);
-             AV *document_context_av = (AV *) SvRV (*document_context_sv);
-             /* should not be needed as we are calling from perl
-             if (self->modified_state)
-               {
-                 build_html_formatting_state (self, self->modified_state);
-                 self->modified_state = 0;
-               }
-              */
              html_pop_document_context (self);
+           }
 
-             av_pop (document_context_av);
-             hv_store (converter_hv, "document_global_context",
-                       strlen ("document_global_context"),
-                       newSViv (self->document_global_context), 0);
-             /* reset to ignore the HMSF_formatting_context flag just set */
-             self->modified_state = 0;
-             self->document_context_change++;
+int
+html_open_command_update_context (SV *converter_in, char *command_name)
+     PREINIT:
+         CONVERTER *self;
+     CODE:
+         self = get_sv_converter (converter_in,
+                                  "html_open_command_update_context");
+         RETVAL = 0;
+         if (self)
+           {
+             enum command_id cmd = lookup_builtin_command (command_name);
+             RETVAL = html_open_command_update_context (self, cmd);
+           }
+    OUTPUT:
+         RETVAL
+
+void
+html_convert_command_update_context (SV *converter_in, char *command_name)
+     PREINIT:
+         CONVERTER *self;
+     CODE:
+         self = get_sv_converter (converter_in,
+                                  "html_convert_command_update_context");
+         if (self)
+           {
+             enum command_id cmd = lookup_builtin_command (command_name);
+             html_convert_command_update_context (self, cmd);
+           }
+
+void
+html_open_type_update_context (SV *converter_in, char *type_name)
+     PREINIT:
+         CONVERTER *self;
+     CODE:
+         self = get_sv_converter (converter_in,
+                                  "html_open_type_update_context");
+         if (self)
+           {
+             enum element_type type = find_element_type (type_name);
+             html_open_type_update_context (self, type);
+           }
+
+void
+html_convert_type_update_context (SV *converter_in, char *type_name)
+     PREINIT:
+         CONVERTER *self;
+     CODE:
+         self = get_sv_converter (converter_in,
+                                  "html_convert_type_update_context");
+         if (self)
+           {
+             enum element_type type = find_element_type (type_name);
+             html_convert_type_update_context (self, type);
+           }
+
+void
+html_set_code_context (SV *converter_in, int code)
+     PREINIT:
+         CONVERTER *self;
+     CODE:
+         self = get_sv_converter (converter_in,
+                                  "html_set_code_context");
+         if (self)
+           html_set_code_context (self, code);
+
+void
+html_pop_code_context (SV *converter_in)
+     PREINIT:
+         CONVERTER *self;
+     CODE:
+         self = get_sv_converter (converter_in,
+                                  "html_pop_code_context");
+         if (self)
+           html_pop_code_context (self);
+
+void
+html_set_string_context (SV *converter_in)
+     PREINIT:
+         CONVERTER *self;
+     CODE:
+         self = get_sv_converter (converter_in,
+                                  "html_set_string_context");
+         if (self)
+           html_set_string_context (self);
+
+void
+html_unset_string_context (SV *converter_in)
+     PREINIT:
+         CONVERTER *self;
+     CODE:
+         self = get_sv_converter (converter_in,
+                                  "html_unset_string_context");
+         if (self)
+           html_unset_string_context (self);
+
+void
+html_set_raw_context (SV *converter_in)
+     PREINIT:
+         CONVERTER *self;
+     CODE:
+         self = get_sv_converter (converter_in,
+                                  "html_set_raw_context");
+         if (self)
+           html_set_raw_context (self);
+
+void
+html_unset_raw_context (SV *converter_in)
+     PREINIT:
+         CONVERTER *self;
+     CODE:
+         self = get_sv_converter (converter_in,
+                                  "html_unset_raw_context");
+         if (self)
+           html_unset_raw_context (self);
+
+SV *
+html_debug_print_html_contexts (SV *converter_in)
+     PREINIT:
+         CONVERTER *self;
+     CODE:
+         self = get_sv_converter (converter_in,
+                                  "html_debug_print_html_contexts");
+         if (self)
+           {
+             char *result = debug_print_html_contexts (self);
+             RETVAL = newSVpv_utf8 (result, 0);
+             free (result);
+           }
+         else
+           RETVAL = newSVpv_utf8 ("", 0);
+    OUTPUT:
+         RETVAL
+
+int
+html_in_math (SV *converter_in)
+     PREINIT:
+         CONVERTER *self;
+     CODE:
+         self = get_sv_converter (converter_in,
+                                  "html_in_math");
+         RETVAL = html_in_math (self);
+    OUTPUT:
+         RETVAL
+
+int
+html_in_preformatted_context (SV *converter_in)
+     PREINIT:
+         CONVERTER *self;
+     CODE:
+         self = get_sv_converter (converter_in,
+                                  "html_in_preformatted_context");
+         RETVAL = html_in_preformatted_context (self);
+    OUTPUT:
+         RETVAL
+
+int
+html_inside_preformatted (SV *converter_in)
+     PREINIT:
+         CONVERTER *self;
+     CODE:
+         self = get_sv_converter (converter_in,
+                                  "html_inside_preformatted");
+         RETVAL = html_inside_preformatted (self);
+    OUTPUT:
+         RETVAL
+
+int
+html_in_upper_case (SV *converter_in)
+     PREINIT:
+         CONVERTER *self;
+     CODE:
+         self = get_sv_converter (converter_in,
+                                  "html_in_upper_case");
+         RETVAL = html_in_upper_case (self);
+    OUTPUT:
+         RETVAL
+
+int
+html_in_non_breakable_space (SV *converter_in)
+     PREINIT:
+         CONVERTER *self;
+     CODE:
+         self = get_sv_converter (converter_in,
+                                  "html_in_non_breakable_space");
+         RETVAL = html_in_non_breakable_space (self);
+    OUTPUT:
+         RETVAL
+
+int
+html_in_space_protected (SV *converter_in)
+     PREINIT:
+         CONVERTER *self;
+     CODE:
+         self = get_sv_converter (converter_in,
+                                  "html_in_space_protected");
+         RETVAL = html_in_space_protected (self);
+    OUTPUT:
+         RETVAL
+
+int
+html_in_code (SV *converter_in)
+     PREINIT:
+         CONVERTER *self;
+     CODE:
+         self = get_sv_converter (converter_in,
+                                  "html_in_code");
+         RETVAL = html_in_code (self);
+    OUTPUT:
+         RETVAL
+
+int
+html_in_string (SV *converter_in)
+     PREINIT:
+         CONVERTER *self;
+     CODE:
+         self = get_sv_converter (converter_in,
+                                  "html_in_string");
+         RETVAL = html_in_string (self);
+    OUTPUT:
+         RETVAL
+
+int
+html_in_verbatim (SV *converter_in)
+     PREINIT:
+         CONVERTER *self;
+     CODE:
+         self = get_sv_converter (converter_in,
+                                  "html_in_verbatim");
+         RETVAL = html_in_verbatim (self);
+    OUTPUT:
+         RETVAL
+
+int
+html_in_raw (SV *converter_in)
+     PREINIT:
+         CONVERTER *self;
+     CODE:
+         self = get_sv_converter (converter_in,
+                                  "html_in_raw");
+         RETVAL = html_in_raw (self);
+    OUTPUT:
+         RETVAL
+
+int
+html_paragraph_number (SV *converter_in)
+     PREINIT:
+         CONVERTER *self;
+     CODE:
+         self = get_sv_converter (converter_in,
+                                  "html_paragraph_number");
+         RETVAL = html_paragraph_number (self);
+    OUTPUT:
+         RETVAL
+
+int
+html_preformatted_number (SV *converter_in)
+     PREINIT:
+         CONVERTER *self;
+     CODE:
+         self = get_sv_converter (converter_in,
+                                  "html_preformatted_number");
+         RETVAL = html_preformatted_number (self);
+    OUTPUT:
+         RETVAL
+
+char *
+html_top_block_command (SV *converter_in)
+     PREINIT:
+         CONVERTER *self;
+         enum command_id cmd;
+     CODE:
+         self = get_sv_converter (converter_in,
+                                  "html_top_block_command");
+         cmd = html_top_block_command (self);
+         RETVAL = builtin_command_name (cmd);
+    OUTPUT:
+         RETVAL
+
+SV *
+html_preformatted_classes_stack (SV *converter_in)
+     PREINIT:
+         CONVERTER *self;
+         STRING_STACK *preformatted_classes_stack;
+         AV *preformatted_classes_av;
+         size_t i;
+     CODE:
+         self = get_sv_converter (converter_in,
+                                  "html_preformatted_classes_stack");
+         preformatted_classes_stack = html_preformatted_classes_stack (self);
+         preformatted_classes_av = newAV();
+         for (i = 0; i < preformatted_classes_stack->top; i++)
+           {
+             SV *class_sv
+               = newSVpv_utf8 (preformatted_classes_stack->stack[i], 0);
+             av_push (preformatted_classes_av, class_sv);
            }
+         RETVAL = newRV_noinc ((SV *)preformatted_classes_av);
+    OUTPUT:
+         RETVAL
+
+char *
+html_in_align (SV *converter_in)
+     PREINIT:
+         CONVERTER *self;
+         enum command_id cmd;
+     CODE:
+         self = get_sv_converter (converter_in,
+                                  "html_in_align");
+         cmd = html_in_align (self);
+         RETVAL = builtin_command_name (cmd);
+    OUTPUT:
+         RETVAL
 
 void
 html_register_opened_section_level (SV *converter_in, int level, close_string)
diff --git a/tp/Texinfo/XS/convert/build_html_perl_state.c 
b/tp/Texinfo/XS/convert/build_html_perl_state.c
index dac3f351d4..326031d3fc 100644
--- a/tp/Texinfo/XS/convert/build_html_perl_state.c
+++ b/tp/Texinfo/XS/convert/build_html_perl_state.c
@@ -659,80 +659,11 @@ build_html_block_commands_stack (COMMAND_STACK 
*block_commands_stack)
   return block_commands_av;
 }
 
-void
-build_html_document_context_ctx (HV *hv,
-                                 HTML_DOCUMENT_CONTEXT *document_context)
-{
-  dTHX;
-
-#define STORE(key, value) hv_store (hv, key, strlen (key), value, 0)
-#define STORE_CTX(name) STORE(#name, newSViv (document_context->name##_ctx))
-  STORE_CTX(string);
-  STORE_CTX(raw);
-  STORE_CTX(verbatim);
-  STORE_CTX(math);
-#undef STORE_CTX
-#undef STORE
-}
-
-HV *
-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;
-  AV *preformatted_classes_av;
-
-  dTHX;
-
-  hv = newHV ();
-
-  build_html_document_context_ctx (hv, document_context);
-
-#define STORE(key, value) hv_store (hv, key, strlen (key), value, 0)
-
-  STORE ("context", newSVpv_utf8 (document_context->context, 0));
-  STORE ("document_global_context",
-         newSVpv_utf8 (document_context->document_global_context, 0));
-
-  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));
-
-  block_commands_av = build_html_block_commands_stack
-                              (&document_context->block_commands);
-  STORE ("block_commands", newRV_noinc ((SV *) block_commands_av));
-
-  preformatted_classes_av = build_html_preformatted_classes_stack
-                               (&document_context->preformatted_classes);
-  STORE ("preformatted_classes", newRV_noinc ((SV *) preformatted_classes_av));
-
-  formatting_context_av = build_html_formatting_context_stack
-                               (&document_context->formatting_context);
-  STORE ("formatting_context", newRV_noinc ((SV *) formatting_context_av));
-
-#undef STORE
-  return hv;
-}
-
 /* there is no need to return anything. */
 SV *
 build_html_formatting_state (CONVERTER *converter, unsigned long flags)
 {
   HV *hv;
-  SV **document_context_sv;
-  AV *document_context_av;
   /*
   SV **files_information_sv;
   HV *files_information_hv;
@@ -801,174 +732,6 @@ build_html_formatting_state (CONVERTER *converter, 
unsigned long flags)
         SvUTF8_on (*current_filename_sv);
     }
 
-  if (flags & HMSF_document_context
-      && (converter->document_context_change
-          || converter->document_contexts_to_pop))
-    {
-      SSize_t top_document_context_idx;
-      FETCH(document_context);
-
-      if (!document_context_sv)
-        {
-          document_context_av = newAV ();
-          fprintf (stderr, "BUG: no document context\n");
-          STORE("document_context", newRV_noinc ((SV *) document_context_av));
-          top_document_context_idx = -1;
-        }
-      else
-        {
-          int doc_top_target;
-          document_context_av = (AV *) SvRV (*document_context_sv);
-          /* check consistentcy of C and perl document context stack levels */
-          top_document_context_idx = av_top_index (document_context_av);
-          doc_top_target = top_document_context_idx+1
-                               + converter->document_context_change;
-          if (doc_top_target != converter->html_document_context.top)
-            {
-              fprintf (stderr,
-          "BUG: top and document context level change mismatch %zu %d (%zu)\n",
-                  converter->html_document_context.top, doc_top_target,
-                  top_document_context_idx+1);
-            }
-
-          /* remove obsolete document contexts in perl */
-          while (converter->document_contexts_to_pop)
-            {
-               /*
-              SV** top_context_sv = av_fetch(document_context_av,
-                                             top_document_context_idx, 0);
-              if (top_context_sv)
-                {
-                  HV *top_context_hv = (HV *) SvRV (*top_context_sv);
-                  SV **context_sv = hv_fetch (top_context_hv, "context",
-                                              strlen ("context"), 0);
-                  char *context = (char *) SvPVutf8_nolen (*context_sv);
-                  fprintf (stderr, "PLPOP (top %zu) ctx '%s'\n",
-                                   top_document_context_idx, context);
-                }
-                */
-              av_pop (document_context_av);
-              converter->document_contexts_to_pop--;
-              top_document_context_idx--;
-            }
-        }
-
-      /* add the modified contexts */
-      for (i = top_document_context_idx +1;
-           i < converter->html_document_context.top; i++)
-        {
-          HTML_DOCUMENT_CONTEXT *document_context
-            = &converter->html_document_context.stack[i];
-          HV *document_context_hv = build_html_document_context 
(document_context);
-          /*
-          fprintf (stderr, "PLPUSH ctx '%s'\n", document_context->context);
-           */
-          av_push (document_context_av, newRV_noinc ((SV *) 
document_context_hv));
-        }
-      converter->document_context_change = 0;
-    }
-
-  if (flags & (HMSF_formatting_context | HMSF_composition_context
-                    | HMSF_preformatted_classes | HMSF_block_commands
-                    | HMSF_monospace | HMSF_top_document_ctx
-                    | HMSF_top_formatting_context))
-    {
-      HTML_DOCUMENT_CONTEXT *top_document_ctx
-         = html_top_document_context (converter);
-      SSize_t top_document_context_idx;
-      SV **top_document_context_sv;
-      HV *top_document_context_hv;
-      AV *formatting_context_av;
-      AV *composition_context_av;
-      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);
-      if (!document_context_sv)
-        {
-          fprintf (stderr,
-                   "BUG: no document context but formatting F: %#8lx\n", 
flags);
-          abort();
-        }
-      document_context_av = (AV *) SvRV (*document_context_sv);
-      top_document_context_idx = av_top_index (document_context_av);
-      if (top_document_context_idx < 0)
-        {
-          fprintf (stderr,
-               "BUG: empty document_context but formatting F: %#8lx\n", flags);
-        }
-      top_document_context_sv = av_fetch (document_context_av,
-                                          top_document_context_idx, 0);
-
-      top_document_context_hv = (HV *) SvRV (*top_document_context_sv);
-#define build_context(name) \
-      if (flags & HMSF_##name) \
-        { \
-          name##_av = build_html_##name##_stack(  \
-                                   &top_document_ctx->name);    \
-          hv_store (top_document_context_hv, #name,             \
-                                    strlen (#name),               \
-                         newRV_noinc ((SV *) name##_av), 0);    \
-        }
-  build_context(formatting_context)
-  build_context(composition_context)
-  build_context(preformatted_classes)
-  build_context(block_commands)
-#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);
-
-      if (!(flags & HMSF_formatting_context)
-          && flags & HMSF_top_formatting_context)
-        {
-          HTML_FORMATTING_CONTEXT *top_formatting_ctx
-         = html_top_formatting_context (&top_document_ctx->formatting_context);
-          SSize_t top_formatting_context_idx;
-          SV **top_formatting_context_sv;
-          HV *top_formatting_context_hv;
-
-          SV **formatting_context_sv = hv_fetch (top_document_context_hv,
-                                            "formatting_context",
-                                         strlen ("formatting_context"), 0);
-          formatting_context_av = (AV *) SvRV (*formatting_context_sv);
-          top_formatting_context_idx = av_top_index (formatting_context_av);
-          top_formatting_context_sv = av_fetch (formatting_context_av,
-                                          top_formatting_context_idx, 0);
-          top_formatting_context_hv = (HV *) SvRV (*top_formatting_context_sv);
-          build_html_formatting_context_ctx (top_formatting_context_hv,
-                                             top_formatting_ctx);
-        }
-    }
-
   if (flags & HMSF_multiple_pass)
     {
       SV **multiple_pass_sv;
diff --git a/tp/Texinfo/XS/convert/build_html_perl_state.h 
b/tp/Texinfo/XS/convert/build_html_perl_state.h
index 6d144ce8d9..c606d8574f 100644
--- a/tp/Texinfo/XS/convert/build_html_perl_state.h
+++ b/tp/Texinfo/XS/convert/build_html_perl_state.h
@@ -28,8 +28,6 @@ void pass_html_global_units_directions (SV *converter_sv,
 void pass_html_elements_in_file_count (SV *converter_sv,
                    FILE_NAME_PATH_COUNTER_LIST *output_unit_files);
 
-HV *build_html_document_context (HTML_DOCUMENT_CONTEXT *document_context);
-
 SV *build_html_formatting_state (CONVERTER *converter, unsigned long flags);
 
 SV *build_html_command_formatted_args
diff --git a/tp/Texinfo/XS/convert/convert_html.c 
b/tp/Texinfo/XS/convert/convert_html.c
index 73efa7d33c..0ebcf71d4f 100644
--- a/tp/Texinfo/XS/convert/convert_html.c
+++ b/tp/Texinfo/XS/convert/convert_html.c
@@ -505,7 +505,7 @@ html_pgdt_tree (const char *translation_context, const char 
*string,
 }
 
 int
-in_code (CONVERTER *self)
+html_in_code (CONVERTER *self)
 {
   HTML_DOCUMENT_CONTEXT *top_document_ctx;
   top_document_ctx = html_top_document_context (self);
@@ -513,7 +513,7 @@ in_code (CONVERTER *self)
 }
 
 int
-in_math (CONVERTER *self)
+html_in_math (CONVERTER *self)
 {
   HTML_DOCUMENT_CONTEXT *top_document_ctx;
   top_document_ctx = html_top_document_context (self);
@@ -521,7 +521,7 @@ in_math (CONVERTER *self)
 }
 
 int
-in_preformatted_context (CONVERTER *self)
+html_in_preformatted_context (CONVERTER *self)
 {
   HTML_DOCUMENT_CONTEXT *top_document_ctx;
   top_document_ctx = html_top_document_context (self);
@@ -529,7 +529,7 @@ in_preformatted_context (CONVERTER *self)
 }
 
 int
-inside_preformatted (CONVERTER *self)
+html_inside_preformatted (CONVERTER *self)
 {
   HTML_DOCUMENT_CONTEXT *top_document_ctx;
   top_document_ctx = html_top_document_context (self);
@@ -537,7 +537,7 @@ inside_preformatted (CONVERTER *self)
 }
 
 int
-in_non_breakable_space (CONVERTER *self)
+html_in_non_breakable_space (CONVERTER *self)
 {
   HTML_DOCUMENT_CONTEXT *top_document_ctx;
   HTML_FORMATTING_CONTEXT *top_formating_ctx;
@@ -548,7 +548,7 @@ in_non_breakable_space (CONVERTER *self)
 }
 
 int
-in_raw (CONVERTER *self)
+html_in_raw (CONVERTER *self)
 {
   HTML_DOCUMENT_CONTEXT *top_document_ctx;
   top_document_ctx = html_top_document_context (self);
@@ -556,7 +556,7 @@ in_raw (CONVERTER *self)
 }
 
 int
-in_space_protected (CONVERTER *self)
+html_in_space_protected (CONVERTER *self)
 {
   HTML_DOCUMENT_CONTEXT *top_document_ctx;
   HTML_FORMATTING_CONTEXT *top_formating_ctx;
@@ -567,14 +567,15 @@ in_space_protected (CONVERTER *self)
 }
 
 int
-in_string (CONVERTER *self)
+html_in_string (CONVERTER *self)
 {
   HTML_DOCUMENT_CONTEXT *top_document_ctx;
   top_document_ctx = html_top_document_context (self);
   return top_document_ctx->string_ctx;
 }
 
-int in_upper_case (CONVERTER *self)
+int
+html_in_upper_case (CONVERTER *self)
 {
   HTML_DOCUMENT_CONTEXT *top_document_ctx;
   HTML_FORMATTING_CONTEXT *top_formating_ctx;
@@ -585,13 +586,117 @@ int in_upper_case (CONVERTER *self)
 }
 
 int
-in_verbatim (CONVERTER *self)
+html_in_verbatim (CONVERTER *self)
 {
   HTML_DOCUMENT_CONTEXT *top_document_ctx;
   top_document_ctx = html_top_document_context (self);
   return top_document_ctx->verbatim_ctx;
 }
 
+int
+html_paragraph_number (CONVERTER *self)
+{
+  HTML_DOCUMENT_CONTEXT *top_document_ctx;
+  HTML_FORMATTING_CONTEXT *top_formating_ctx;
+  top_document_ctx = html_top_document_context (self);
+  top_formating_ctx
+    = html_top_formatting_context (&top_document_ctx->formatting_context);
+  return top_formating_ctx->paragraph_number;
+}
+
+int
+html_preformatted_number (CONVERTER *self)
+{
+  HTML_DOCUMENT_CONTEXT *top_document_ctx;
+  HTML_FORMATTING_CONTEXT *top_formating_ctx;
+  top_document_ctx = html_top_document_context (self);
+  top_formating_ctx
+    = html_top_formatting_context (&top_document_ctx->formatting_context);
+  return top_formating_ctx->preformatted_number;
+}
+
+enum command_id
+html_top_block_command (CONVERTER *self)
+{
+  HTML_DOCUMENT_CONTEXT *top_document_ctx;
+  top_document_ctx = html_top_document_context (self);
+  if (top_document_ctx->block_commands.top <= 0)
+    return 0;
+  return top_command (&top_document_ctx->block_commands);
+}
+
+STRING_STACK *
+html_preformatted_classes_stack (CONVERTER *self)
+{
+  HTML_DOCUMENT_CONTEXT *top_document_ctx;
+  top_document_ctx = html_top_document_context (self);
+  return &top_document_ctx->preformatted_classes;
+}
+
+enum command_id
+html_in_align (CONVERTER *self)
+{
+  HTML_DOCUMENT_CONTEXT *top_document_ctx;
+  COMMAND_OR_TYPE *context;
+  top_document_ctx = html_top_document_context (self);
+  context = top_command_or_type (&top_document_ctx->composition_context);
+  if (context->variety == CTV_type_command)
+    {
+      enum command_id cmd = context->cmd;
+      if (html_commands_data[cmd].flags & HF_HTML_align)
+        return cmd;
+    }
+  return 0;
+}
+
+void
+html_set_code_context (CONVERTER *self, int code)
+{
+  HTML_DOCUMENT_CONTEXT *top_document_ctx;
+  top_document_ctx = html_top_document_context (self);
+  push_integer_stack_integer (&top_document_ctx->monospace, code);
+}
+
+void
+html_pop_code_context (CONVERTER *self)
+{
+  HTML_DOCUMENT_CONTEXT *top_document_ctx;
+  top_document_ctx = html_top_document_context (self);
+  pop_integer_stack (&top_document_ctx->monospace);
+}
+
+void
+html_set_string_context (CONVERTER *self)
+{
+  HTML_DOCUMENT_CONTEXT *top_document_ctx;
+  top_document_ctx = html_top_document_context (self);
+  top_document_ctx->string_ctx++;
+}
+
+void
+html_unset_string_context (CONVERTER *self)
+{
+  HTML_DOCUMENT_CONTEXT *top_document_ctx;
+  top_document_ctx = html_top_document_context (self);
+  top_document_ctx->string_ctx--;
+}
+
+void
+html_set_raw_context (CONVERTER *self)
+{
+  HTML_DOCUMENT_CONTEXT *top_document_ctx;
+  top_document_ctx = html_top_document_context (self);
+  top_document_ctx->raw_ctx++;
+}
+
+void
+html_unset_raw_context (CONVERTER *self)
+{
+  HTML_DOCUMENT_CONTEXT *top_document_ctx;
+  top_document_ctx = html_top_document_context (self);
+  top_document_ctx->raw_ctx--;
+}
+
 size_t
 count_elements_in_filename (CONVERTER *self,
                  enum count_elements_in_filename_type type,
@@ -1851,7 +1956,7 @@ default_css_string_format_protect_text (const char *text, 
TEXT *result)
    conversion, with the possibility to add more for spaces protection */
 #define OTXI_ALL_CONVERT_TEXT(additional_delim,other_cases) \
   const char *p = content_used; \
-      if (in_code (self) || in_math (self)) \
+      if (html_in_code (self) || html_in_math (self)) \
         OTXI_CONVERT_TEXT(additional_delim,  \
           other_cases) \
       else if (self->use_unicode_text) \
@@ -1960,9 +2065,6 @@ html_new_document_context (CONVERTER *self,
   HTML_DOCUMENT_CONTEXT_STACK *stack = &self->html_document_context;
   HTML_DOCUMENT_CONTEXT *doc_context;
 
-  self->modified_state |= HMSF_document_context;
-  self->document_context_change++;
-
   if (stack->top >= stack->space)
     {
       stack->stack
@@ -2002,13 +2104,6 @@ html_pop_document_context (CONVERTER *self)
   if (stack->top == 0)
     fatal ("HTML document context stack empty for pop");
 
-  self->modified_state |= HMSF_document_context;
-  self->document_context_change--;
-  /* set document_contexts_to_pop to the lowest level below last sync with
-     perl reached */
-  if (-self->document_context_change > self->document_contexts_to_pop)
-    self->document_contexts_to_pop = -self->document_context_change;
-
   document_ctx = &stack->stack[stack->top -1];
 
   free (document_ctx->context);
@@ -3746,18 +3841,18 @@ convert_text (CONVERTER *self, const enum element_type 
type,
   char *content_used;
   int contents_used_to_be_freed = 0;
 
-  if (in_verbatim (self))
+  if (html_in_verbatim (self))
     {
       html_default_format_protect_text (content, result);
       return;
     }
-  else if (in_raw (self))
+  else if (html_in_raw (self))
     {
       text_append (result, content);
       return;
     }
 
-  if (in_upper_case (self))
+  if (html_in_upper_case (self))
     {
       content_used = to_upper_or_lower_multibyte (content, 1);
       contents_used_to_be_freed = 1;
@@ -3766,15 +3861,15 @@ convert_text (CONVERTER *self, const enum element_type 
type,
     /* cast needed to avoid a compiler warning */
     content_used = (char *) content;
 
-  if (in_preformatted_context (self))
+  if (html_in_preformatted_context (self))
     {
       OTXI_ALL_CONVERT_TEXT ( , )
     }
-  else if (in_non_breakable_space (self))
+  else if (html_in_non_breakable_space (self))
     {
       OTXI_ALL_CONVERT_TEXT (" \n", OTXI_NO_BREAK_CASES(p))
     }
-  else if (in_space_protected (self))
+  else if (html_in_space_protected (self))
     {
       OTXI_ALL_CONVERT_TEXT (" \n", OTXI_SPACE_PROTECTION_CASES(p))
     }
@@ -3903,7 +3998,7 @@ convert_row_type (CONVERTER *self, const enum 
element_type type,
                   const ELEMENT *element, const char *content,
                   TEXT *result)
 {
-  if (in_string (self))
+  if (html_in_string (self))
     {
       if (content)
         text_append (result, content);
@@ -3936,7 +4031,7 @@ convert_w_command (CONVERTER *self, const enum command_id 
cmd,
         text_append (result,
                      args_formatted->args[0].formatted[AFT_type_normal]);
     }
-  if (!in_string (self))
+  if (!html_in_string (self))
     {
       text_append (result, "<!-- /@w -->");
     }
@@ -4025,7 +4120,7 @@ convert_unit_type (CONVERTER *self, const enum 
output_unit_type unit_type,
   ELEMENT *unit_command;
   char *formatted_footer;
 
-  if (in_string (self))
+  if (html_in_string (self))
     return;
 
   if (!output_unit->tree_unit_directions[D_prev])
@@ -4102,7 +4197,7 @@ convert_special_unit_type (CONVERTER *self,
   char *formatted_footer;
   char *formatted_heading;
 
-  if (in_string (self))
+  if (html_in_string (self))
     return;
 
   special_unit_variety = output_unit->special_unit_variety;
@@ -4853,12 +4948,6 @@ html_check_transfer_state_finalization (CONVERTER *self)
         fprintf (stderr, "BUG: tree_to_build: %zu\n",
                          self->tree_to_build.number);
        */
-      if (self->document_context_change)
-        fprintf (stderr, "BUG: document_context_change: %d\n",
-                         self->document_context_change);
-      if (self->document_contexts_to_pop)
-        fprintf (stderr, "BUG: document_contexts_to_pop: %d\n",
-                         self->document_contexts_to_pop);
       if (self->no_arg_formatted_cmd_translated.number)
         fprintf (stderr, "BUG: no_arg_formatted_cmd_translated: %zu\n",
                          self->no_arg_formatted_cmd_translated.number);
@@ -5319,7 +5408,6 @@ html_open_command_update_context (CONVERTER *self, enum 
command_id data_cmd)
                  &top_document_ctx->formatting_context,
                  context_str);
       free (context_str);
-      self->modified_state |= HMSF_formatting_context;
     }
 
   top_formating_ctx
@@ -5328,14 +5416,12 @@ html_open_command_update_context (CONVERTER *self, enum 
command_id data_cmd)
   if (builtin_command_data[data_cmd].flags & CF_block)
     {
       push_command (&top_document_ctx->block_commands, data_cmd);
-      self->modified_state |= HMSF_block_commands;
     }
 
   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;
@@ -5352,53 +5438,44 @@ html_open_command_update_context (CONVERTER *self, enum 
command_id data_cmd)
                             data_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)
     {
       top_document_ctx->raw_ctx++;
-      self->modified_state |= HMSF_top_document_ctx;
     }
   else if (data_cmd == CM_verbatim)
     {
       top_document_ctx->verbatim_ctx++;
-      self->modified_state |= HMSF_top_document_ctx;
     }
 
   if (builtin_command_data[data_cmd].other_flags & CF_brace_code
       || builtin_command_data[data_cmd].flags & CF_preformatted_code)
     {
       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_integer_stack_integer (&top_document_ctx->monospace, 0);
-      self->modified_state |= HMSF_monospace;
     }
   else if (self->upper_case[data_cmd])
     {
       top_formating_ctx->upper_case_ctx++;
-      self->modified_state |= HMSF_top_formatting_context;
     }
   else if (builtin_command_data[data_cmd].flags & CF_math)
     {
       top_document_ctx->math_ctx++;
-      self->modified_state |= HMSF_top_document_ctx;
       if (self->conf->CONVERT_TO_LATEX_IN_MATH > 0)
         convert_to_latex = 1;
     }
   if (data_cmd == CM_verb)
     {
       top_formating_ctx->space_protected++;
-      self->modified_state |= HMSF_top_formatting_context;
     }
   else if (data_cmd == CM_w)
     {
       top_formating_ctx->no_break++;
-      self->modified_state |= HMSF_top_formatting_context;
     }
   return convert_to_latex;
 }
@@ -5418,7 +5495,6 @@ html_convert_command_update_context (CONVERTER *self, 
enum command_id data_cmd)
     {
       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)
@@ -5426,18 +5502,15 @@ html_convert_command_update_context (CONVERTER *self, 
enum command_id data_cmd)
       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;
     }
 
   if (data_cmd == CM_verb)
     {
       top_formating_ctx->space_protected--;
-      self->modified_state |= HMSF_top_formatting_context;
     }
   else if (data_cmd == CM_w)
     {
       top_formating_ctx->no_break--;
-      self->modified_state |= HMSF_top_formatting_context;
     }
 
   if (builtin_command_data[data_cmd].flags & CF_preformatted_code
@@ -5446,41 +5519,34 @@ html_convert_command_update_context (CONVERTER *self, 
enum command_id data_cmd)
       || builtin_command_data[data_cmd].other_flags & CF_brace_code)
     {
       pop_integer_stack (&top_document_ctx->monospace);
-      self->modified_state |= HMSF_monospace;
     }
   else if (self->upper_case[data_cmd])
     {
       top_formating_ctx->upper_case_ctx--;
-      self->modified_state |= HMSF_top_formatting_context;
     }
   else if (builtin_command_data[data_cmd].flags & CF_math)
     {
       top_document_ctx->math_ctx--;
-      self->modified_state |= HMSF_top_document_ctx;
     }
 
   if (html_commands_data[data_cmd].flags & HF_format_raw)
     {
       top_document_ctx->raw_ctx--;
-      self->modified_state |= HMSF_top_document_ctx;
     }
   else if (data_cmd == CM_verbatim)
     {
       top_document_ctx->verbatim_ctx--;
-      self->modified_state |= HMSF_top_document_ctx;
     }
 
   if (builtin_command_data[data_cmd].flags & CF_block)
     {
       pop_command (&top_document_ctx->block_commands);
-      self->modified_state |= HMSF_block_commands;
     }
 
   if (html_commands_data[data_cmd].flags & HF_format_context)
     {
       pop_html_formatting_context (
                  &top_document_ctx->formatting_context);
-      self->modified_state |= HMSF_formatting_context;
     }
 
   if (builtin_command_data[data_cmd].flags & CF_brace
@@ -5500,12 +5566,10 @@ html_open_type_update_context (CONVERTER *self, enum 
element_type type)
   if (type == ET_paragraph)
     {
       top_formating_ctx->paragraph_number++;
-      self->modified_state |= HMSF_top_formatting_context;
     }
   else if (type == ET_preformatted || type == ET_rawpreformatted)
     {
       top_formating_ctx->preformatted_number++;
-      self->modified_state |= HMSF_top_formatting_context;
     }
   else if (self->pre_class_types[type])
     {
@@ -5514,20 +5578,16 @@ html_open_type_update_context (CONVERTER *self, enum 
element_type 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_integer_stack_integer (&top_document_ctx->monospace, 1);
-      self->modified_state |= HMSF_monospace;
     }
 
   if (type == ET__string)
     {
       top_document_ctx->string_ctx++;
-      self->modified_state |= HMSF_top_document_ctx;
     }
 }
 
@@ -5539,13 +5599,11 @@ html_convert_type_update_context (CONVERTER *self, enum 
element_type type)
   if (self->code_types[type])
     {
       pop_integer_stack (&top_document_ctx->monospace);
-      self->modified_state |= HMSF_monospace;
     }
 
   if (type == ET__string)
     {
       top_document_ctx->string_ctx--;
-      self->modified_state |= HMSF_top_document_ctx;
     }
 
   if (self->pre_class_types[type])
@@ -5553,14 +5611,12 @@ html_convert_type_update_context (CONVERTER *self, enum 
element_type type)
       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;
     }
 }
 
 #define ADD(x) text_append (result, x)
 
-static char *
+char *
 debug_print_html_contexts (CONVERTER *self)
 {
   int i;
@@ -5600,6 +5656,17 @@ debug_print_html_contexts (CONVERTER *self)
 
     }
   text_append (&contexts_str, ")");
+   /*
+  text_append (&contexts_str, "{");
+  for (i = 0; i < top_document_ctx->block_commands.top; i++)
+    {
+      enum command_id cmd = top_document_ctx->block_commands.stack[i];
+      if (i != 0)
+        text_append (&contexts_str, "|");
+      text_append (&contexts_str, builtin_command_name (cmd));
+    }
+  text_append (&contexts_str, "}");
+    */
   return contexts_str.text;
 }
 
@@ -5862,13 +5929,11 @@ convert_to_html_internal (CONVERTER *self, const 
ELEMENT *element,
                                                    command_type.text, arg_idx);
                           push_integer_stack_integer (
                                           &top_document_ctx->monospace, 1);
-                          self->modified_state |= HMSF_monospace;
 
                           convert_to_html_internal (self, arg, &formatted_arg,
                                                     explanation);
                           pop_integer_stack
                               (&top_document_ctx->monospace);
-                          self->modified_state |= HMSF_monospace;
 
                           free (explanation);
                           arg_formatted->formatted[AFT_type_monospace]
@@ -5967,7 +6032,6 @@ convert_to_html_internal (CONVERTER *self, const ELEMENT 
*element,
                             = html_top_document_context (self);
                           text_reset (&formatted_arg);
                           top_document_ctx->raw_ctx++;
-                          self->modified_state |= HMSF_top_document_ctx;
                           xasprintf (&explanation, "%s A[%d]raw",
                                                    command_type.text, arg_idx);
                           convert_to_html_internal (self, arg, &formatted_arg,
@@ -5975,7 +6039,6 @@ convert_to_html_internal (CONVERTER *self, const ELEMENT 
*element,
 
                           free (explanation);
                           top_document_ctx->raw_ctx--;
-                          self->modified_state |= HMSF_top_document_ctx;
                           arg_formatted->formatted[AFT_type_raw]
                             = strdup (formatted_arg.text);
                         }
diff --git a/tp/Texinfo/XS/convert/convert_html.h 
b/tp/Texinfo/XS/convert/convert_html.h
index 8f1a5eacbb..950c61a086 100644
--- a/tp/Texinfo/XS/convert/convert_html.h
+++ b/tp/Texinfo/XS/convert/convert_html.h
@@ -2,6 +2,8 @@
 #ifndef CONVERT_HTML_H
 #define CONVERT_HTML_H
 
+#include "command_ids.h"
+#include "element_types.h"
 #include "converter_types.h"
 /* for FILE_SOURCE_INFO_LIST */
 #include "utils.h"
@@ -23,10 +25,41 @@ void html_finalize_output_state (CONVERTER *self);
 
 void html_converter_prepare_output (CONVERTER* self);
 
+int html_open_command_update_context (CONVERTER *self,
+                                      enum command_id data_cmd);
+void html_convert_command_update_context (CONVERTER *self,
+                                          enum command_id data_cmd);
+void html_open_type_update_context (CONVERTER *self,
+                                    enum element_type type);
+void html_convert_type_update_context (CONVERTER *self, enum element_type 
type);
 void html_new_document_context (CONVERTER *self,
         char *context_name, char *document_global_context,
         enum command_id block_command);
 void html_pop_document_context (CONVERTER *self);
+void html_set_code_context (CONVERTER *self, int code);
+void html_pop_code_context (CONVERTER *self);
+void html_set_string_context (CONVERTER *self);
+void html_unset_string_context (CONVERTER *self);
+void html_set_raw_context (CONVERTER *self);
+void html_unset_raw_context (CONVERTER *self);
+
+int html_in_math (CONVERTER *self);
+int html_in_preformatted_context (CONVERTER *self);
+int html_inside_preformatted (CONVERTER *self);
+int html_in_upper_case (CONVERTER *self);
+int html_in_non_breakable_space (CONVERTER *self);
+int html_in_space_protected (CONVERTER *self);
+int html_in_code (CONVERTER *self);
+int html_in_string (CONVERTER *self);
+int html_in_verbatim (CONVERTER *self);
+int html_in_raw (CONVERTER *self);
+int html_paragraph_number (CONVERTER *self);
+int html_preformatted_number (CONVERTER *self);
+enum command_id html_top_block_command (CONVERTER *self);
+STRING_STACK *html_preformatted_classes_stack (CONVERTER *self);
+enum command_id html_in_align (CONVERTER *self);
+
+char *debug_print_html_contexts (CONVERTER *self);
 
 void html_register_opened_section_level (CONVERTER *self, int level,
                                          const char *close_string);
diff --git a/tp/Texinfo/XS/main/converter_types.h 
b/tp/Texinfo/XS/main/converter_types.h
index 97f4882588..949a006e58 100644
--- a/tp/Texinfo/XS/main/converter_types.h
+++ b/tp/Texinfo/XS/main/converter_types.h
@@ -651,10 +651,6 @@ typedef struct CONVERTER {
                                            change */
     ARRAY_INDEX_LIST file_changed_counter;  /* index of files in
                                  output_unit_files with changed counter */
-    int document_context_change; /* change of document context top that may 
need
-                                    to be brought to perl */
-    int document_contexts_to_pop;  /* number of contexts to pop in perl before
-                                      readding the new contexts */
     HTML_ADDED_TARGET_LIST added_targets; /* targets added */
     /* next three allow to switch from normal HTML formatting to css strings
        formatting */
diff --git a/tp/Texinfo/XS/main/utils.h b/tp/Texinfo/XS/main/utils.h
index 9fd8f61f7c..16a067dac5 100644
--- a/tp/Texinfo/XS/main/utils.h
+++ b/tp/Texinfo/XS/main/utils.h
@@ -131,15 +131,16 @@ enum command_location {
 
 /* HTML modified state flags */
 #define HMSF_current_root            0x0001
-#define HMSF_document_context        0x0002
-#define HMSF_formatting_context      0x0004
-#define HMSF_composition_context     0x0008
-#define HMSF_preformatted_classes    0x0010
-#define HMSF_block_commands          0x0020
-#define HMSF_monospace               0x0040
-#define HMSF_top_formatting_context  0x0080
-/* for the integer variables in top document context */
-#define HMSF_top_document_ctx        0x0100
+/*
+#define HMSF_        0x0002
+#define HMSF_      0x0004
+#define HMSF_     0x0008
+#define HMSF_    0x0010
+#define HMSF_          0x0020
+#define HMSF_               0x0040
+#define HMSF_  0x0080
+#define HMSF_        0x0100
+ */
 #define HMSF_current_node            0x0200
 #define HMSF_current_output_unit     0x0400
 #define HMSF_current_filename        0x0800
diff --git a/tp/ext/highlight_syntax.pm b/tp/ext/highlight_syntax.pm
index c0a56df8e4..d5204a1eda 100644
--- a/tp/ext/highlight_syntax.pm
+++ b/tp/ext/highlight_syntax.pm
@@ -614,7 +614,8 @@ sub highlight_preformatted_command($$$$$)
         # _preformatted_class().
         # Since we are formatting @example itself, it is not in the 
preformatted
         # context anymore, so we readd.
-        my @pre_classes = $self->preformatted_classes_stack();
+        my $preformatted_classes_stack = $self->preformatted_classes_stack();
+        my @pre_classes = @{$preformatted_classes_stack};
         # NOTE $pre_class_format is setup below to correspond to
         # $pre_class_commands{$cmdname}, which cannot be used directly,
         # as it is private.



reply via email to

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