title: Extract text with lxml.html
body: <p>I have a HTML file:</p>
  
  <pre><code>&lt;html&gt;
      &lt;p&gt;somestr
          &lt;sup&gt;1&lt;/sup&gt;
         anotherstr
      &lt;/p&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I would like to extract the text as:
   <p>somestr<sup>1</sup>anotherstr</p></p>
  
  <p>but I can't figure out how to do it. I have written a <code>to_sup()</code> function  that converts numeric strings to superscript so the closest I get  is something like:</p>
  
  <pre><code>for i in doc.xpath('.//p/text()|.//sup/text()'):
      if i.tag == 'sup':
          print to_sup(i),
      else:
          print i,
  </code></pre>
  
  <p>but I <code>ElementStringResult</code> doesn't seem to have a method to get the tag name, so I am a bit lost. Any ideas how to solve it?</p>