Skip to content

Commit 600f67a

Browse files
committed
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 <git@jdknight.me>
1 parent 6f4f436 commit 600f67a

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

lib/github/commands/rest2html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,12 @@ class GitHubHTMLTranslator(HTMLTranslator):
258258
self.body.append(self.starttag(node, 'img', **atts))
259259
HTMLTranslator.depart_image(self, node)
260260

261+
# treat images held in a reference on the base document as inlined
262+
# images; this is to help avoid rendering a reference's decorative
263+
# line for the spacing after an image
264+
if (isinstance(node.parent, nodes.reference)
265+
and isinstance(node.parent.parent, nodes.document)):
266+
self.body.append(self.body.pop().rstrip('\n'))
261267

262268
def kbd(name, rawtext, text, lineno, inliner, options={}, content=[]):
263269
return [nodes.raw('', '<kbd>%s</kbd>' % text, format='html')], []

0 commit comments

Comments
 (0)