develooper Front page | perl.libwww | Postings from January 2002

Re: Fixing opening/closing tags.

Thread Previous | Thread Next
From:
Sean M. Burke
Date:
January 6, 2002 15:13
Subject:
Re: Fixing opening/closing tags.
Message ID:
3.0.6.32.20020106161026.008a43a0@mail.spinn.net
At 07:31 AM 2002-01-05 -0800, Bill Moseley wrote:
>[...]
>One problem, of course, is I don't really know what the actual <tag> will
>be, and there might be a mixture of tags:
>
>   <b>This <em>is something -- really</em> -- awkward</b> without doubt
>
>Ends up:
>
>   <b>This <em>is something</em></b>
>   <b><em>really</em></b>
>   <b>awkward</b> without doubt
>[...]
>But I'm wondering if HTML::TreeBuilder might be able to rescue me.
>
>It doesn't seem like an uncommon problem, so I'm asking here for advice.

It's an uncommon problem.  And it's tricky.

But here's a hint: Since you're operating on text nodes, and asking things
about them like their parentage, consider the $h->objectify_text() method
-- applying it at least to <b>'s in a tree, then hacking at the text nodes
as appropriate, then calling $h->deobjectify_text, or whatever I called it.

Further hint: what you'll need to clone the <em>...</em> above is:
ref($em)->new($em->tag, $em->all_external_attr).  At least I think that's
right.


--
Sean M. Burke  sburke@cpan.org  http://www.spinn.net/~sburke/


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About