From 2b9c7635d3285aa69fe3df50c063cb4f2ede096b Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Sun, 30 Aug 2026 02:20:54 +0000 Subject: [PATCH] Figure-wrap lone images even with trailing inline attrs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Space-separated brace attrs on a lone image's own line (e.g. {style="max-width: 40em"}) are consumed onto the paragraph but leave an empty text token in the inline children, which defeated the lone-image check — the image stayed a bare inline without the figure wrapper (and without lightbox/zoom treatment). Strip empty text tokens before the check. --- pagerite/markdown.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pagerite/markdown.py b/pagerite/markdown.py index d165878..b69be13 100644 --- a/pagerite/markdown.py +++ b/pagerite/markdown.py @@ -180,7 +180,13 @@ def _unwrap_lone_figures(state) -> None: for i, token in enumerate(tokens): if token.type != "inline" or not token.children: continue - [child] = token.children if len(token.children) == 1 else [None] + # Attrs consumed out of the text (e.g. {style=...} space-separated + # on the image's own line) leave empty text tokens behind — strip + # them so the lone-image check is not thrown off by user styling. + children = [c for c in token.children if c.type != "text" or c.content] + if children: + token.children = children + [child] = children if len(children) == 1 else [None] if child and child.type == "image": if ( tokens[i - 1].type == "paragraph_open"