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. slug filename by willhardy 2 years, 6 months ago
  2. Template tag to sort a list of links by pytechd 4 years, 5 months ago
  3. YUI Loader as Django middleware by akaihola 3 years, 9 months ago
  4. Template tags to integrate with modconcat by matthanger 2 years, 6 months ago
  5. Better Static Image Serving With Fallback by menendez 1 year, 10 months ago

Comments

(Forgotten your password?)