File Coverage

lib/Pod/PseudoPod/HTML.pm
Criterion Covered Total %
statement 156 162 96.3
branch 37 42 88.1
condition 1 2 50.0
subroutine 75 79 94.9
pod 3 73 4.1
total 272 358 75.9


\n\n" } '; $_[0]->emit() } ';
line stmt bran cond sub pod time code
1             package Pod::PseudoPod::HTML;
2 5     5   2943 use strict;
  5         9  
  5         213  
3 5     5   29 use vars qw( $VERSION );
  5         6  
  5         298  
4             $VERSION = '0.19';
5 5     5   28 use Carp ();
  5         9  
  5         100  
6 5     5   21 use base qw( Pod::PseudoPod );
  5         8  
  5         1490  
7              
8 5     5   2807 use HTML::Entities 'encode_entities';
  5         26954  
  5         11446  
9              
10             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11              
12             sub new {
13 64     64 1 34908 my $self = shift;
14 64         211 my $new = $self->SUPER::new(@_);
15 64   50     346 $new->{'output_fh'} ||= *STDOUT{IO};
16 64         188 $new->accept_targets( 'html', 'HTML' );
17 64         1131 $new->accept_targets_as_text( qw(author blockquote comment caution
18             editor epigraph example figure important listing literal note
19             production programlisting screen sidebar table tip warning) );
20              
21 64         4331 $new->nix_X_codes(1);
22 64         415 $new->nbsp_for_S(1);
23 64         315 $new->add_css_tags(0);
24 64         101 $new->add_body_tags(0);
25 64         139 $new->codes_in_verbatim(1);
26 64         283 $new->{'scratch'} = '';
27 64         490 return $new;
28             }
29              
30             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31              
32             sub handle_text {
33             # escape special characters in HTML (<, >, &, etc)
34 109 100   109 0 311 $_[0]{'scratch'} .= $_[0]{'in_verbatim'} ? encode_entities( $_[1] ) : $_[1]
35             }
36              
37 43     43 0 95 sub start_Para { $_[0]{'scratch'} .= '

' }

38 6     6 0 14 sub start_Verbatim { $_[0]{'scratch'} .= '
'; $_[0]{'in_verbatim'} = 1} 
  6         14  
39              
40 1     1 0 4 sub start_head0 { $_[0]{'scratch'} = '

' }

41 1     1 0 2 sub start_head1 { $_[0]{'scratch'} = '

' }

42 1     1 0 3 sub start_head2 { $_[0]{'scratch'} = '

' }

43 1     1 0 3 sub start_head3 { $_[0]{'scratch'} = '

' }

44 1     1 0 3 sub start_head4 { $_[0]{'scratch'} = '
' }
45              
46 2     2 0 4 sub start_item_bullet { $_[0]{'scratch'} .= '
  • ' }
  • 47 2     2 0 5 sub start_item_number { $_[0]{'scratch'} .= "
  • $_[1]{'number'}. " }
  • 48 2     2 0 4 sub start_item_text { $_[0]{'scratch'} .= '
  • ' }
  • 49              
    50 1     1 0 3 sub start_over_bullet { $_[0]{'scratch'} .= '
      '; $_[0]->emit() }
      1         2  
    51 1     1 0 3 sub start_over_text { $_[0]{'scratch'} .= '
      '; $_[0]->emit() }
      1         2  
    52 0     0 0 0 sub start_over_block { $_[0]{'scratch'} .= '
      '; $_[0]->emit() }
      0         0  
    53 1     1 0 2 sub start_over_number { $_[0]{'scratch'} .= '
      '; $_[0]->emit() }
      1         3  
    54              
    55 1     1 0 2 sub end_over_bullet { $_[0]{'scratch'} .= ''; $_[0]->emit('nowrap') }
      1         5  
    56 1     1 0 3 sub end_over_text { $_[0]{'scratch'} .= ''; $_[0]->emit('nowrap') }
      1         3  
    57 0     0 0 0 sub end_over_block { $_[0]{'scratch'} .= ''; $_[0]->emit('nowrap') }
      0         0  
    58 1     1 0 3 sub end_over_number { $_[0]{'scratch'} .= ''; $_[0]->emit('nowrap') }
      1         2  
    59              
    60             # . . . . . Now the actual formatters:
    61              
    62 43     43 0 65 sub end_Para { $_[0]{'scratch'} .= '

    '; $_[0]->emit() }
      43         79  
    63             sub end_Verbatim {
    64 6     6 0 15 $_[0]{'scratch'} .= '';
    65 6         9 $_[0]{'in_verbatim'} = 0;
    66 6         12 $_[0]->emit('nowrap');
    67             }
    68              
    69 1     1 0 2 sub end_head0 { $_[0]{'scratch'} .= ''; $_[0]->emit() }
      1         2  
    70 1     1 0 2 sub end_head1 { $_[0]{'scratch'} .= ''; $_[0]->emit() }
      1         2  
    71 1     1 0 2 sub end_head2 { $_[0]{'scratch'} .= ''; $_[0]->emit() }
      1         2  
    72 1     1 0 1 sub end_head3 { $_[0]{'scratch'} .= ''; $_[0]->emit() }
      1         3  
    73 1     1 0 2 sub end_head4 { $_[0]{'scratch'} .= ''; $_[0]->emit() }
      1         3  
    74              
    75 2     2 0 5 sub end_item_bullet { $_[0]{'scratch'} .= ''; $_[0]->emit() }
      2         5  
    76 2     2 0 3 sub end_item_number { $_[0]{'scratch'} .= ''; $_[0]->emit() }
      2         4  
    77 2     2 0 4 sub end_item_text { $_[0]->emit() }
    78              
    79             sub start_sidebar {
    80 3     3 0 6 my ($self, $flags) = @_;
    81 3 50       8 $self->{'scratch'} = $self->{'css_tags'} ? '
    82 3 100       6 if ($flags->{'title'}) {
    83 2         16 $self->{'scratch'} .= "\n

    " . $flags->{'title'} . "

    ";
    84             }
    85 3         8 $self->emit('nowrap');
    86             }
    87              
    88 3 50   3 0 5 sub end_sidebar { $_[0]{'scratch'} .= $_[0]->{'css_tags'} ? '' : ''; $_[0]->emit() }
      3         7  
    89              
    90             sub start_figure {
    91 3     3 0 5 my ($self, $flags) = @_;
    92 3         6 $self->{'in_figure'} = 1;
    93              
    94 3 100       10 $self->{'figure_title'} = $flags->{'title'} if $flags->{'title'};
    95             }
    96              
    97             sub end_figure {
    98 3     3 0 5 my ($self, $flags) = @_;
    99 3         5 $self->{'in_figure'} = 0;
    100              
    101 3 100       12 if ($self->{'figure_title'})
    102             {
    103 1         3 $self->{'scratch'} .= "

    " . $self->{'figure_title'} . "

    ";
    104 1         3 delete $self->{'figure_title'};
    105             }
    106              
    107 3         5 $self->emit('nowrap');
    108             }
    109              
    110             # This handles =begin and =for blocks of all kinds.
    111             sub start_for {
    112 18     18 0 30 my ($self, $flags) = @_;
    113 18 100       52 if ($self->{'css_tags'}) {
    114 2         6 $self->{'scratch'} .= '
    115 2 50       8 $self->{'scratch'} .= ' class="'.$flags->{'target'}.'"' if ($flags->{'target'});
    116 2         4 $self->{'scratch'} .= '>';
    117 2         6 $self->emit('nowrap');
    118             }
    119              
    120             }
    121             sub end_for {
    122 18     18 0 28 my ($self) = @_;
    123 18 100       49 if ($self->{'css_tags'}) {
    124 2         4 $self->{'scratch'} .= '';
    125 2         9 $self->emit('nowrap');
    126             }
    127             }
    128              
    129             sub start_table {
    130 7     7 0 13 my ($self, $flags) = @_;
    131 7 100       12 if ($flags->{'title'}) {
    132 2         5 $self->{'scratch'} .= "

    Table: " . $flags->{'title'} . "

    \n";
    133             }
    134 7         8 $self->{'scratch'} .= '';
    135 7         21 $self->emit('nowrap');
    136             }
    137              
    138 7     7 0 10 sub end_table { $_[0]{'scratch'} .= '
    '; $_[0]->emit('nowrap') }
      7         10  
    139              
    140 1     1 0 3 sub start_headrow { $_[0]{'in_headrow'} = 1 }
    141 1     1 0 3 sub start_bodyrows { $_[0]{'in_headrow'} = 0 }
    142              
    143 8     8 0 14 sub start_row { $_[0]{'scratch'} .= "
    144 8     8 0 10 sub end_row { $_[0]{'scratch'} .= '
      8         14  
    145              
    146 14 100   14 0 44 sub start_cell { $_[0]{'scratch'} .= $_[0]{'in_headrow'} ? '' : ''; }
    147             sub end_cell {
    148 14     14 0 13 my $self = shift;
    149 14 100       24 $self->{'scratch'} .= ($self->{'in_headrow'}) ? '' : '
    150 14         24 $self->emit('nowrap');
    151             }
    152              
    153             sub start_Document {
    154 61     61 0 89 my ($self) = @_;
    155 61 100       147 if ($self->{'body_tags'}) {
    156 2         5 $self->{'scratch'} .= "\n";
    157 2 100       5 $self->{'scratch'} .= "\n" if $self->{'css_tags'};
    158 2         4 $self->emit('nowrap');
    159             }
    160             }
    161             sub end_Document {
    162 61     61 0 89 my ($self) = @_;
    163 61 100       138 if ($self->{'body_tags'}) {
    164 2         3 $self->{'scratch'} .= "\n";
    165 2         6 $self->emit('nowrap');
    166             }
    167             }
    168              
    169             # Handling code tags
    170 1     1 0 2 sub start_A { $_[0]{'scratch'} .= ' 171 1     1 0 3 sub end_A { $_[0]{'scratch'} .= '">link' }
    172              
    173 3     3 0 7 sub start_B { $_[0]{'scratch'} .= '' }
    174 3     3 0 8 sub end_B { $_[0]{'scratch'} .= '' }
    175              
    176 1     1 0 2 sub start_C { $_[0]{'scratch'} .= '' }
    177 1     1 0 2 sub end_C { $_[0]{'scratch'} .= '' }
    178              
    179 0     0 0 0 sub start_E { $_[0]{'scratch'} .= '&' }
    180 0     0 0 0 sub end_E { $_[0]{'scratch'} .= ';' }
    181              
    182 4 100   4 0 15 sub start_F { $_[0]{'scratch'} .= ($_[0]{'in_figure'}) ? ' 183 4 100   4 0 14 sub end_F { $_[0]{'scratch'} .= ($_[0]{'in_figure'}) ? '">' : '' }
    184              
    185 1     1 0 3 sub start_G { $_[0]{'scratch'} .= '' }
    186 1     1 0 3 sub end_G { $_[0]{'scratch'} .= '' }
    187              
    188 1     1 0 3 sub start_H { $_[0]{'scratch'} .= '' }
    189 1     1 0 2 sub end_H { $_[0]{'scratch'} .= '' }
    190              
    191 1     1 0 3 sub start_I { $_[0]{'scratch'} .= '' }
    192 1     1 0 2 sub end_I { $_[0]{'scratch'} .= '' }
    193              
    194             sub start_N {
    195 2     2 0 4 my ($self) = @_;
    196 2 100       7 $self->{'scratch'} .= '' if ($self->{'css_tags'});
    197 2         4 $self->{'scratch'} .= ' (footnote: ';
    198             }
    199             sub end_N {
    200 2     2 0 4 my ($self) = @_;
    201 2         4 $self->{'scratch'} .= ')';
    202 2 100       6 $self->{'scratch'} .= '' if $self->{'css_tags'};
    203             }
    204              
    205 1     1 0 2 sub start_R { $_[0]{'scratch'} .= '' }
    206 1     1 0 2 sub end_R { $_[0]{'scratch'} .= '' }
    207              
    208 1 50   1 0 6 sub start_U { $_[0]{'scratch'} .= '' if $_[0]{'css_tags'} }
    209 1 50   1 0 5 sub end_U { $_[0]{'scratch'} .= '' if $_[0]{'css_tags'} }
    210              
    211 5     5 0 11 sub start_Z { $_[0]{'scratch'} .= ' 212 5     5 0 12 sub end_Z { $_[0]{'scratch'} .= '">' }
    213              
    214             sub emit {
    215 119     119 0 163 my($self, $nowrap) = @_;
    216 119         187 my $out = $self->{'scratch'} . "\n";
    217 119         113 print {$self->{'output_fh'}} $out, "\n";
      119         320  
    218 119         986 $self->{'scratch'} = '';
    219 119         222 return;
    220             }
    221              
    222             # Set additional options
    223              
    224 66     66 1 202 sub add_body_tags { $_[0]{'body_tags'} = $_[1] }
    225 70     70 1 325 sub add_css_tags { $_[0]{'css_tags'} = $_[1] }
    226              
    227             # bypass built-in E<> handling to preserve entity encoding
    228       20     sub _treat_Es {}
    229              
    230             1;
    231              
    232             __END__