From a96ab058644e43bb5fdf32c0b3b238e1a9e1360f Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 14 Dec 2013 16:50:19 +0000 Subject: Use image alt text if available --- mammoth/conversion.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'mammoth/conversion.py') diff --git a/mammoth/conversion.py b/mammoth/conversion.py index 5580925..635b57c 100644 --- a/mammoth/conversion.py +++ b/mammoth/conversion.py @@ -77,10 +77,14 @@ class DocumentConverter(object): output = io.BytesIO() base64.encode(image_bytes, output) encoded_src = output.getvalue().rstrip("\n") - - html_generator.self_closing("img", { + + attributes = { "src": "data:{0};base64,{1}".format(image.content_type, encoded_src) - }) + } + if image.alt_text: + attributes["alt"] = image.alt_text + + html_generator.self_closing("img", attributes) def _convert_elements_to_html(self, elements, html_generator): -- cgit v1.2.3