gallery.py: add caption title/alt to images.
authorW. Trevor King <wking@tremily.us>
Wed, 17 Oct 2012 22:42:27 +0000 (18:42 -0400)
committerW. Trevor King <wking@tremily.us>
Wed, 17 Oct 2012 23:07:23 +0000 (19:07 -0400)
posts/gallery/gallery.py

index 8c7da07df942d9460b60174e39752ff06879c0a0..ecdd85fb0c0084269485214272ebe3d68d88be4b 100755 (executable)
@@ -465,7 +465,17 @@ class CGIGalleryServer (object):
             image_path,image_url = self._thumb(image, **kwargs)
         else:
             image_url = image
-        return '<img src="{}" />'.format(image_url)
+        sections = ['<img src="{}"'.format(image_url)]
+        caption = self._get_image_caption(path=image)
+        if caption:
+            caption = _xml_sax_saxutils.quoteattr(
+                caption.replace('\n', ' ').strip())
+            sections.extend([
+                    'title={}'.format(caption),
+                    'alt={}'.format(caption),
+                    ])
+        sections.append('/>')
+        return ' '.join(sections)
 
     def _image_page(self, image):
         return image_base(image) + '/'