On Thu, Feb 11, 2021 at 07:03:17AM -0800, Per Bothner wrote: > > The big problem I have is understanding the "global" structure (as opposed to > making local changes in the code) in that the logical nested sectioning > structure > is not reflected. For that. we'd need to generate a <div class="section"> > before processing a section node, and defer the closing </div> until after > we'd > processed not only the section node, but also all of its subsections. > > Figuring out how to do that correctly is difficult, since one has to > understand > both the parse tree structure and the control flow. For example, is the > sectioning structure reflected in the tree, or does it have to be inferred?
The sectioning structure is not reflected in the tree structure but the local sectioning structure is available from the sectioning elements in the tree, such as @chapter, with section_childs, section_up, section_prev... as explained in tp/Texinfo/Structuring.pm documentation of sectioning_structure(). In any case, the way the tree is setup right now never follows the imbrication of the sectioning tree. Conversion is always processed going through each sectioning element linearly as they appear in the document. This does not prevent reconstituting the nested sectioning structure. This is done in Convert/DocBook.pm. The elements are opened rather normally (around l 690), but they are closed only when they do not have next element and close parents in the tree. Starting l 1142 there is the code that closes the nested sectioning tree elements. > There are other problems with my patch (some unneeded elements; "node" div > before "section" div), but those are "local" changes that I assume will be > relatively easy once we have the proper nesting. > > I.e. if someone can show me how to generate elements like > <div class="section" id=="xxyy">...</div> so it wraps the entire section > (title, header links, node contents *and* its sub-sections), then > I can probably figure out the rest. I hope to have answered that... > -- > --Per Bothner > [email protected] http://per.bothner.com/ > diff --git a/tp/Texinfo/Convert/HTML.pm b/tp/Texinfo/Convert/HTML.pm > index 443b6b4702..7f08be66b4 100644 > --- a/tp/Texinfo/Convert/HTML.pm > +++ b/tp/Texinfo/Convert/HTML.pm > @@ -2420,8 +2420,10 @@ sub _convert_heading_command($$$$$) > } > > my $element_id = $self->command_id($command); > - $result .= "<span id=\"$element_id\"></span>" > - if (defined($element_id) and $element_id ne ''); > + $result .= '<div class="convert-heading-' . $cmdname . '"'; > + $result .= " id=\"$element_id\"" > + if (defined($element_id) and $element_id ne ''); > + $result .= ">\n"; > > print STDERR "Process $command " > .Texinfo::Structuring::_print_root_command_texi($command)."\n" > @@ -2515,7 +2517,7 @@ sub _convert_heading_command($$$$$) > $result .= _mini_toc($self, $command); > } > > - return $result; > + return $result . '</div>'; > } > > foreach my $command (keys(%sectioning_commands), 'node') { > @@ -4657,14 +4659,14 @@ sub _convert_element_type($$$$) > } > } > > - my $result = ''; > + my $result = "<div class=\"node\">\n"; > my $special_element; > > 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"; > + $result = "<div class=\"node\" id=\"$id\">\n"; > } > if ($self->get_conf('HEADERS') > # first in page > @@ -4691,19 +4693,19 @@ 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); > $result .= &{$self->{'format_element_footer'}}($self, $type, > $element, $content); > - return $result; > + return $result . "</div>"; > } > > sub _default_element_footer($$$$)
