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)