Re: LWP 5.0: FormatText and more?
Gisle Aas (aas@bergen.sn.no)
Fri, 28 Jun 1996 12:09:26 +0200
In message <199606271738.NAA00981@superprism.net>, San Deng writes:
>
> FormatText removes all references to graphics (<img ....>). How can I
> retain some mimimal info on those graphics? For example, I have html
> lines
>
> ...
> This is after FormatTextMore <img src=smiley.gif> (see the smiley).
> ...
>
> then after some other package, say, FormatTextMore, the above lines
> will be
>
> ...
> This is after FormatTextMore [smiley.gif] (see the smiley).
> ...
>
>
> I couldn't figure out how to use "traverse". If I did, I could write
> something like FormatTextMore. Could someone enlighten me on that?
Just make a sub-class of HTML::FormatText where you override the <img>
handling:
package FormatTextMore;
require HTML::FormatText;
@ISA = qw(HTML::FormatText);
sub img_start
{
my($self, $img) = @_;
$self->out("[" . $img->attr('src') . "]");
}
package main;
#
# Show example usage
#
require HTML::TreeBuilder;
$h = new HTML::TreeBuilder;
$h->parse("This is after FormatTextMore <img src=smiley.gif> (see the smiley)");
$f = new FormatTextMore;
print $f->format($h);