in reply to Replacing an HTML element with multiple elements using HTML::TreeBuilder

Treebuilder API is cancer. Use something better.
use Web::Query::LibXML qw(); my $w = Web::Query->new_from_html(<<'HTML'); <body> … HTML $w->find('blockquote p')->each(sub { my @parts = split ' ', $_->text; if (@parts > 1) { for my $p (reverse @parts) { $_->after("<p>$p</p>"); } $_->remove; } }); print $w->as_html; __END__ … <blockquote id="two"><p>ddd</p><p>eee</p><p>fff</p></blockquote> …
  • Comment on Re: Replacing an HTML element with multiple elements using HTML::TreeBuilder
  • Download Code

Replies are listed 'Best First'.
Re^2: Replacing an HTML element with multiple elements using HTML::TreeBuilder
by Anonymous Monk on Jul 04, 2019 at 04:01 UTC

    daxim: Treebuilder API is cancer. Use something better.

    No it isn't. It is neither damaging nor does it spread.

    Sugar is nice, unless it rots your attitude :P