1package Text::Trac::P; 2use strict; 3use warnings; 4use base qw(Text::Trac::BlockNode); 5use Text::Trac::Text; 6 7our $VERSION = '0.24'; 8 9sub parse { 10 my ( $self, $l ) = @_; 11 my $c = $self->{context}; 12 13 if ( !@{ $c->in_block_of } or $c->in_block_of->[-1] ne 'p' ) { 14 $c->htmllines('<p>'); 15 push @{ $c->in_block_of }, 'p'; 16 } 17 18 # define block parsers called. 19 $self->block_nodes( [qw( blockquote hr )] ); 20 $self->block_parsers( $self->_get_parsers('block') ); 21 22 my $cite_depth = 0; 23 $c->unshiftline; 24 while ( $c->hasnext ) { 25 last if $c->nextline =~ /^$/; 26 $l = $c->shiftline; 27 last if $l =~ /^\s+$/; 28 29 my $blockquote_depth = 0; 30 for ( @{ $c->in_block_of } ) { 31 $blockquote_depth++ if $_ eq 'blockquote'; 32 } 33 34 if ( $l =~ /^(>+)/ ) { 35 $cite_depth = length $1; 36 if ( $blockquote_depth != $cite_depth ) { 37 $c->unshiftline; 38 last; 39 } 40 else { 41 $l =~ s/^>+//; 42 } 43 } 44 elsif ( $l !~ /^(?:>|\s+)/ and $blockquote_depth ) { 45 $c->htmllines('</p>'); 46 pop @{ $c->in_block_of }; 47 for ( 1 .. $blockquote_depth ) { 48 $c->htmllines('</blockquote>'); 49 pop @{ $c->in_block_of }; 50 } 51 52 $c->unshiftline; 53 last; 54 } 55 56 # parse other block nodes 57 my $parsers = $self->_get_matched_parsers( 'block', $l ); 58 if ( grep { ref($_) ne 'Text::Trac::P' } @{$parsers} ) { 59 $c->htmllines('</p>'); 60 pop @{ $c->in_block_of }; 61 $c->unshiftline; 62 last; 63 } 64 65 # parse inline nodes 66 $l = $self->replace($l); 67 $c->htmllines($l); 68 } 69 70 if ( @{ $c->in_block_of } and $c->in_block_of->[-1] eq 'p' ) { 71 $c->htmllines('</p>'); 72 pop @{ $c->in_block_of }; 73 74 my $blockquote_depth = 0; 75 for ( @{ $c->in_block_of } ) { 76 $blockquote_depth++ if $_ eq 'blockquote'; 77 } 78 79 if ($cite_depth) { 80 for ( $blockquote_depth .. length $1 ) { 81 $c->htmllines('</blockquote>'); 82 pop @{ $c->in_block_of }; 83 } 84 } 85 } 86 87 return; 88} 89 901; 91