Figure-wrap lone images even with trailing inline attrs
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 <img> without the
figure wrapper (and without lightbox/zoom treatment). Strip empty text
tokens before the check.
This commit is contained in:
@@ -180,7 +180,13 @@ def _unwrap_lone_figures(state) -> None:
|
|||||||
for i, token in enumerate(tokens):
|
for i, token in enumerate(tokens):
|
||||||
if token.type != "inline" or not token.children:
|
if token.type != "inline" or not token.children:
|
||||||
continue
|
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 child and child.type == "image":
|
||||||
if (
|
if (
|
||||||
tokens[i - 1].type == "paragraph_open"
|
tokens[i - 1].type == "paragraph_open"
|
||||||
|
|||||||
Reference in New Issue
Block a user