From 2736ab6dbfa95c4a6d99837b715ecccb23c84215 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 31 Aug 2022 21:33:29 +0100 Subject: Only use the alt text of image elements as a fallback --- mammoth/images.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'mammoth') diff --git a/mammoth/images.py b/mammoth/images.py index 9dba353..21b9288 100644 --- a/mammoth/images.py +++ b/mammoth/images.py @@ -5,12 +5,13 @@ from . import html def img_element(func): def convert_image(image): - attributes = func(image).copy() + attributes = {} if image.alt_text: attributes["alt"] = image.alt_text - + attributes.update(func(image)) + return [html.element("img", attributes)] - + return convert_image # Undocumented, but retained for backwards-compatibility with 0.3.x @@ -21,7 +22,7 @@ inline = img_element def data_uri(image): with image.open() as image_bytes: encoded_src = base64.b64encode(image_bytes.read()).decode("ascii") - + return { "src": "data:{0};base64,{1}".format(image.content_type, encoded_src) } -- cgit v1.2.3