Fixed #19496 -- Added truncatechars_html filter.

Thanks esevece for the suggestion and  Nick Sandford and Martin Warne
for the inital work on the patch.
This commit is contained in:
Jeremy 2013-01-10 17:27:20 +08:00 committed by Tim Graham
parent 390001ce52
commit f94f466cd3
5 changed files with 93 additions and 23 deletions

View file

@ -2172,6 +2172,26 @@ For example::
If ``value`` is ``"Joel is a slug"``, the output will be ``"Joel i..."``.
.. templatefilter:: truncatechars_html
truncatechars_html
^^^^^^^^^^^^^^^^^^
.. versionadded:: 1.7
Similar to :tfilter:`truncatechars`, except that it is aware of HTML tags. Any
tags that are opened in the string and not closed before the truncation point
are closed immediately after the truncation.
For example::
{{ value|truncatechars_html:9 }}
If ``value`` is ``"<p>Joel is a slug</p>"``, the output will be
``"<p>Joel i...</p>"``.
Newlines in the HTML content will be preserved.
.. templatefilter:: truncatewords
truncatewords