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')], [] diff --git a/test/markup_test.rb b/test/markup_test.rb index baa1dec2..6ab95662 100644 --- a/test/markup_test.rb +++ b/test/markup_test.rb @@ -137,4 +137,16 @@ def test_commonmarker_options assert_equal "<style>.red{color: red;}</style>\n", GitHub::Markup.render_s(GitHub::Markups::MARKUP_MARKDOWN, "", options: {commonmarker_opts: [:UNSAFE]}) assert_equal "\n", GitHub::Markup.render_s(GitHub::Markups::MARKUP_MARKDOWN, "", options: {commonmarker_opts: [:UNSAFE], commonmarker_exts: [:autolink, :table, :strikethrough]}) end + + def test_blanks_rst_inlined_reference + expected = '' + + actual = GitHub::Markup.render_s(GitHub::Markups::MARKUP_RST, <<~RST + .. image:: https://example.com/img.svg + :target: https://example.com/ + RST + ) + + assert_equal expected, actual.strip.lines.last + end end