Skip to content

Commit

Permalink
Fix regression for image height/width
Browse files Browse the repository at this point in the history
This fixes a regression introduced in #113 where height/width attributes
were removed from images defined in reStructuredText.

More discussion here: #113 (comment)
  • Loading branch information
di committed Apr 21, 2020
1 parent 8901b5a commit 40b1460
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions readme_renderer/rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ class ReadMeHTMLTranslator(HTMLTranslator):
# Overrides base class not to output `<object>` tag for SVG images.
object_image_types = {}

def emptytag(self, node, tagname, suffix="\n", **attributes):
"""Override this to add back the width/height attributes."""
if tagname == "img":
if "width" in node:
attributes["width"] = node["width"]
if "height" in node:
attributes["height"] = node["height"]

return super(ReadMeHTMLTranslator, self).emptytag(
node, tagname, suffix, **attributes
)


SETTINGS = {
# Cloaking email addresses provides a small amount of additional
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/test_rst_png_attrs.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<img alt="alternate text" class="align-right" src="https://example.com/badge.png">
<img alt="alternate text" class="align-right" height="100px" src="https://example.com/badge.png" width="25.0%">
2 changes: 1 addition & 1 deletion tests/fixtures/test_rst_svg_attrs.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<img alt="alternate text" class="align-right" src="https://example.com/badge.svg">
<img alt="alternate text" class="align-right" height="100px" src="https://example.com/badge.svg" width="25.0%">

0 comments on commit 40b1460

Please sign in to comment.