From 79643dc0faf86043d91bfbc047400b5dcbd818fc Mon Sep 17 00:00:00 2001 From: Joe Nahmias Date: Thu, 6 Jun 2024 12:31:56 -0400 Subject: [PATCH] fix: support non-word characters in link names for ePUB generation Closes: chromatic#249 Inspired by @sd43 in 2684d569f452e99440d1520e35d50fa0382d49e1 --- build/tools/build_epub.pl | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/build/tools/build_epub.pl b/build/tools/build_epub.pl index e12bb7f7..e199868c 100755 --- a/build/tools/build_epub.pl +++ b/build/tools/build_epub.pl @@ -21,6 +21,7 @@ my $anchors = get_anchors(@chapters); my $table_of_contents = []; my %entries; +my $link_pos; sub Pod::PseudoPod::HTML::begin_X { @@ -84,19 +85,22 @@ sub clean_name return 'i' . $name; } +sub Pod::PseudoPod::HTML::start_L +{ + my $self = shift; + $link_pos = length($self->{scratch}); +} + sub Pod::PseudoPod::HTML::end_L { my $self = shift; - if ($self->{scratch} =~ s/\b(\w+)$//) - { - my $link = $1; - die "Unknown link $link\n" unless exists $anchors->{$link}; - $self->{scratch} .= - '' - . $anchors->{$link}[1] . "($link)"; - } + my $link = substr($self->{scratch}, $link_pos); + + die "Unknown link $link\n" unless exists $anchors->{$link}; + + substr($self->{scratch}, $link_pos, length($link), + '" + . $anchors->{$link}[1] . ''); } for my $chapter (@chapters)