Login

Tag "paragraph"

Snippet List

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
Read More

Line & paragraph chopping

I was faced with the fact that I wanted to post 2 paragraph-long summaries on one of my sites, and this is what I did (you could of course cut it down earlier, but I'd say this belongs to what is called "template logic") Use like so: {% load myExtraModule %} {{ blogpost.content|paragraphs:"2" }} The lines filter works the exact same way, and you might want to improve on these a bit, I don't maintain them as I don't use them anymore.

  • chop
  • cut
  • line
  • paragraph
  • block
Read More

2 snippets posted so far.