help-texinfo
[Top][All Lists]
Advanced

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

Re: Struggling with a targeted [Contents] button


From: Patrice Dumas
Subject: Re: Struggling with a targeted [Contents] button
Date: Fri, 13 Sep 2024 19:33:40 +0200

On Fri, Sep 13, 2024 at 06:56:22PM +0200, Rudolf Adamkovič wrote:
> Hi,
> 
> [I have been fighting the problem below for 3+ hours.]
> 
> In my HTML export, I would like to have
> 
>   a navigation button that links the current node in TOC,
> 
> the way
> 
>   texinfo_set_from_init_file('TOC_LINKS', 'true');
> 
> does.
> 
> So far, I have the following:
> 
>   sub _my_experiment_button {
>       my ($self, $direction) = @_;
> 
>       # I SHOULD PROBABLY PASS IN SOME "COMMAND" ?!
>       my $href = $self->command_contents_href(1, 'contents');
>   
>       return ("<a href=\"$href\">Contents</a>", 1);
>   }
>   
>   my $experiment_button = ['This', \&_my_experiment_button];
>   my $section_buttons = [ ... <snip> ..., $experiment_button];
>   
>   texinfo_set_from_init_file('SECTION_BUTTONS', $section_buttons);
>   texinfo_set_from_init_file('SECTION_FOOTER_BUTTONS', $section_buttons);
> 
> The resulting [Contents] button
> 
>   links to the TOC file --- YAY! ---
> 
> but the link
> 
>   is missing the '#toc-...' anchor.
> 
> Any help would be *deeply* appreciated.

As you notice, you should pass a Texinfo tree command element.
Conveniently, this is the next argument of the button formatting
function.  However, I tested it and it is not enough if the element
passed to the button formatting function is a node element, in addition,
the associated sectionning command has to be found, which requires
knowing more about the Texinfo tree.  The extra keys are documented in
https://www.gnu.org/software/texinfo/manual/texi2any_internals/texi2any_internals.html#Texinfo_003a_003aParser-Extra-keys-specific-of-certain-_0040_002dcommands-or-containers

Here is what worked for me:

  sub _my_experiment_button {
      my ($self, $direction, $element) = @_;

      if ($element->{'extra'}->{'associated_section'}) {
        $element = $element->{'extra'}->{'associated_section'};
      }

      my $href = $self->command_contents_href($element, 'contents');

      return ("<a href=\"$href\">Contents</a>", 1);
  }



As a side note, what you do is a good idea.  Maybe I'll add it to the
book.pm example.

-- 
Pat



reply via email to

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