Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Position coincident page marks in the correct order #1274

Merged
merged 3 commits into from
Nov 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions src/lib/Guiguts/HTMLConvert.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1245,20 +1245,19 @@ sub html_convert_sidenotes {
sub html_convert_pageanchors {
my $textwindow = $::textwindow;
::working("Inserting Page Number Markup");
$|++;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this even do? (perl, you are weird)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also known as $OUTPUT_AUTOFLUSH it apparently forces immediate flushing on every write or print. I did wonder (given the relative infrequency that I would have thought it is needed) why someone though it necessary to have $| as a short version of the full variable name. At the bottom of the docs, it had this explanation:

Mnemonic: when you want your pipes to be piping hot.

As you say, perl is weird 🤣

my @pagerefs; # keep track of first/last page markers at the same position
my $tempcounter;
my $mark = '1.0';
while ( $textwindow->markPrevious($mark) ) {
$mark = $textwindow->markPrevious($mark);
}

my $closure = voidclosure();

# Work through all the text markers
while ( $mark = $textwindow->markNext($mark) ) {
next unless $mark =~ m{Pg(\S+)}; # Only look at page markers
my $markindex = $textwindow->index($mark); # Get page marker's index
# Get a correctly sorted list of page markers - if two markers are at the
# same location, the order returned by markNext is not defined, but we need
# them ordered by png.
my @pagemarklist = sort grep ( /^Pg\S+$/, $textwindow->markNames );

for my $idx ( 0 .. $#pagemarklist ) {
my $mark = $pagemarklist[$idx];
my $markindex = $textwindow->index($mark); # Get page marker's index
my $marknext = $idx < $#pagemarklist ? $pagemarklist[ $idx + 1 ] : "";

# This is the custom page label
my $num = $::pagenumbers{$mark}{label};
Expand All @@ -1278,12 +1277,6 @@ sub html_convert_pageanchors {
push @pagerefs, $num;
}

# Find next page marker & its index
my $marknext = $mark;
while ( $marknext = $textwindow->markNext($marknext) ) {
last if $marknext =~ m{Pg(\S+)};
}

# If no more marks (reached end of file) or there are word characters between the
# current mark and the next, then convert batch of accumulated page markers to a string
my $pagereference = '';
Expand Down
Loading