From 87abb2abeff14622254759d41939a4083245c2ec Mon Sep 17 00:00:00 2001 From: Martin Donath Date: Thu, 23 Apr 2026 14:00:36 +0200 Subject: [PATCH] fix: remove `img` attributes moved to parent in `GLightboxExtension` Signed-off-by: squidfunk --- python/zensical/extensions/glightbox.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/python/zensical/extensions/glightbox.py b/python/zensical/extensions/glightbox.py index 470cf18..e6453f5 100644 --- a/python/zensical/extensions/glightbox.py +++ b/python/zensical/extensions/glightbox.py @@ -84,11 +84,11 @@ class GlightboxTreeprocessor(Treeprocessor): return # Wrap image with anchor - idx = list(parent).index(img) + index = list(parent).index(img) el = self._build_anchor(img) parent.remove(img) el.append(img) - parent.insert(idx, el) + parent.insert(index, el) def _build_anchor(self, img: Element) -> Element: """Construct the anchor from image attributes.""" @@ -126,6 +126,19 @@ class GlightboxTreeprocessor(Treeprocessor): if gallery := self._resolve_gallery(img): el.set("data-gallery", gallery) + # Remove sourced attributes from img now that they live on the anchor + for attr in ( + "data-width", + "data-height", + "data-src", + "data-title", + "data-description", + "data-caption-position", + "data-gallery", + ): + if attr in img.attrib: + img.attrib.pop(attr) + # Return element return el