title: Django template: smartly slice the HTML content
body: <p>I would like to <strong>smartly</strong> slice an HTML content.</p>
  
  <p>Taking the <code>news</code> as an example, the page for displaying a news list is as follows:</p>
  
  <pre><code>&lt;table&gt;
    &lt;tr&gt;&lt;th&gt;Title&lt;/th&gt;&lt;th&gt;Content&lt;/th&gt;&lt;/tr&gt;
    {% for news in newsList %}
      &lt;tr&gt;
        &lt;td&gt;&lt;a href="/news/{{news.id}}/"&gt;{{news.title}}&lt;/a&gt;&lt;/td&gt;
        &lt;td&gt;{{news.content | slice:":30" | safe}} ...&lt;/td&gt;
      &lt;/tr&gt;
    {% endfor %}
  &lt;/table&gt;
  </code></pre>
  
  <p>The content of a news is sliced such that the user will only see some part of the news. But if the place of <code>slice:":30"</code> happens to be in an HTML tag, there would be a problem.</p>
  
  <p>For example, if the content of <code>news.content</code> is the following:</p>
  
  <p><code>&lt;p&gt;What is Content Marketing?&lt;/p&gt;</code></p>
  
  <p>The result of slicing would be <code>&lt;p&gt;What is Content Marketing?&lt; ...</code>, in which the tag <code>&lt;p&gt;</code> is not closed.</p>
  
  <p>Is there any way to preserve an HTML tag when slicing?</p>