Let's say I have the following html that is an outline using header tags:
<h1>blah</h1> <p>blah<p> <h2>blah</h2> <p>blah</p> <h3>blah</h3> <p>blah</p> <h2>blah blah blah</h2> <p>blah</p> <h1>blah</h2> <h2>blah</h2> <h2>blah</h2>
I want to convert that to this, wrapping each h2 with a div:
In other words, the algorithm must search for all h2 tags, then find the next sibling tag that is not an h1 tag or EOF, and wrap that section in a div tag. HTML::Element and HTML::TreeBuilder seem like the right tools for the job but this problem seems so common I'm wondering if there is something that works out of the box for dealing with HTML that is set up like an outline.<h1>blah</h1> <p>blah<p> <div> <h2>blah</h2> </div> <div> <p>blah</p> <h3>blah</h3> <p>blah</p> </div> <div> <h2>blah blah blah</h2> <p>blah</p> </div> <h1>blah</h1> <div> <h2>blah</h2> </div> <div> <h2>blah</h2> </div>
$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
In reply to Wrapping HTML "sections" with a div by nysus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |