in reply to Replacing an HTML element with multiple elements using HTML::TreeBuilder
for my $p ($xhtml->findnodes('//blockquote/p')) { my $text = $p->as_text(); $text =~ s/^\s+//; $text =~ s/\s+$//; if ( $text =~/\n\s*\n\s*/ ) { my @paragraphs = split(/\s*\n\s*/, $text); my @new_elems; for my $para (@paragraphs) { my $new = HTML::Element->new('p'); $new->push_content($para); push(@new_elems, $new); } $p->replace_with(@new_elems); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Replacing an HTML element with multiple elements using HTML::TreeBuilder
by mldvx4 (Hermit) on Jul 03, 2019 at 17:52 UTC |