Add rel=lightbox to all image-links

1
2
3
4
5
6
7
8
9
import re
from django.utils.encoding import smart_unicode

r_lightbox = re.compile('<a (?=[^>]*\.(jpg|gif|png))(?![^>]*lightbox)')
s_lightbox = '<a rel="lightbox" '

@register.filter
def lightbox(content):
    return r_lightbox.sub(s_lightbox, smart_unicode(content))

More like this

  1. True links in the admin list by svetlyak 5 years, 8 months ago
  2. Template tags to integrate with modconcat by matthanger 3 years, 10 months ago
  3. iPernity thumbnail helper by sedden 4 years, 6 months ago
  4. Filter to resize a ImageField on demand by michelts 6 years, 1 month ago
  5. Cacheable resources by jbrisbin 4 years, 9 months ago

Comments

(Forgotten your password?)