Skip to content

Commit

Permalink
fix links in generated HTML documentation
Browse files Browse the repository at this point in the history
Invoke installhtml in the right way for it to generate relative links.
Fix installhtml's code for creating relative links in the index for
split documents.  Update Pod::Html's section name transformer to
match the actual output seen via Pod::Simple::XHTML.  Incidentally
update split-on-head code for the new style of HTML generated by
Pod::Simple::XHTML.  Fixes [perl #110056].
  • Loading branch information
Zefram committed Dec 14, 2017
1 parent 59eb8be commit 0bd1c35
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 32 deletions.
1 change: 0 additions & 1 deletion Makefile.SH
Expand Up @@ -1204,7 +1204,6 @@ install.html: all installhtml
${LOCAL_PERL} installhtml \\
--podroot=. --podpath=. --recurse \\
--htmldir=\$(privlib)/html \\
--htmlroot=\$(privlib)/html \\
--splithead=pod/perlipc \\
--splititem=pod/perlfunc \\
--ignore=Porting/Maintainers.pm,Porting/pumpkin.pod,Porting/repository.pod \\
Expand Down
19 changes: 7 additions & 12 deletions ext/Pod-Html/lib/Pod/Html.pm
Expand Up @@ -5,7 +5,7 @@ require Exporter;
our $VERSION = 1.23;
our @ISA = qw(Exporter);
our @EXPORT = qw(pod2html htmlify);
our @EXPORT_OK = qw(anchorify);
our @EXPORT_OK = qw(anchorify relativize_url);

use Carp;
use Config;
Expand Down Expand Up @@ -661,19 +661,12 @@ sub html_escape {

#
# htmlify - converts a pod section specification to a suitable section
# specification for HTML. Note that we keep spaces and special characters
# except ", ? (Netscape problem) and the hyphen (writer's problem...).
# specification for HTML. We adopt the mechanism used by the formatter
# that we use.
#
sub htmlify {
my( $heading) = @_;
$heading =~ s/(\s+)/ /g;
$heading =~ s/\s+\Z//;
$heading =~ s/\A\s+//;
# The hyphen is a disgrace to the English language.
# $heading =~ s/[-"?]//g;
$heading =~ s/["?]//g;
$heading = lc( $heading );
return $heading;
return Pod::Simple::XHTML->can("idify")->(undef, $heading, 1);
}

#
Expand Down Expand Up @@ -801,7 +794,7 @@ sub resolve_pod_page_link {
# then $self->htmlroot eq '' (by definition of htmlfileurl) so
# $self->htmldir needs to be prepended to link to get the absolute path
# that will be relativized
$url = relativize_url(
$url = Pod::Html::relativize_url(
File::Spec::Unix->catdir(Pod::Html::_unixify($self->htmldir), $url),
$self->htmlfileurl # already unixified
);
Expand All @@ -810,6 +803,8 @@ sub resolve_pod_page_link {
return $url . ".html$section";
}

package Pod::Html;

#
# relativize_url - convert an absolute URL to one relative to a base URL.
# Assumes both end in a filename.
Expand Down
24 changes: 12 additions & 12 deletions ext/Pod-Html/t/anchorify.t
Expand Up @@ -23,18 +23,18 @@ foreach $i (0..$#poddata) {
$heads{anchorify($1)} = 1 if $poddata[$i] =~ /=head[1-6]\s+(.*)/;
}
my %expected = map { $_ => 1 } qw(
name
description
subroutine
error
method
has_a_wordspace
hastrailingwordspace
hasleadingwordspace
has_extra_internalwordspace
hasquotes
hasquestionmark
has_hyphen_and_space
NAME
DESCRIPTION
Subroutine
Error
Method
Has_A_Wordspace
HasTrailingWordspace
HasLeadingWordspace
Has_Extra_InternalWordspace
Has_Quotes
Has_QuestionMark
Has_Hyphen_And_Space
);
is_deeply(
\%heads,
Expand Down
14 changes: 7 additions & 7 deletions installhtml
Expand Up @@ -7,7 +7,7 @@ use Config; # for config options in the makefile
use File::Spec::Functions qw(rel2abs no_upwards);
use Getopt::Long; # for command-line parsing
use Cwd;
use Pod::Html 'anchorify';
use Pod::Html 1.23 qw(anchorify relativize_url);

=head1 NAME
Expand Down Expand Up @@ -240,10 +240,10 @@ foreach my $dir (@splithead) {
$/ = "";
my @data = ();
while (<H>) {
last if /name="name"/i;
last if m!<h1 id="NAME">NAME</h1>!;
$_ =~ s{href="#(.*)">}{
my $url = "$pod/$1.html" ;
$url = Pod::Html::relativize_url( $url, "$file.html" )
my $url = "$file/@{[anchorify(qq($1))]}.html" ;
$url = relativize_url( $url, "$file.html" )
if ( ! defined $Options{htmlroot} || $Options{htmlroot} eq '' );
"href=\"$url\">" ;
}egi;
Expand All @@ -254,7 +254,7 @@ foreach my $dir (@splithead) {
# now rewrite the file
open(H, '>', "$file.html") ||
die "$0: error opening $file.html for output: $!\n";
print H "@data", "\n";
print H @data, "</body>\n\n</html>\n\n\n";
close(H);
}

Expand Down Expand Up @@ -321,9 +321,9 @@ sub create_index {
m#<h1 id="NAME">NAME</h1>\s*<p>\s*(\S+)\s+-\s+(\S.*?\S)</p>#);
defined $lcp1 or die "$0: can't find NAME section in $dir/$file\n";

my $url= "$pod/$file" ;
my $url= "$dir/$file" ;
if ( ! defined $Options{htmlroot} || $Options{htmlroot} eq '' ) {
$url = Pod::Html::relativize_url( "$pod/$file", $html ) ;
$url = relativize_url( $url, $html ) ;
}

print HTML qq(<DT><A HREF="$url">);
Expand Down

0 comments on commit 0bd1c35

Please sign in to comment.