Author: russellm
Date: 2010-08-07 09:57:24 -0500 (Sat, 07 Aug 2010)
New Revision: 13555

Modified:
   django/trunk/django/template/defaultfilters.py
   django/trunk/django/utils/text.py
   django/trunk/docs/ref/templates/builtins.txt
Log:
Fixed #11021 -- Clarified newline stripping behavior in the truncatewords and 
truncatewords_html filters. Thanks to Ben Spaulding for the report and patch.

Modified: django/trunk/django/template/defaultfilters.py
===================================================================
--- django/trunk/django/template/defaultfilters.py      2010-08-07 14:56:59 UTC 
(rev 13554)
+++ django/trunk/django/template/defaultfilters.py      2010-08-07 14:57:24 UTC 
(rev 13555)
@@ -256,6 +256,8 @@
     Truncates a string after a certain number of words.
 
     Argument: Number of words to truncate after.
+
+    Newlines within the string are removed.
     """
     from django.utils.text import truncate_words
     try:
@@ -271,6 +273,8 @@
     Truncates HTML after a certain number of words.
 
     Argument: Number of words to truncate after.
+
+    Newlines in the HTML are preserved.
     """
     from django.utils.text import truncate_html_words
     try:

Modified: django/trunk/django/utils/text.py
===================================================================
--- django/trunk/django/utils/text.py   2010-08-07 14:56:59 UTC (rev 13554)
+++ django/trunk/django/utils/text.py   2010-08-07 14:57:24 UTC (rev 13555)
@@ -39,7 +39,10 @@
 def truncate_words(s, num, end_text='...'):
     """Truncates a string after a certain number of words. Takes an optional
     argument of what should be used to notify that the string has been
-    truncated, defaults to ellipsis (...)"""
+    truncated, defaulting to ellipsis (...)
+
+    Newlines in the string will be stripped.
+    """
     s = force_unicode(s)
     length = int(num)
     words = s.split()
@@ -51,10 +54,13 @@
 truncate_words = allow_lazy(truncate_words, unicode)
 
 def truncate_html_words(s, num, end_text='...'):
-    """Truncates html to a certain number of words (not counting tags and
+    """Truncates HTML to a certain number of words (not counting tags and
     comments). Closes opened tags if they were correctly closed in the given
     html. Takes an optional argument of what should be used to notify that the
-    string has been truncated, defaults to ellipsis (...)."""
+    string has been truncated, defaulting to ellipsis (...).
+
+    Newlines in the HTML are preserved.
+    """
     s = force_unicode(s)
     length = int(num)
     if length <= 0:

Modified: django/trunk/docs/ref/templates/builtins.txt
===================================================================
--- django/trunk/docs/ref/templates/builtins.txt        2010-08-07 14:56:59 UTC 
(rev 13554)
+++ django/trunk/docs/ref/templates/builtins.txt        2010-08-07 14:57:24 UTC 
(rev 13555)
@@ -1883,6 +1883,8 @@
 
 If ``value`` is ``"Joel is a slug"``, the output will be ``"Joel is ..."``.
 
+Newlines within the string will be removed.
+
 .. templatefilter:: truncatewords_html
 
 truncatewords_html
@@ -1902,6 +1904,8 @@
 If ``value`` is ``"<p>Joel is a slug</p>"``, the output will be
 ``"<p>Joel is ...</p>"``.
 
+Newlines in the HTML content will be preserved.
+
 .. templatefilter:: unordered_list
 
 unordered_list

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to