~ubuntu-branches/ubuntu/trusty/libpod-simple-perl/trusty

« back to all changes in this revision

Viewing changes to lib/Pod/Simple/XHTML.pm

  • Committer: Package Import Robot
  • Author(s): gregor herrmann
  • Date: 2012-06-02 19:46:46 UTC
  • mfrom: (1.1.15)
  • Revision ID: package-import@ubuntu.com-20120602194646-snwch2m75wjvyua9
Tags: 3.22-1
* New upstream release.
* Remove patches, all applied upstream.
* Update years of packaging copyright.
* Add debian/NEWS mentioning a compatibility change.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
package Pod::Simple::XHTML;
46
46
use strict;
47
47
use vars qw( $VERSION @ISA $HAS_HTML_ENTITIES );
48
 
$VERSION = '3.20';
 
48
$VERSION = '3.22';
49
49
use Pod::Simple::Methody ();
50
50
@ISA = ('Pod::Simple::Methody');
51
51
 
151
151
A string containing all characters that should be encoded as HTML entities,
152
152
specified using the regular expression character class syntax (what you find
153
153
within brackets in regular expressions). This value will be passed as the
154
 
second argument to the C<encode_entities> function of L<HTML::Entities>. IF
 
154
second argument to the C<encode_entities> function of L<HTML::Entities>. If
155
155
L<HTML::Entities> is not installed, then any characters other than C<&<>"'>
156
156
will be encoded numerically.
157
157
 
251
251
  $new->man_url_prefix('http://man.he.net/man');
252
252
  $new->html_charset('ISO-8859-1');
253
253
  $new->nix_X_codes(1);
254
 
  $new->codes_in_verbatim(1);
255
254
  $new->{'scratch'} = '';
256
255
  $new->{'to_index'} = [];
257
256
  $new->{'output'} = [];
301
300
      my ($self, $text) = @_;
302
301
      if ($self->{'in_foo'}) {
303
302
          $self->{'scratch'} .= build_foo_html($text);
304
 
      } else {
305
 
          $self->{'scratch'} .= $text;
 
303
          return;
306
304
      }
 
305
      $self->SUPER::handle_text($text);
307
306
  }
308
307
 
 
308
=head2 handle_code
 
309
 
 
310
This method handles the body of text that is marked up to be code.
 
311
You might for instance override this to plug in a syntax highlighter.
 
312
The base implementation just escapes the text and wraps it in C<<< <code>...</code> >>>.
 
313
 
309
314
=head2 accept_targets_as_html
310
315
 
311
316
This method behaves like C<accept_targets_as_text>, but also marks the region
327
332
}
328
333
 
329
334
sub handle_text {
 
335
    if ($_[0]{'in_code'}) {
 
336
        return $_[0]->handle_code( $_[1] );
 
337
    }
330
338
    # escape special characters in HTML (<, >, &, etc)
331
339
    $_[0]{'scratch'} .= $_[0]->__in_literal_xhtml_region
332
340
                      ? $_[1]
333
341
                      : $_[0]->encode_entities( $_[1] );
334
342
}
335
343
 
 
344
sub handle_code {
 
345
    $_[0]{'scratch'} .= '<code>' . $_[0]->encode_entities( $_[1] ) . '</code>';
 
346
}
 
347
 
336
348
sub start_Para     { $_[0]{'scratch'} = '<p>' }
337
 
sub start_Verbatim { $_[0]{'scratch'} = '<pre><code>' }
 
349
sub start_Verbatim { $_[0]{'scratch'} = '<pre>'; $_[0]{'in_code'} = 1; }
338
350
 
339
351
sub start_head1 {  $_[0]{'in_head'} = 1 }
340
352
sub start_head2 {  $_[0]{'in_head'} = 2 }
397
409
 
398
410
sub end_Para     { $_[0]{'scratch'} .= '</p>'; $_[0]->emit }
399
411
sub end_Verbatim {
400
 
    $_[0]{'scratch'}     .= '</code></pre>';
 
412
    $_[0]{'scratch'} .= '</pre>';
 
413
    delete $_[0]{'in_code'};
401
414
    $_[0]->emit;
402
415
}
403
416
 
568
581
sub start_B { $_[0]{'scratch'} .= '<b>' }
569
582
sub end_B   { $_[0]{'scratch'} .= '</b>' }
570
583
 
571
 
sub start_C { $_[0]{'scratch'} .= '<code>' }
572
 
sub end_C   { $_[0]{'scratch'} .= '</code>' }
 
584
sub start_C { $_[0]{'in_code'} = 1; }
 
585
sub end_C   { delete $_[0]{'in_code'}; }
573
586
 
574
587
sub start_F { $_[0]{'scratch'} .= '<i>' }
575
588
sub end_F   { $_[0]{'scratch'} .= '</i>' }