Index: django/utils/text.py
===================================================================
--- django/utils/text.py (revision 10651)
+++ django/utils/text.py (working copy)
@@ -61,8 +61,8 @@
return u''
html4_singlets = ('br', 'col', 'link', 'base', 'img', 'param', 'area', 'hr', 'input')
# Set up regular expressions
- re_words = re.compile(r'&.*?;|<.*?>|(\w[\w-]*)', re.U)
- re_tag = re.compile(r'<(/)?([^ ]+?)(?: (/)| .*?)?>')
+ re_words = re.compile(r'&.*?;|<.*?>|(\w[\w-]*)', re.U|re.S)
+ re_tag = re.compile(r'<(/)?([^ ]+?)(?: (/)| .*?)?>', re.S)
# Count non-HTML words and keep note of open tags
pos = 0
ellipsis_pos = 0
Index: tests/regressiontests/utils/tests.py
===================================================================
--- tests/regressiontests/utils/tests.py (revision 10651)
+++ tests/regressiontests/utils/tests.py (working copy)
@@ -9,6 +9,7 @@
import timesince
import datastructures
import itercompat
+import text
from decorators import DecoratorFromMiddlewareTests
# We need this because "datastructures" uses sorted() and the tests are run in
@@ -23,6 +24,7 @@
'timesince': timesince,
'datastructures': datastructures,
'itercompat': itercompat,
+ 'text': text,
}
class TestUtilsHtml(TestCase):
Index: tests/regressiontests/utils/text.py
===================================================================
--- tests/regressiontests/utils/text.py (revision 0)
+++ tests/regressiontests/utils/text.py (revision 0)
@@ -0,0 +1,40 @@
+"""
+>>> from django.utils.text import truncate_html_words
+
+>>> a = "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout."
+>>> truncate_html_words(a, 8)
+u'It is a long established fact that a ...'
+
+>>> a = "It is a long \\nestablished fact that a reader will be distracted by the readable content of a page when looking at its layout."
+>>> truncate_html_words(a, 8)
+u'It is a long \\nestablished fact that a ...'
+
+>>> a = 'It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.'
+>>> truncate_html_words(a, 8)
+u'It is a long established fact that a ...'
+
+>>> a = 'Fact: Python > Ruby. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.'
+>>> truncate_html_words(a, 8)
+u'Fact: Python > Ruby. It is a long established ...'
+
+>>> a = 'Fact: Ruby < Python.
It is a long established fact that a reader will be distracted bythe readable content of a page when looking at its layout.'
+>>> truncate_html_words(a, 8)
+u'Fact: Ruby < Python.
It is a long established ...'
+
+>>> a = 'Fact: Ruby < Python.
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.'
+>>> truncate_html_words(a, 8)
+u'Fact: Ruby < Python.
It is a long established ...'
+
+>>> a = 'Fact: Ruby < Python.
It > is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.'
+>>> truncate_html_words(a, 8)
+u'Fact: Ruby < Python.
It > is a long established ...'
+
+# Oops. Not smart enough after all. But proper behavior according to code.
+>>> a = 'It is a that a reader will be distracted by the readable content of a page when looking at its layout.'
+>>> truncate_html_words(a, 8)
+u'It is a that a reader will be ...'
+"""
+
+if __name__ == "__main__":
+ import doctest
+ doctest.testmod()
Property changes on: tests\regressiontests\utils\text.py
___________________________________________________________________
Added: svn:eol-style
+ native