fixes for edge cases
[librarian.git] / src / librarian / elements / figures / ilustr.py
index ab7c2b7..9b3b165 100644 (file)
@@ -4,6 +4,8 @@ from ..base import WLElement
 
 
 class Ilustr(WLElement):
+    SHOULD_HAVE_ID = True
+
     EPUB_TAG = HTML_TAG = 'img'
 
     def get_html_attr(self, builder):
@@ -27,10 +29,9 @@ class Ilustr(WLElement):
         else:
             th = img.resize((width, round(width * img.size[1] / img.size[0])))
 
-        imgfile.close()
         buffer = six.BytesIO()
         th.save(buffer, format=th_format)
-        ## TODO: Counter
+        imgfile.close()
         file_name = 'image%d.%s' % (
             builder.assign_image_number(),
             ext
@@ -44,8 +45,8 @@ class Ilustr(WLElement):
         
         return {
             'src': file_name,
-            'alt': self.attrib['alt'],
-            'title': self.attrib['alt'],
+            'alt': self.attrib.get('alt', ''),
+            'title': self.attrib.get('alt', ''),
         }
 
     get_epub_attr = get_html_attr