@register.tag(name='<STR_LIT>')<EOL>def do_truncate(parser, token):
_, count = token.split_contents()<EOL>nodelist = parser.parse(('<STR_LIT>', '<STR_LIT>',))<EOL>token = parser.next_token()<EOL>if token.contents == '<STR_LIT>':<EOL><INDENT>nodelist_more = parser.parse(('<STR_LIT>',))<EOL>parser.delete_first_token()<EOL><DEDENT>else:<EOL><INDENT>nodelist_more = None<EOL><DEDENT>return TruncateNode(count, nodelist, nodelist_more)<EOL>
Truncates given text (html-aware)
Sample usage::

    {% truncate 60 %}
         {{ some_text }}
    {% more %}
         <a href="asdasd">Read more..</a>
    {% endtruncate %}