Modify the POD to HTML conversion code to work on older Perls
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -19,26 +19,9 @@ use EPICS::Readfile;
|
||||
|
||||
BEGIN {
|
||||
$::XHTML = eval "require EPICS::PodXHtml; 1";
|
||||
$::ENTITIES = eval "require HTML::Entities; 1";
|
||||
if (!$::XHTML) {
|
||||
require EPICS::PodHtml;
|
||||
}
|
||||
if (!$::ENTITIES) {
|
||||
my %entities = (
|
||||
q{>} => 'gt',
|
||||
q{<} => 'lt',
|
||||
q{'} => '#39',
|
||||
q{"} => 'quot',
|
||||
q{&} => 'amp',
|
||||
);
|
||||
|
||||
sub encode_entities {
|
||||
my $str = shift;
|
||||
my $ents = join '', keys %entities;
|
||||
$str =~ s/([ $ents ])/'&' . ($entities{$1} || sprintf '#x%X', ord $1) . ';'/xge;
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
use Pod::Usage;
|
||||
@@ -190,7 +173,7 @@ my $pod = join "\n", '=for html <div class="pod">', '',
|
||||
} $dbd->pod,
|
||||
'=for html </div>', '';
|
||||
|
||||
$podHtml->force_title(encode_entities($title));
|
||||
$podHtml->force_title($podHtml->encode_entities($title));
|
||||
$podHtml->perldoc_url_prefix('');
|
||||
$podHtml->perldoc_url_postfix('.html');
|
||||
$podHtml->output_fh($out);
|
||||
|
||||
Reference in New Issue
Block a user