1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC
6 # <sales@bestpractical.com>
8 # (Except where explicitly superseded by other copyright notices)
13 # This work is made available to you under the terms of Version 2 of
14 # the GNU General Public License. A copy of that license should have
15 # been provided with this software, but in any event can be snarfed
18 # This work is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 # 02110-1301 or visit their web page on the internet at
27 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
30 # CONTRIBUTION SUBMISSION POLICY:
32 # (The following paragraph is not intended to limit the rights granted
33 # to you to modify and distribute this software under the terms of
34 # the GNU General Public License and is only of importance to you if
35 # you choose to contribute your changes and enhancements to the
36 # community by submitting them to Best Practical Solutions, LLC.)
38 # By intentionally submitting any modifications, corrections or
39 # derivatives to this work, or any other work intended for use with
40 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 # you are the copyright holder for those contributions and you grant
42 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 # royalty-free, perpetual, license to use, copy, create derivative
44 # works based on those contributions, and sublicense and distribute
45 # those contributions and any derivatives thereof.
47 # END BPS TAGGED BLOCK }}}
52 package RT::Pod::HTML;
53 use base 'Pod::Simple::XHTML';
55 use HTML::Entities qw//;
57 __PACKAGE__->_accessorize(
62 my $self = shift->SUPER::new(@_);
64 $self->anchor_items(1);
70 return HTML::Entities::decode_entities($_[0]);
73 sub perldoc_url_prefix { "http://metacpan.org/module/" }
75 sub html_header { '' }
78 my $toc = "../" x ($self->batch_mode_current_level - 1);
79 return '<a href="./' . $toc . '">← Back to index</a>';
83 $_[0]{'scratch_F'} = $_[0]{'scratch'};
84 $_[0]{'scratch'} = "";
88 my $text = $self->{scratch};
89 my $file = $self->decode_entities($text);
91 if (my $local = $self->resolve_local_link($file)) {
92 $text = qq[<a href="$local">$text</a>];
95 $self->{'scratch'} = delete $self->{scratch_F};
96 $self->{'scratch'} .= "<i>$text</i>";
101 $self->{scratch} = '<a href="#___top">' . $self->{scratch} . '</a>';
102 return $self->SUPER::_end_head(@_);
105 sub resolve_pod_page_link {
107 my ($name, $section) = @_;
109 # Only try to resolve local links if we're in batch mode and are linking
110 # outside the current document.
111 return $self->SUPER::resolve_pod_page_link(@_)
112 unless $self->batch_mode and $name;
114 my $local = $self->resolve_local_link($name, $section);
118 : $self->SUPER::resolve_pod_page_link(@_);
121 sub resolve_local_link {
123 my ($name, $section) = @_;
125 $name .= ""; # stringify name, it may be an object
127 $section = defined $section
128 ? '#' . $self->idify($section, 1)
132 if ($name =~ /^RT(::(?!Extension::|Authen::)|$)/ or $self->batch->found($name)) {
134 map { $self->encode_entities($_) }
137 elsif ($name =~ /^rt([-_]|$)/) {
138 $local = $self->encode_entities($name);
140 elsif ($name =~ /^(\w+)_Config(\.pm)?$/) {
142 $local = "$1_Config";
144 elsif ($name eq 'README') {
145 # We process README separately in devel/tools/rt-static-docs
148 elsif ($name =~ /^UPGRADING.*/) {
149 # If an UPGRADING file is referred to anywhere else (such as
150 # templates.pod) we won't have seen UPGRADING yet and will treat
151 # it as a non-local file.
154 # These matches handle links that look like filenames, such as those we
155 # parse out of F<> tags.
156 elsif ( $name =~ m{^(?:lib/)(RT/[\w/]+?)\.pm$}
157 or $name =~ m{^(?:docs/)(.+?)\.pod$})
159 $name = join "::", split '/', $1;
161 map { $self->encode_entities($_) }
166 # Resolve links correctly by going up
167 my $found = $self->batch->found($name);
168 my $depth = $self->batch_mode_current_level
170 return ($depth ? "../" x $depth : "") . ($found ? "" : "rt/latest/") . "$local.html$section";
176 sub batch_mode_page_object_init {
177 my ($self, $batch, $module, $infile, $outfile, $depth) = @_;
178 $self->SUPER::batch_mode_page_object_init(@_[1..$#_]);
179 $self->batch( $batch );