Ticket #4657: urlize_trunc.patch

File urlize_trunc.patch, 1.5 KB (added by Chris Beaven, 17 years ago)
  • django/utils/html.py

     
    5757    www. links. Links can have trailing punctuation (periods, commas, close-parens)
    5858    and leading punctuation (opening parens) and it'll still do the right thing.
    5959
    60     If trim_url_limit is not None, the URLs in link text will be limited to
    61     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.
    6262
    6363    If nofollow is True, the URLs in link text will get a rel="nofollow" attribute.
    6464    """
    65     trim_url = lambda x, limit=trim_url_limit: limit is not None and (x[:limit] + (len(x) >=limit and '...' or '')) or x
     65    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
    6666    words = word_split_re.split(text)
    6767    nofollow_attr = nofollow and ' rel="nofollow"' or ''
    6868    for i, word in enumerate(words):
  • docs/templates.txt

     
    12661266urlizetrunc
    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
    12721273
Back to Top