Modify the POD to HTML conversion code to work on older Perls

This commit is contained in:
Andrew Johnson
2020-04-14 16:41:20 -05:00
parent a95635a018
commit 45cf2ea5ce
3 changed files with 40 additions and 22 deletions
+18 -2
View File
@@ -5,6 +5,20 @@ use warnings;
use base 'Pod::Simple::HTML';
sub encode_entities {
my ($self, $str) = @_;
my %entities = (
q{>} => 'gt',
q{<} => 'lt',
q{'} => '#39',
q{"} => 'quot',
q{&} => 'amp'
);
my $ents = join '', keys %entities;
$str =~ s/([$ents])/'&' . $entities{$1} . ';'/ge;
return $str;
}
# Translate L<link text|filename/Section name>
# into <a href="filename.html#Section-name">link text</a>
@@ -18,9 +32,11 @@ sub do_pod_link {
if ($link->tagname eq 'L' and $link->attr('type') eq 'pod') {
my $to = $link->attr('to');
my $section = $link->attr('section');
$section = $self->section_escape($section)
if defined $section and length($section .= ''); # (stringify)
$ret = $to ? "$to.html" : '';
$ret .= "#$section" if $section;
$ret = (defined $to and length $to) ? "$to.html" : '';
$ret .= "#$section" if defined $section and length $section;
}
else {
# all other links are generated by the parent class
+21 -2
View File
@@ -5,15 +5,34 @@ use warnings;
use base 'Pod::Simple::XHTML';
BEGIN {
if ($Pod::Simple::XHTML::VERSION < '3.16') {
# encode_entities() wasn't a method, add it
our *encode_entities = sub {
my ($self, $str) = @_;
my %entities = (
q{>} => 'gt',
q{<} => 'lt',
q{'} => '#39',
q{"} => 'quot',
q{&} => 'amp'
);
my $ents = join '', keys %entities;
$str =~ s/([$ents])/'&' . $entities{$1} . ';'/ge;
return $str;
}
}
}
# Translate L<link text|filename/Section name>
# into <a href="filename.html#Section-name">link text</a>
sub resolve_pod_page_link {
my ($self, $to, $section) = @_;
my $ret = $to ? "$to.html" : '';
my $ret = defined $to ? "$to.html" : '';
$ret .= '#' . $self->idify($self->encode_entities($section), 1)
if $section;
if defined $section;
return $ret;
}