Ticket #4657: urlize_trunc.2.patch
File urlize_trunc.2.patch, 2.6 KB (added by , 17 years ago) |
---|
-
django/utils/html.py
57 57 www. links. Links can have trailing punctuation (periods, commas, close-parens) 58 58 and leading punctuation (opening parens) and it'll still do the right thing. 59 59 60 If trim_url_limit is not None, the URLs in link text will be limited to61 trim_url_limit characters.60 If trim_url_limit is not None, the URLs in link text longer than this limit 61 will truncated to trim_url_limit-3 characters and appended with an elipsis. 62 62 63 63 If nofollow is True, the URLs in link text will get a rel="nofollow" attribute. 64 64 """ 65 trim_url = lambda x, limit=trim_url_limit: limit is not None and (x[:limit] + (len(x) >=limit and '...' or ''))or x65 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 66 words = word_split_re.split(text) 67 67 nofollow_attr = nofollow and ' rel="nofollow"' or '' 68 68 for i, word in enumerate(words): -
docs/templates.txt
1266 1266 urlizetrunc 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 1272 1273 -
tests/regressiontests/defaultfilters/tests.py
121 121 '<a href="http://short.com/" rel="nofollow">http://short.com/</a>' 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 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 126 135 >>> wordcount('') 127 136 0 128 137