Changeset 6911
- Timestamp:
- 12/10/07 23:49:11 (1 year ago)
- Files:
-
- django/trunk/django/utils/html.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/utils/html.py
r6856 r6911 1 " HTML utilities suitable for global use."1 """HTML utilities suitable for global use.""" 2 2 3 3 import re … … 9 9 from django.utils.http import urlquote 10 10 11 # Configuration for urlize() function 11 # Configuration for urlize() function. 12 12 LEADING_PUNCTUATION = ['(', '<', '<'] 13 13 TRAILING_PUNCTUATION = ['.', ',', ')', '>', '\n', '>'] 14 14 15 # list of possible strings used for bullets in bulleted lists15 # List of possible strings used for bullets in bulleted lists. 16 16 DOTS = ['·', '*', '\xe2\x80\xa2', '•', '•', '•'] 17 17 … … 29 29 30 30 def escape(html): 31 " Return the given HTML with ampersands, quotes and carets encoded."31 """Returns the given HTML with ampersands, quotes and carets encoded.""" 32 32 return mark_safe(force_unicode(html).replace('&', '&').replace('<', '<').replace('>', '>').replace('"', '"').replace("'", ''')) 33 33 escape = allow_lazy(escape, unicode) … … 43 43 44 44 def linebreaks(value, autoescape=False): 45 " Converts newlines into <p> and <br />s"45 """Converts newlines into <p> and <br />s.""" 46 46 value = re.sub(r'\r\n|\r|\n', '\n', force_unicode(value)) # normalize newlines 47 47 paras = re.split('\n{2,}', value) … … 51 51 paras = [u'<p>%s</p>' % p.strip().replace('\n', '<br />') for p in paras] 52 52 return u'\n\n'.join(paras) 53 linebreaks = allow_lazy(linebreaks, unicode) 53 linebreaks = allow_lazy(linebreaks, unicode) 54 54 55 55 def strip_tags(value): 56 " Return the given HTML with all tags stripped."56 """Returns the given HTML with all tags stripped.""" 57 57 return re.sub(r'<[^>]*?>', '', force_unicode(value)) 58 58 strip_tags = allow_lazy(strip_tags) 59 59 60 60 def strip_spaces_between_tags(value): 61 " Return the given HTML with spaces between tags removed."61 """Returns the given HTML with spaces between tags removed.""" 62 62 return re.sub(r'>\s+<', '><', force_unicode(value)) 63 63 strip_spaces_between_tags = allow_lazy(strip_spaces_between_tags, unicode) 64 64 65 65 def strip_entities(value): 66 " Return the given HTML with all entities (&something;) stripped."66 """Returns the given HTML with all entities (&something;) stripped.""" 67 67 return re.sub(r'&(?:\w+|#\d+);', '', force_unicode(value)) 68 68 strip_entities = allow_lazy(strip_entities, unicode) 69 69 70 70 def fix_ampersands(value): 71 " Return the given HTML with all unencoded ampersands encoded correctly."71 """Returns the given HTML with all unencoded ampersands encoded correctly.""" 72 72 return unencoded_ampersands_re.sub('&', force_unicode(value)) 73 73 fix_ampersands = allow_lazy(fix_ampersands, unicode) … … 75 75 def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False): 76 76 """ 77 Convert any URLs in text into clickable links.77 Converts any URLs in text into clickable links. 78 78 79 79 Works on http://, https://, and www. links. Links can have trailing
