Django

Code

Changeset 5513

Show
Ignore:
Timestamp:
06/22/07 22:10:32 (1 year ago)
Author:
mtredinnick
Message:

Fixed #4657 -- Fixed an error in an edge case of the urlizetrunc filter.
Thanks, SmileyChris?.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/utils/html.py

    r4933 r5513  
    5454def urlize(text, trim_url_limit=None, nofollow=False): 
    5555    """ 
    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. 
    5960 
    60     If trim_url_limit is not None, the URLs in link text will be limited to 
    61     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. 
    6263 
    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. 
    6466    """ 
    65     trim_url = lambda x, limit=trim_url_limit: limit is not None and (x[:limit] + (len(x) >=limit and '...' or '')) or x 
     67    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 
    6668    words = word_split_re.split(text) 
    6769    nofollow_attr = nofollow and ' rel="nofollow"' or '' 
  • django/trunk/docs/templates.txt

    r5443 r5513  
    12671267~~~~~~~~~~~ 
    12681268 
    1269 Converts URLs into clickable links, truncating URLs to the given character limit. 
     1269Converts URLs into clickable links, truncating URLs longer than the given 
     1270character limit. 
    12701271 
    12711272**Argument:** Length to truncate URLs to 
  • django/trunk/tests/regressiontests/defaultfilters/tests.py

    r4919 r5513  
    122122 
    123123>>> 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) 
     12931 
     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>' 
    125136 
    126137>>> wordcount('')