Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.2.X] Fixed #11021 -- Clarified newline stripping behavior in the t…

…runcatewords and truncatewords_html filters. Thanks to Ben Spaulding for the report and patch.

Backport of r13555 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@13562 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c7c59bc24f6b680277c05e4b631d9e4a69f44473 1 parent 0ea661c
Russell Keith-Magee authored August 07, 2010
4  django/template/defaultfilters.py
@@ -256,6 +256,8 @@ def truncatewords(value, arg):
256 256
     Truncates a string after a certain number of words.
257 257
 
258 258
     Argument: Number of words to truncate after.
  259
+
  260
+    Newlines within the string are removed.
259 261
     """
260 262
     from django.utils.text import truncate_words
261 263
     try:
@@ -271,6 +273,8 @@ def truncatewords_html(value, arg):
271 273
     Truncates HTML after a certain number of words.
272 274
 
273 275
     Argument: Number of words to truncate after.
  276
+
  277
+    Newlines in the HTML are preserved.
274 278
     """
275 279
     from django.utils.text import truncate_html_words
276 280
     try:
12  django/utils/text.py
@@ -39,7 +39,10 @@ def _generator():
39 39
 def truncate_words(s, num, end_text='...'):
40 40
     """Truncates a string after a certain number of words. Takes an optional
41 41
     argument of what should be used to notify that the string has been
42  
-    truncated, defaults to ellipsis (...)"""
  42
+    truncated, defaulting to ellipsis (...)
  43
+
  44
+    Newlines in the string will be stripped.
  45
+    """
43 46
     s = force_unicode(s)
44 47
     length = int(num)
45 48
     words = s.split()
@@ -51,10 +54,13 @@ def truncate_words(s, num, end_text='...'):
51 54
 truncate_words = allow_lazy(truncate_words, unicode)
52 55
 
53 56
 def truncate_html_words(s, num, end_text='...'):
54  
-    """Truncates html to a certain number of words (not counting tags and
  57
+    """Truncates HTML to a certain number of words (not counting tags and
55 58
     comments). Closes opened tags if they were correctly closed in the given
56 59
     html. Takes an optional argument of what should be used to notify that the
57  
-    string has been truncated, defaults to ellipsis (...)."""
  60
+    string has been truncated, defaulting to ellipsis (...).
  61
+
  62
+    Newlines in the HTML are preserved.
  63
+    """
58 64
     s = force_unicode(s)
59 65
     length = int(num)
60 66
     if length <= 0:
4  docs/ref/templates/builtins.txt
@@ -1883,6 +1883,8 @@ For example::
1883 1883
 
1884 1884
 If ``value`` is ``"Joel is a slug"``, the output will be ``"Joel is ..."``.
1885 1885
 
  1886
+Newlines within the string will be removed.
  1887
+
1886 1888
 .. templatefilter:: truncatewords_html
1887 1889
 
1888 1890
 truncatewords_html
@@ -1902,6 +1904,8 @@ For example::
1902 1904
 If ``value`` is ``"<p>Joel is a slug</p>"``, the output will be
1903 1905
 ``"<p>Joel is ...</p>"``.
1904 1906
 
  1907
+Newlines in the HTML content will be preserved.
  1908
+
1905 1909
 .. templatefilter:: unordered_list
1906 1910
 
1907 1911
 unordered_list

0 notes on commit c7c59bc

Please sign in to comment.
Something went wrong with that request. Please try again.