fix: remove img attributes moved to parent in GLightboxExtension

Signed-off-by: squidfunk <martin.donath@squidfunk.com>
This commit is contained in:
Martin Donath
2026-04-23 14:00:36 +02:00
committed by GitHub
parent 5795fc8fe4
commit 87abb2abef
+15 -2
View File
@@ -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