title: how to truncate HTML string without leaving it malformated?
body: <p>I have to display first N (for example say 50 or 100) characters out of entire html string. I have to display well formated html.If i apply simple substring that will get me a malformated html string 
  E.g. </p>
  
  <p>Sample string : <code>"&lt;html&gt;&lt;body&gt;&lt;a href="http://foo.com"&gt;foo&lt;/a&gt;&lt;/body&gt;&lt;/html&gt;"</code></p>
  
  <p>trucated string: <code>"&lt;html&gt;&lt;body&gt;&lt;a href="http://foo.com"&gt;foo&lt;"</code></p>
  
  <p>This will get me malformated html :(</p>
  
  <p>Any ideas on how to achieve this ??</p>