1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2013 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//;
58 my $self = shift->SUPER::new(@_);
60 $self->anchor_items(1);
66 return HTML::Entities::decode_entities($_[0]);
69 sub perldoc_url_prefix { "http://metacpan.org/module/" }
71 sub html_header { '' }
74 my $toc = "../" x ($self->batch_mode_current_level - 1);
75 return '<a href="./' . $toc . '">← Back to index</a>';
79 $_[0]{'scratch_F'} = $_[0]{'scratch'};
80 $_[0]{'scratch'} = "";
84 my $text = $self->{scratch};
85 my $file = $self->decode_entities($text);
87 if (my $local = $self->resolve_local_link($file)) {
88 $text = qq[<a href="$local">$text</a>];
91 $self->{'scratch'} = delete $self->{scratch_F};
92 $self->{'scratch'} .= "<i>$text</i>";
97 $self->{scratch} = '<a href="#___top">' . $self->{scratch} . '</a>';
98 return $self->SUPER::_end_head(@_);
101 sub resolve_pod_page_link {
103 my ($name, $section) = @_;
105 # Only try to resolve local links if we're in batch mode and are linking
106 # outside the current document.
107 return $self->SUPER::resolve_pod_page_link(@_)
108 unless $self->batch_mode and $name;
110 my $local = $self->resolve_local_link($name, $section);
114 : $self->SUPER::resolve_pod_page_link(@_);
117 sub resolve_local_link {
119 my ($name, $section) = @_;
121 $section = defined $section
122 ? '#' . $self->idify($section, 1)
126 if ($name =~ /^RT::/) {
128 map { $self->encode_entities($_) }
131 elsif ($name =~ /^rt[-_]/) {
132 $local = $self->encode_entities($name);
134 elsif ($name eq "RT_Config" or $name eq "RT_Config.pm") {
135 $local = "RT_Config";
137 # These matches handle links that look like filenames, such as those we
138 # parse out of F<> tags.
139 elsif ( $name =~ m{^(?:lib/)(RT/[\w/]+?)\.pm$}
140 or $name =~ m{^(?:docs/)(.+?)\.pod$})
143 map { $self->encode_entities($_) }
148 # Resolve links correctly by going up
149 my $depth = $self->batch_mode_current_level - 1;
150 return ($depth ? "../" x $depth : "") . "$local.html$section";