@register.filter
@stringfilter
def url_trim(html):
 fragment = fromstring(html)
 for (el, attrib_, link_, pos_) in fragment.iterlinks():
  new_link_text = trim_url(el.text_content())
  el.text = new_link_text
 return mark_safe(tostring(fragment, encoding=unicode))

@ register . filter @ stringfilter def url_trim ( html ) : fragment = fromstring ( html ) for ( el , attrib_ , link_ , pos_ ) in fragment . iterlinks ( ) : new_link_text = trim_url ( el . text_content ( ) ) el . text = new_link_text return mark_safe ( tostring ( fragment , encoding = unicode ) )
trims anchor texts that are longer than 70 chars .