On Tue, Jan 07, 2025 at 07:17:37PM +0000, Gavin Smith wrote: > If I understand correctly the issue is with the "Index" link that > is generated in the HTML output and that there is no way to configure > which index this refers to. > > This could be allowed with two options: > * One to suppress the default "Index" link > * Another to add a link to all pages to a certain node. This link > would be expressed in terms of node (e.g. "Concept Index"), not index > (e.g. "cp"). > > In July 2024, a user expressed a desire to add a "Top" link to > the navigation bar for all pages: > > > == Adding a "Top" navigation entry > > > > For a web page I find it useful to be able to easily go to the > > homepage. I'm manually changing the HTML to add a "Top" navigation entry > > that points to the index page. I experimented with several options but > > didn't get this effect. Is something like this possible, and if not, > > would it be a useful addition? > > Frederico Muñoz, 2024-07-17 > https://lists.gnu.org/archive/html/bug-texinfo/2024-07/msg00002.html > > This appears to be exactly the same problem. I think we should support > both links to pages in the Texinfo system as well as arbitrary URLs > in header links. > > It could be done with some option to texi2any, like > > texi2any --html "--nav-button=Index=Concept Index" > > I prefer to allow this kind of customization, especially for functionality > that is of a wide interest, through options or variables, rather than the > customization API, as the former would be easier for users and also less > likely to break.
It is always better indeed. But it also gets easily complicated to cater with all the possibilities. For this specific example, there should be two different options node/href, replacing an existing button or adding another with the same name should be distinguished, the user may want to have the button prepended or postpended, only for headers and not footers, only if split at nodes... Also, to do the same in the default case for global directions, you need to specify description, accesskey, rel... I think that it would be better to make it easier to do it with init files rather than try to have an interface for all the possibilities. It could be still possible to do an init file that does what you propose above, once done, the user would do texi2any --html --init add_nav_button.pm -c "CUST_ARG=Index=Concept Index" or something like that. A bit like tex4ht and similar and we could have libraries of init files. I think that it would be more extensible that way rather than try to have everything in the HTML converter. Also adding the url is very easy in init files, like my $button_string = '<a href="https://myhomepage.example.com/">Home</a>'; push @$buttons_list, \$button_string; -- Pat
use strict; use Texinfo::Convert::NodeNameNormalization; use Texinfo::Parser; my @buttons_specs = ('SECTION_BUTTONS', 'CHAPTER_BUTTONS', 'TOP_BUTTONS', 'CHAPTER_FOOTER_BUTTONS', 'SECTION_FOOTER_BUTTONS', 'NODE_FOOTER_BUTTONS', 'MISC_BUTTONS', 'TOP_FOOTER_BUTTONS', 'LINKS_BUTTONS'); my $node_name = 'General Index'; my $node_element; my $default_buttons; sub _node_button($) { my $self = shift; my $href = $self->command_href($node_element); return "<a href=\"$href\">Index</a>", 1; } sub _add_string_and_node_link_buttons { my ($self, $document, $stage) = @_; # gather default buttons if not already done. if (!defined($default_buttons)) { foreach my $buttons_spec (@buttons_specs) { $default_buttons->{$buttons_spec} = $self->get_conf($buttons_spec); } } my $parser = Texinfo::Parser::parser(); my $tree = $parser->parse_texi_line($node_name); my $normalized_node = Texinfo::Convert::NodeNameNormalization::convert_to_identifier($tree); $node_element = $self->label_command($normalized_node); if (!$node_element) { print STDERR "Could not find: $normalized_node\n"; } foreach my $buttons_spec (@buttons_specs) { my $buttons_list = [@{$default_buttons->{$buttons_spec}}]; if (defined($node_element)) { push @$buttons_list, \&_node_button; } my $button_string = '<a href="https://myhomepage.example.com/">Home</a>'; push @$buttons_list, \$button_string; $self->set_conf($buttons_spec, $buttons_list); } return 0; } texinfo_register_handler('structure', \&_add_string_and_node_link_buttons);