diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
index 47e116c..531e6ab 100644
a
|
b
|
def truncatewords(value, arg):
|
258 | 258 | Truncates a string after a certain number of words. |
259 | 259 | |
260 | 260 | Argument: Number of words to truncate after. |
| 261 | |
| 262 | Note that newlines within the string are removed. |
261 | 263 | """ |
262 | 264 | from django.utils.text import truncate_words |
263 | 265 | try: |
… |
… |
def truncatewords_html(value, arg):
|
273 | 275 | Truncates HTML after a certain number of words. |
274 | 276 | |
275 | 277 | Argument: Number of words to truncate after. |
| 278 | |
| 279 | Note that newlines are preserved, unlike `truncatewords`. |
276 | 280 | """ |
277 | 281 | from django.utils.text import truncate_html_words |
278 | 282 | try: |
diff --git a/django/utils/text.py b/django/utils/text.py
index fe46e26..0e03bd5 100644
a
|
b
|
def wrap(text, width):
|
38 | 38 | wrap = allow_lazy(wrap, unicode) |
39 | 39 | |
40 | 40 | def truncate_words(s, num): |
41 | | "Truncates a string after a certain number of words." |
| 41 | """ |
| 42 | Truncates a string after a certain number of words. |
| 43 | |
| 44 | Note that newlines within the string are removed. |
| 45 | """ |
42 | 46 | s = force_unicode(s) |
43 | 47 | length = int(num) |
44 | 48 | words = s.split() |
… |
… |
def truncate_html_words(s, num):
|
54 | 58 | Truncates html to a certain number of words (not counting tags and |
55 | 59 | comments). Closes opened tags if they were correctly closed in the given |
56 | 60 | html. |
| 61 | |
| 62 | Note that newlines are preserved, unlike `truncate_words`. |
57 | 63 | """ |
58 | 64 | s = force_unicode(s) |
59 | 65 | length = int(num) |
diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt
index f4e49a9..4dd5416 100644
a
|
b
|
For example::
|
1510 | 1510 | |
1511 | 1511 | If ``value`` is ``"Joel is a slug"``, the output will be ``"Joel is ..."``. |
1512 | 1512 | |
| 1513 | Note that newlines within the string are removed. |
| 1514 | |
1513 | 1515 | .. templatefilter:: truncatewords_html |
1514 | 1516 | |
1515 | 1517 | truncatewords_html |
… |
… |
closed immediately after the truncation.
|
1522 | 1524 | This is less efficient than ``truncatewords``, so should only be used when it |
1523 | 1525 | is being passed HTML text. |
1524 | 1526 | |
| 1527 | Note that newlines are preserved, unlike the `truncatewords`_ filter. |
| 1528 | |
1525 | 1529 | .. templatefilter:: unordered_list |
1526 | 1530 | |
1527 | 1531 | unordered_list |