diff options
| author | Jeremy <saturn5971@gmail.com> | 2013-01-10 17:27:20 +0800 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-02-13 10:27:27 -0500 |
| commit | f94f466cd3461527fb76a3e8951039a3c2388829 (patch) | |
| tree | a65d54abff8f37160f6af72542f514dd319a9df7 /docs | |
| parent | 390001ce52802a7fa1fceeabfb646e6b32911fb9 (diff) | |
Fixed #19496 -- Added truncatechars_html filter.
Thanks esevece for the suggestion and Nick Sandford and Martin Warne
for the inital work on the patch.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/templates/builtins.txt | 20 | ||||
| -rw-r--r-- | docs/releases/1.7.txt | 5 |
2 files changed, 24 insertions, 1 deletions
diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt index 737224794d..93ec2adab5 100644 --- a/docs/ref/templates/builtins.txt +++ b/docs/ref/templates/builtins.txt @@ -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 diff --git a/docs/releases/1.7.txt b/docs/releases/1.7.txt index 3519ac5bda..8d2f329fed 100644 --- a/docs/releases/1.7.txt +++ b/docs/releases/1.7.txt @@ -657,7 +657,7 @@ Templates * :func:`django.shortcuts.render()` * :func:`django.shortcuts.render_to_response()` -* The :tfilter:`time` filter now accepts timzone-related :ref:`format +* The :tfilter:`time` filter now accepts timezone-related :ref:`format specifiers <date-and-time-formatting-specifiers>` ``'e'``, ``'O'`` , ``'T'`` and ``'Z'`` and is able to digest :ref:`time-zone-aware <naive_vs_aware_datetimes>` ``datetime`` instances performing the expected @@ -668,6 +668,9 @@ Templates otherwise. It also now accepts an optional ``using`` keyword argument to control which cache it uses. +* The new :tfilter:`truncatechars_html` filter truncates a string to be no + longer than the specified number of characters, taking HTML into account. + Requests ^^^^^^^^ |
