I think the code below will do what you want (semi-tested). But I'd have to booster pretty strongly against the perl solution. In this case you probably should do it with CSS. If the blockquote is truly a "quote," okay, but if you're only changing it for the formatting, you should format from without. Both solutions are below.
use strict; use HTML::TokeParser; use CGI qw( blockquote ); my $string = join '', <DATA>; my $string_ref = \$string; my $p = HTML::TokeParser->new( $string_ref ); my $html; my $last_end_tag; while ( my $token = $p->get_token ) { if ( $token->[0] =~ /[TCD]/ ) { $html .= $token->[1]; } elsif ( $token->[0] eq 'S' ) { if ( $token->[1] eq 'p' and $last_end_tag eq 'h4' ) { $html .= blockquote( $token->[2], $p->get_text('/p') ); $p->get_token(); # toss the </p> $last_end_tag = 'blockquote'; } else { $html .= $token->[-1]; } } elsif ( $token->[0] eq 'E' ) { # if it's a new blockquote, it's closed already $html .= $token->[-1] unless $token->[1] eq '/p' and $last_end_tag eq 'h4'; $last_end_tag = $token->[1]; } } print $html; __END__ <p>Stand alone p, or, aw, skip it.</p> <h4 class="title">This is an h4</h4> <p class="salad" id="taco">A first paragraph.</p> <p>A follower.</p> <p>Big finish. Or Finnish?</p>
CSS solution.
blockquote { /* format definition, whatever you want... */ margin:1em 1em 1em 2em; font-style:italic; font-size:105%; } h4 + p { /* format definition identical to your blockquote def */ }
update: fixed grammar flatulence + one more, sigh.
In reply to Re: HTML module help please?
by Your Mother
in thread HTML module help please?
by Cody Pendant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |