Changeset 5513
- Timestamp:
- 06/22/07 22:10:32 (1 year ago)
- Files:
-
- django/trunk/django/utils/html.py (modified) (1 diff)
- django/trunk/docs/templates.txt (modified) (1 diff)
- django/trunk/tests/regressiontests/defaultfilters/tests.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/utils/html.py
r4933 r5513 54 54 def urlize(text, trim_url_limit=None, nofollow=False): 55 55 """ 56 Converts any URLs in text into clickable links. Works on http://, https:// and 57 www. links. Links can have trailing punctuation (periods, commas, close-parens) 58 and leading punctuation (opening parens) and it'll still do the right thing. 56 Converts any URLs in text into clickable links. Works on http://, https:// 57 and www. links. Links can have trailing punctuation (periods, commas, 58 close-parens) and leading punctuation (opening parens) and it'll still do 59 the right thing. 59 60 60 If trim_url_limit is not None, the URLs in link text will be limited to61 trim_url_limit characters.61 If trim_url_limit is not None, the URLs in link text longer than this limit 62 will truncated to trim_url_limit-3 characters and appended with an elipsis. 62 63 63 If nofollow is True, the URLs in link text will get a rel="nofollow" attribute. 64 If nofollow is True, the URLs in link text will get a rel="nofollow" 65 attribute. 64 66 """ 65 trim_url = lambda x, limit=trim_url_limit: limit is not None and ( x[:limit] + (len(x) >=limit and '...' or ''))or x67 trim_url = lambda x, limit=trim_url_limit: limit is not None and (len(x) > limit and ('%s...' % x[:max(0, limit - 3)])) or x 66 68 words = word_split_re.split(text) 67 69 nofollow_attr = nofollow and ' rel="nofollow"' or '' django/trunk/docs/templates.txt
r5443 r5513 1267 1267 ~~~~~~~~~~~ 1268 1268 1269 Converts URLs into clickable links, truncating URLs to the given character limit. 1269 Converts URLs into clickable links, truncating URLs longer than the given 1270 character limit. 1270 1271 1271 1272 **Argument:** Length to truncate URLs to django/trunk/tests/regressiontests/defaultfilters/tests.py
r4919 r5513 122 122 123 123 >>> urlizetrunc('http://www.google.co.uk/search?hl=en&q=some+long+url&btnG=Search&meta=', 20) 124 '<a href="http://www.google.co.uk/search?hl=en&q=some+long+url&btnG=Search&meta=" rel="nofollow">http://www.google.co...</a>' 124 '<a href="http://www.google.co.uk/search?hl=en&q=some+long+url&btnG=Search&meta=" rel="nofollow">http://www.google...</a>' 125 126 # Check truncating of URIs which are the exact length 127 >>> uri = 'http://31characteruri.com/test/' 128 >>> len(uri) 129 31 130 >>> urlizetrunc(uri, 31) 131 '<a href="http://31characteruri.com/test/" rel="nofollow">http://31characteruri.com/test/</a>' 132 >>> urlizetrunc(uri, 30) 133 '<a href="http://31characteruri.com/test/" rel="nofollow">http://31characteruri.com/t...</a>' 134 >>> urlizetrunc(uri, 2) 135 '<a href="http://31characteruri.com/test/" rel="nofollow">...</a>' 125 136 126 137 >>> wordcount('')
