1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +00:00

unicode: Fixed #4662 -- Fixed a remaining ASCII assumption in

truncatewords_html(). Thanks, Ivan Sagalaev.


git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5533 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2007-06-25 13:11:10 +00:00
parent 9c5994743c
commit daaa3a1dde
2 changed files with 4 additions and 1 deletions

View File

@ -59,7 +59,7 @@ def truncate_html_words(s, num):
return u'' return u''
html4_singlets = ('br', 'col', 'link', 'base', 'img', 'param', 'area', 'hr', 'input') html4_singlets = ('br', 'col', 'link', 'base', 'img', 'param', 'area', 'hr', 'input')
# Set up regular expressions # Set up regular expressions
re_words = re.compile(r'&.*?;|<.*?>|([A-Za-z0-9][\w-]*)') re_words = re.compile(r'&.*?;|<.*?>|(\w[\w-]*)', re.U)
re_tag = re.compile(r'<(/)?([^ ]+?)(?: (/)| .*?)?>') re_tag = re.compile(r'<(/)?([^ ]+?)(?: (/)| .*?)?>')
# Count non-HTML words and keep note of open tags # Count non-HTML words and keep note of open tags
pos = 0 pos = 0

View File

@ -104,6 +104,9 @@ u'<p>one <a href="#">two - three <br>four</a> five</p>'
>>> truncatewords_html(u'<p>one <a href="#">two - three <br>four</a> five</p>', 100) >>> truncatewords_html(u'<p>one <a href="#">two - three <br>four</a> five</p>', 100)
u'<p>one <a href="#">two - three <br>four</a> five</p>' u'<p>one <a href="#">two - three <br>four</a> five</p>'
>>> truncatewords_html(u'\xc5ngstr\xf6m was here', 1)
u'\xc5ngstr\xf6m ...'
>>> upper(u'Mixed case input') >>> upper(u'Mixed case input')
u'MIXED CASE INPUT' u'MIXED CASE INPUT'