filter for extracting a number of paragraphs from any HTML code
From: [incredible times](http://incredibletimes.org) With inspiration from: [Unethical Blogger](http://unethicalblogger.com/2008/05/03/parsing-html-with-python.html) This code parses any provided HTML content, and extracts a number of paragraphs specified, with all the content and tags inside them. Example: Template variable "content" contains: <a href="#>some text</a> <p><strong>Testing</strong>testing testing this is a tester's life</p> <div>I wont see the world</div> <p>Another paragraph</p> So, place this code in any loaded template module (inside a templatetags folder of your app... i.e. myapp/templatetags/myutils.py) {% load myutils %} {{ content|paragraphs:"1"}} Would return: <p><strong>Testing</strong>testing testing this is a tester's life</p> Whereas {% load myutils %} {{ content|paragraphs:"2"}} Returns: <p><strong>Testing</strong>testing testing this is a tester's life</p> <p>Another paragraph</p>
- filter
- paragraph
- html
- parse
- extract