in reply to Re: Wrapping HTML "sections" with a div
in thread Wrapping HTML "sections" with a div

I got this far before deciding I should see if I'm re-inventing the wheel:

sub wrap { my $tree = HTML::TreeBuilder->new_from_content(shift); foreach my $h2 ( $tree->find_by_tag_name('h2') ) { my $parent = HTML::Element->new('div', 'data-role' => 'collapsible +'); $h2->replace_with($parent); $parent->push_content($h2); } return $tree->as_HTML; }

The above only wraps the <h2> tag, not its associated content. The HTML is generated from markdown using Markdent so I think the proper thing to do is figure out how that works. Seems like it can do the job.

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks