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
- Form field with fixed value by roam 1 week, 4 days ago
- New Snippet! by Antoliny0919 2 weeks, 4 days ago
- Add Toggle Switch Widget to Django Forms by OgliariNatan 3 months, 1 week ago
- get_object_or_none by azwdevops 6 months, 4 weeks ago
- Mask sensitive data from logger by agusmakmun 8 months, 3 weeks ago
Comments
Please login first before commenting.