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

Re: Fixing opening/closing tags.

Thread Previous | Thread Next
Sean M. Burke
January 6, 2002 15:13
Re: Fixing opening/closing tags.
Message ID:
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

Sean M. Burke

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About