Add the attribute "rel='lightbox'" to all Links, if the target is an image.
<a href="/path/to/image.jpg">Image</a>
becomes
<a rel="lightbox" href="/path/to/image.jpg">Image</a>
Works for JPG, GIF and PNG Files.
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
- find even number by Rajeev529 2 weeks ago
- Form field with fixed value by roam 1 month ago
- New Snippet! by Antoliny0919 1 month, 1 week ago
- Add Toggle Switch Widget to Django Forms by OgliariNatan 4 months ago
- get_object_or_none by azwdevops 7 months, 3 weeks ago
Comments
Please login first before commenting.