From 3fbe181b12d60075790ed174b56452c6f7c7ddf0 Mon Sep 17 00:00:00 2001 From: David Lynch Date: Sat, 23 Nov 2024 16:48:09 -0600 Subject: [PATCH] In no-images case, replace with alt if present rather than decomposing Putting a placeholder there for the altless, to avoid confusion. --- ebook/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ebook/__init__.py b/ebook/__init__.py index af8f247..136678b 100644 --- a/ebook/__init__.py +++ b/ebook/__init__.py @@ -132,9 +132,10 @@ def chapter_html( # Remove all images from the chapter so you don't get that annoying grey background. for img in soup.find_all('img'): if img.parent.name.lower() == "figure": - img.parent.decompose() + # TODO: figcaption? + img.parent.replace_with(img.get('alt', '🖼')) else: - img.decompose() + img.replace_with(img.get('alt', '🖼')) title = titleprefix and f'{titleprefix}: {title}' or title contents = str(soup)