title: How to handle html tags in highlight fragment in SOLR
body: <p>I use SOLR hit highlighting feature to set highlights in a document matches the query.</p>
  
  <p>The problem is one of the fields contain valid HTML, but highlight fragment returned is not valid HTML, that's why after the rendering whole page layout is broken.</p>
  
  <p>For example query <code>field:lucene</code> get me this document:</p>
  
  <p><code>&lt;p&gt;&lt;a href="/some/link"&gt;Here is the discussion, what the difference between SOLR, Elasticsearch and Lucene&lt;/a&gt;&lt;/p&gt;</code></p>
  
  <p>Highlight fragment is <code>Elasticsearch and &lt;em&gt;Lucene&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;</code>.</p>
  
  <p>One of the option I've tried to set fragment size = 0 (return whole field content) but it can be very large and I need just a few snippets for the result page.</p>
  
  <p>Another option is to remove all HTML tags and show snippet in plain text, but I need <code>&lt;em&gt;</code> tags for highlighting. Also some tags could be broken in fragment like a <code>&lt;/p</code> that means we can't use html parsers for that purpose.</p>
  
  <p>It seems like a common problem in search, is there some state-of-the-art approach to handle that?</p>