From f7531afbf6250e5cf65d1641afe24c81cce8a306 Mon Sep 17 00:00:00 2001 From: squidfunk Date: Thu, 23 Apr 2026 13:36:05 +0200 Subject: [PATCH] fix: images in raw HTML are double-processed by `GLightboxExtension` Signed-off-by: squidfunk --- python/zensical/extensions/glightbox.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/python/zensical/extensions/glightbox.py b/python/zensical/extensions/glightbox.py index 7f6ef2e..470cf18 100644 --- a/python/zensical/extensions/glightbox.py +++ b/python/zensical/extensions/glightbox.py @@ -164,6 +164,9 @@ class GlightboxPostprocessor(Postprocessor): def __init__(self, md: Markdown | None, config: dict[str, object]) -> None: super().__init__(md) self._processor = GlightboxTreeprocessor(md, config) + self._processed: set[int] = set() + + # Source classes to skip from postprocessor self._skip_classes = GlightboxTreeprocessor.SKIP_CLASSES | frozenset( cast("list[str]", config.get("skip_classes") or []) ) @@ -171,8 +174,11 @@ class GlightboxPostprocessor(Postprocessor): def run(self, text: str) -> str: """Wrap images in stashed HTML blocks.""" for i, raw in enumerate(self.md.htmlStash.rawHtmlBlocks): - self.md.htmlStash.rawHtmlBlocks[i] = _RE.sub(self._maybe_wrap, raw) - print(self.md.htmlStash.rawHtmlBlocks[i]) + if i not in self._processed: + self.md.htmlStash.rawHtmlBlocks[i] = _RE.sub( + self._maybe_wrap, raw + ) + self._processed.add(i) # Return text unmodified, as we only need to modify the stashed raw HTML # blocks, which will later be reinstated by the raw HTML postprocessor