From 600f67a934a4c52875e5d3cd27b1c48a03d6c8e9 Mon Sep 17 00:00:00 2001 From: James Knight Date: Mon, 3 Mar 2025 21:27:58 -0500 Subject: [PATCH] rest2html: treat referenced wrapped images in base document as inlined docutils will only add newlines around images it believes are inlined. For images held in references, it checks the parent of the reference if its a `TextElement` to consider it inlined. Since a document is not a `TextElement` type, it will wrap an image with newlines. For GitHub output, this is not desired and will result in the extra whitespace being rendered with a reference's decorative line. To avoid this, always strip any appended suffixes for images in this scenario. Signed-off-by: James Knight --- lib/github/commands/rest2html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/github/commands/rest2html b/lib/github/commands/rest2html index c6fc663e..8cc1f161 100755 --- a/lib/github/commands/rest2html +++ b/lib/github/commands/rest2html @@ -258,6 +258,12 @@ class GitHubHTMLTranslator(HTMLTranslator): self.body.append(self.starttag(node, 'img', **atts)) HTMLTranslator.depart_image(self, node) + # treat images held in a reference on the base document as inlined + # images; this is to help avoid rendering a reference's decorative + # line for the spacing after an image + if (isinstance(node.parent, nodes.reference) + and isinstance(node.parent.parent, nodes.document)): + self.body.append(self.body.pop().rstrip('\n')) def kbd(name, rawtext, text, lineno, inliner, options={}, content=[]): return [nodes.raw('', '%s' % text, format='html')], []