bug-texinfo
[Top][All Lists]
Advanced

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

Re: html structure revisited


From: Patrice Dumas
Subject: Re: html structure revisited
Date: Sat, 13 Feb 2021 17:59:52 +0100

On Fri, Feb 12, 2021 at 01:51:42PM -0800, Per Bothner wrote:
> How about this (attached) patch.
> 
> I've tried --no-split, --split=node, --split=chapter, and --split=section;
> the latter both with and without js-info.
> 
> I have not tested @part or @raisesections/@lowersections.
> 
> I suspect this approach may be more efficent than that used by the DocBook
> back-end.  It could probably be modified for the latter by changing:
>     push(@{$self->{'pending_closes'}}, "</div>\n");
> to the appropriate closing tag.

Overall looks ok, and probably makes sense to have the sectioning
structure tree available at best as possible.

There is an issue, though, that is not so easy to handle.  In general,
it is better to avoid "side effects" in formatting functions that can be 
customized, such that it is easy to modify only one function.

Here, whether it is with an explicit structure as you do, or implicitly 
by having  elements opened but not closed, it is unavoidable to have
some interactions among formatting functions that can be customized.
The question is then, how best to setup the information such that it is
as easy as possible to do customization functions.

Also what I prefer to do is to avoid having customization function
directly using converter structures, but rather access through
functions.

I may not have done all that systematically, I am pretty sure that there
are functions that can be customized with side effects, and unclean
access to internal data, but I think that it is important to avoid that,
especially if other modify the HTML converter or do customization
functions.

Regarding your patch, my feeling is that the best is to have a function
to register opened sectioning commands, and another to ask for the
closing elements down to a given level.  Does it looks ok?

> -- 
>       --Per Bothner
> per@bothner.com   http://per.bothner.com/

> diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm
> index 443b6b4702..4b34aeecf2 100644
> --- a/tp/Texinfo/Convert/HTML.pm
> +++ b/tp/Texinfo/Convert/HTML.pm
> @@ -2419,9 +2419,27 @@ sub _convert_heading_command($$$$$)
>      return $result;
>    }
>  
> +  my $section = $command->{'extra'}->{'associated_section'};
> +  if ($section) {
> +      my $level = $section->{'level'};
> +      while (@{$self->{'pending_closes'}} > $level) {
> +          my $close = pop @{$self->{'pending_closes'}};
> +          $result .= $close if ($close);
> +      }
> +      while (@{$self->{'pending_closes'}} < $level) {
> +          push(@{$self->{'pending_closes'}}, "");
> +      }
> +  }
> +  $result .= '<div';
> +  if ($section) {
> +      $result .= ' class="'.$section->{'cmdname'}.'"';
> +      push(@{$self->{'pending_closes'}}, "</div>\n");
> +  } else {
> +      $result .= ' class="node"';
> +  }
>    my $element_id = $self->command_id($command);
> -  $result .= "<span id=\"$element_id\"></span>"
> -    if (defined($element_id) and $element_id ne '');
> +  $result .= " id=\"$element_id\""
> +      if (defined($element_id) and $element_id ne '');
>  
>    print STDERR "Process $command "
>          .Texinfo::Structuring::_print_root_command_texi($command)."\n"
> @@ -2433,6 +2451,7 @@ sub _convert_heading_command($$$$$)
>        and $command->{'parent'}->{'type'} eq 'element') {
>      $element = $command->{'parent'};
>    }
> +  $result .= ">\n";
>    if ($element) {
>      $result .= &{$self->{'format_element_header'}}($self, $cmdname, 
>                                              $command, $element);
> @@ -2514,7 +2533,7 @@ sub _convert_heading_command($$$$$)
>                         eq 'inline')))) {
>      $result .= _mini_toc($self, $command);
>    }
> -
> +  $result .= '</div>' if (! $section);
>    return $result;
>  }
>  
> @@ -4663,9 +4682,6 @@ sub _convert_element_type($$$$)
>    if ($element->{'extra'}->{'special_element'}) {
>      $special_element = $element->{'extra'}->{'special_element'};
>      my $id = $self->command_id($element);
> -    if ($id ne '') {
> -      $result .= "<span id=\"$id\"></span>\n";
> -    }
>      if ($self->get_conf('HEADERS') 
>          # first in page
>          or $self->{'counter_in_file'}->{$element->{'filename'}} == 1) {
> @@ -4691,13 +4707,13 @@ sub _convert_element_type($$$$)
>      if ($special_element_body eq '') {
>        return '';
>      }
> -    $result .= $special_element_body;
> +    $result .= $special_element_body . '</div>';
>    } elsif (!$element->{'element_prev'}) {
>      $result .= $self->_print_title();
>      if (!$element->{'element_next'}) {
>        # only one element
>        my $foot_text = &{$self->{'format_footnotes_text'}}($self);
> -      return 
> $result.$content.$foot_text.$self->get_conf('DEFAULT_RULE')."\n";
> +      return 
> $result.$content.$foot_text.$self->get_conf('DEFAULT_RULE')."</div>\n";
>      }
>    }
>    $result .= $content unless ($special_element);
> @@ -5127,6 +5143,7 @@ sub converter_initialize($)
>  
>    $self->{'document_context'} = [];
>    $self->{'multiple_pass'} = [];
> +  $self->{'pending_closes'} = [];
>    $self->_new_document_context('_toplevel_context');
>  
>    if ($self->get_conf('SPLIT') and $self->get_conf('SPLIT') ne 'chapter'
> @@ -6495,9 +6512,13 @@ sub _default_end_file($)
>  {
>    my $self = shift;
>    my $program_text = '';
> +  while (@{$self->{'pending_closes'}}) {
> +      my $close = pop @{$self->{'pending_closes'}};
> +      $program_text .= $close if ($close);
> +  }
>    if ($self->get_conf('PROGRAM_NAME_IN_FOOTER')) {
>      my $program_string = &{$self->{'format_program_string'}}($self);
> -    $program_text = "<p><font size=\"-1\">
> +    $program_text .= "<p><font size=\"-1\">
>    $program_string
>  </font></p>";
>    }




reply via email to

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