[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Struggling with a targeted [Contents] button
From: |
Rudolf Adamkovič |
Subject: |
Re: Struggling with a targeted [Contents] button |
Date: |
Fri, 13 Sep 2024 23:21:00 +0200 |
Patrice Dumas <pertusus@free.fr> writes:
> As you notice, you should pass a Texinfo tree command element.
> Conveniently, this is the next argument of the button formatting
> function.
In missed even that. :)
> However, I tested it and it is not enough [...]
>
> Here is what worked for me: [...]
Thank you much, Patrice!
[It would have taken me close-to-forever to figure that out.]
> As a side note, what you do is a good idea. Maybe I'll add it to the
> book.pm example.
It makes the [Contents] button much more practical.
(Features like this make a documentation system great, IMO.)
P.S.
The amusing fact is that, while in-section [Contents] are better
targeting the appropriate section, the top-level [Contents] is better
without the default anchor, when 'CONTENTS_OUTPUT_LOCATION' is
'separate_element', to avoid unnecessary pre-scrolling.
So, I ended up with the following two buttons:
#####################
## CONTENTS BUTTON ##
#####################
# Like the default [Contents] button but
#
# does not pre-scroll to the "Table of Contents" heading,
#
# to avoid "jumping content" when
#
# 'CONTENTS_OUTPUT_LOCATION' is 'separate_element'.
my sub contents_button {
my ($self, $direction) = @_;
my $unit = $self->global_direction_unit($direction);
my $command = $unit->{'unit_command'};
my $href = $self->command_filename($command);
return ("[<a href=\"$href\">Contents</a>]", 1);
}
my $contents_button = ['Contents', \&contents_button];
########################
## IN-CONTENTS BUTTON ##
########################
# Like the default [Contents] button but
#
# pre-scrolls to the current section,
#
# to aid navigation.
my sub in_contents_button {
my ($self, undef, $element) = @_;
my $element = $element->{'extra'}->{'associated_section'};
my $href = $self->command_contents_href($element, 'contents');
return ("[<a href=\"$href\">Contents</a>]", 0);
}
my $in_contents_button = ['This', \&in_contents_button];
P.S. You made my day!
Rudy
--
“Those who cannot remember the past are condemned to repeat it.” ---
George Santayana, Life of Reason: Reason in Common Sense, 1905
Rudolf Adamkovič <rudolf@adamkovic.org> [he/him]
http://adamkovic.org