On Fri, Nov 01, 2019 at 02:12:37PM +0000, Gavin Smith wrote:
> I would like a way of having a menu in each HTML file that lists the
> section names of subordinate nodes. This would replace the menu that
> already exists which is generated from the @menu block in the source.
> I don't believe there is any way to do this currently with texi2any.
Should it be placed at the same place as the menu, or be right after the
command heading?
I attach an example that generates such a list right after the heading.
Something that looks strange is that the node names are used in the
navigation header, while the sections names are used in the list of
subordinate sections/nodes.
--
Pat
use strict;
set_from_init_file('SHOW_MENU', 0);
my $NO_BULLET_LIST_CLASS = 'no-bullet';
sub use_section_sub_toc_convert_heading_command($$$$$)
{
my $self = shift;
my $cmdname = shift;
my $command = shift;
my $args = shift;
my $content = shift;
my $result = '';
# not clear that it may really happen
if ($self->in_string) {
$result .= $self->command_string($command) ."\n" if ($cmdname ne 'node');
$result .= $content if (defined($content));
return $result;
}
my $element_id = $self->command_id($command);
$result .= "<a name=\"$element_id\"></a>\n"
if (defined($element_id) and $element_id ne '');
print STDERR "Process $command "
.Texinfo::Structuring::_print_root_command_texi($command)."\n"
if ($self->get_conf('DEBUG'));
my $element;
if ($Texinfo::Common::root_commands{$command->{'cmdname'}}
and $command->{'parent'}
and $command->{'parent'}->{'type'}
and $command->{'parent'}->{'type'} eq 'element') {
$element = $command->{'parent'};
}
if ($element) {
$result .= &{$self->{'format_element_header'}}($self, $cmdname,
$command, $element);
}
my $heading_level;
# FIXME this is done as in texi2html: node is used as heading if there
# is nothing else. Is it right?
if ($cmdname eq 'node') {
if (!$element or (!$element->{'extra'}->{'section'}
and $element->{'extra'}->{'node'}
and $element->{'extra'}->{'node'} eq $command
# bogus node may not have been normalized
and defined($command->{'extra'}->{'normalized'}))) {
if ($command->{'extra'}->{'normalized'} eq 'Top') {
$heading_level = 0;
} else {
$heading_level = 3;
}
}
} else {
$heading_level = $command->{'level'};
}
my $heading = $self->command_text($command);
# $heading not defined may happen if the command is a @node, for example
# if there is an error in the node.
if (defined($heading) and $heading ne '' and defined($heading_level)) {
if ($self->get_conf('TOC_LINKS')
and $Texinfo::Common::root_commands{$cmdname}
and $Texinfo::Common::sectioning_commands{$cmdname}) {
my $content_href = $self->command_contents_href($command, 'contents',
$self->{'current_filename'});
if ($content_href) {
$heading = "<a href=\"$content_href\">$heading</a>";
}
}
if ($self->in_preformatted()) {
$result .= '<strong>'.$heading.'</strong>'."\n";
} else {
# if the level was changed, set the command name right
if ($cmdname ne 'node'
and $heading_level ne $Texinfo::Common::command_structuring_level{$cmdname}) {
$cmdname
= $Texinfo::Common::level_to_structuring_command{$cmdname}->[$heading_level];
}
$result .= &{$self->{'format_heading_text'}}($self, $cmdname, $heading,
$heading_level, $command);
}
}
if ($command->{'section_childs'} and @{$command->{'section_childs'}}) {
# and $cmdname ne 'top') {
$result .= $self->_attribute_class('ul', $NO_BULLET_LIST_CLASS).">\n";
foreach my $section_child (@{$command->{'section_childs'}}) {
my $content_href = $self->command_href($section_child);
my $heading = $self->command_text($section_child);
if ($content_href) {
$result .= "<li> "."<a href=\"$content_href\">$heading</a>" . " </li>\n";
}
}
$result .= "</ul>\n";
}
$result .= $content if (defined($content));
return $result;
}
foreach my $command (keys(%Texinfo::Common::sectioning_commands), 'node') {
texinfo_register_command_formatting($command,
\&use_section_sub_toc_convert_heading_command);
}
1;