1
0
Fork 0
mirror of https://github.com/kemayo/leech synced 2025-12-06 16:33:16 +01:00

In no-images case, replace with alt if present rather than decomposing

Putting a placeholder there for the altless, to avoid confusion.
This commit is contained in:
David Lynch 2024-11-23 16:48:09 -06:00
parent 740a41f4ef
commit 3fbe181b12

View file

@ -132,9 +132,10 @@ def chapter_html(
# Remove all images from the chapter so you don't get that annoying grey background. # Remove all images from the chapter so you don't get that annoying grey background.
for img in soup.find_all('img'): for img in soup.find_all('img'):
if img.parent.name.lower() == "figure": if img.parent.name.lower() == "figure":
img.parent.decompose() # TODO: figcaption?
img.parent.replace_with(img.get('alt', '🖼'))
else: else:
img.decompose() img.replace_with(img.get('alt', '🖼'))
title = titleprefix and f'{titleprefix}: {title}' or title title = titleprefix and f'{titleprefix}: {title}' or title
contents = str(soup) contents = str(soup)