I have some HTML:
<p>Lorem ipsum example laoreet. <a href="#">example</a>Cum porttitor</p>
<p>Phasellus <a href="#">gravida tempor example</a> magna</p>
I need to wrap a span around any instances of the text 'example' that occurs in the HTML unless it is inside an anchor tag. So that the above would become:
<p>Lorem ipsum <span class="something">example</span> laoreet. <a href="#">example</a>Cum porttitor</p>
<p>Phasellus <a href="#">gravida tempor example</a> posuere. Fusce vitae urna eu <span class="something">example</span> magna</p>
I can select the content of paragraphs that isn't inside an anchor tag using:
doc.xpath('//p//text()') - doc.xpath('//p//a/text()')
I can wrap tags around the text content of another tag using:
doc.search('div.some-class text()').wrap('<span class="something"></span>')
But how do I wrap tags around text within that content?