From: Zefram Date: Thu, 14 Dec 2017 02:27:28 +0000 (+0000) Subject: fix links in generated HTML documentation X-Git-Tag: v5.27.7~95 X-Git-Url: https://perl5.git.perl.org/perl5.git/commitdiff_plain/0bd1c35ee47dab181543ba366fe021122c591f65?ds=sidebyside fix links in generated HTML documentation 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]. --- diff --git a/Makefile.SH b/Makefile.SH index 7ddb23e..8569955 100755 --- a/Makefile.SH +++ b/Makefile.SH @@ -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 \\ diff --git a/ext/Pod-Html/lib/Pod/Html.pm b/ext/Pod-Html/lib/Pod/Html.pm index 8f7999b..4927a7c 100644 --- a/ext/Pod-Html/lib/Pod/Html.pm +++ b/ext/Pod-Html/lib/Pod/Html.pm @@ -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; @@ -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); } # @@ -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 ); @@ -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. diff --git a/ext/Pod-Html/t/anchorify.t b/ext/Pod-Html/t/anchorify.t index d7b1808..0677f9e 100644 --- a/ext/Pod-Html/t/anchorify.t +++ b/ext/Pod-Html/t/anchorify.t @@ -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, diff --git a/installhtml b/installhtml index 1b724c0..62e92fc 100644 --- a/installhtml +++ b/installhtml @@ -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 @@ -240,10 +240,10 @@ foreach my $dir (@splithead) { $/ = ""; my @data = (); while () { - last if /name="name"/i; + last if m!

NAME

!; $_ =~ 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; @@ -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, "\n\n\n\n\n"; close(H); } @@ -321,9 +321,9 @@ sub create_index { m#

NAME

\s*

\s*(\S+)\s+-\s+(\S.*?\S)

#); 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(
);