diff --git a/pydocx/export/html.py b/pydocx/export/html.py index 18e3ea53..468d1796 100644 --- a/pydocx/export/html.py +++ b/pydocx/export/html.py @@ -686,6 +686,7 @@ def export_table_cell(self, table_cell): def export_drawing(self, drawing): length, width = drawing.get_picture_extents() rotate = drawing.get_picture_rotate_angle() + description = drawing.get_picture_description() relationship_id = drawing.get_picture_relationship_id() if not relationship_id: return @@ -705,6 +706,8 @@ def export_drawing(self, drawing): attrs['height'] = height_px if rotate: attrs['rotate'] = rotate + if description: + attrs['description'] = description tag = self.get_image_tag(image=image, **attrs) if tag: @@ -726,7 +729,7 @@ def get_image_source(self, image): ) return self.escape(b64_encoded_src) - def get_image_tag(self, image, width=None, height=None, rotate=None): + def get_image_tag(self, image, width=None, height=None, rotate=None, description=None): image_src = self.get_image_source(image) if image_src: attrs = { @@ -737,6 +740,8 @@ def get_image_tag(self, image, width=None, height=None, rotate=None): attrs['height'] = height if rotate: attrs['style'] = 'transform: rotate(%sdeg);' % rotate + if description: + attrs['alt'] = description return HtmlTag( 'img', diff --git a/pydocx/export/numbering_span.py b/pydocx/export/numbering_span.py index 809ff672..a48a65dd 100644 --- a/pydocx/export/numbering_span.py +++ b/pydocx/export/numbering_span.py @@ -295,10 +295,10 @@ def detect_parent_child_map_for_items(self): list_start_stop_index = {} # we are interested only in components that are part of the listing components = [component for component in self.components if - hasattr(component, 'properties') - and hasattr(component.properties, 'numbering_properties') - and component.numbering_definition - and component.get_numbering_level()] + hasattr(component, 'properties') and + hasattr(component.properties, 'numbering_properties') and + component.numbering_definition and + component.get_numbering_level()] if not components: return False diff --git a/pydocx/openxml/drawing/wordprocessing/inline.py b/pydocx/openxml/drawing/wordprocessing/inline.py index 27d23e65..5645741f 100644 --- a/pydocx/openxml/drawing/wordprocessing/inline.py +++ b/pydocx/openxml/drawing/wordprocessing/inline.py @@ -7,9 +7,11 @@ from pydocx.models import XmlModel, XmlChild from pydocx.openxml.drawing.graphic import Graphic +from pydocx.openxml.wordprocessing.document_properties import DocPr class Inline(XmlModel): XML_TAG = 'inline' graphic = XmlChild(type=Graphic) + DocPr = XmlChild(type=DocPr) diff --git a/pydocx/openxml/wordprocessing/document_properties.py b/pydocx/openxml/wordprocessing/document_properties.py new file mode 100644 index 00000000..0ae73323 --- /dev/null +++ b/pydocx/openxml/wordprocessing/document_properties.py @@ -0,0 +1,14 @@ +from __future__ import ( + absolute_import, + print_function, + unicode_literals, +) + +from pydocx.models import XmlModel, XmlAttribute + + +class DocPr(XmlModel): + XML_TAG = 'docPr' + + title = XmlAttribute(name='title') + descr = XmlAttribute(name='descr') diff --git a/pydocx/openxml/wordprocessing/drawing.py b/pydocx/openxml/wordprocessing/drawing.py index cdf67119..0a9ca1cf 100644 --- a/pydocx/openxml/wordprocessing/drawing.py +++ b/pydocx/openxml/wordprocessing/drawing.py @@ -27,6 +27,12 @@ def graphic(self): except AttributeError: pass + def get_picture_description(self): + try: + return self.inline.DocPr.descr + except AttributeError: + return None + def get_picture_extents(self): graphic = self.graphic length = 0 diff --git a/tests/fixtures/external_image.html b/tests/fixtures/external_image.html index 2a782a3f..c8c92134 100644 --- a/tests/fixtures/external_image.html +++ b/tests/fixtures/external_image.html @@ -1,6 +1,7 @@

AAA A description...This arrow should point down:

\ No newline at end of file +

This arrow should point down: Macintosh HD:Users:jhubert:tmp:up.png

\ No newline at end of file