Skip to content

Commit

Permalink
Set a default width for rendering images so they don't get raw wdith
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorns committed Nov 21, 2023
1 parent 18c9b1f commit b553b76
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions md2cf/confluence_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,26 @@ def block_code(self, code, lang=None):
root_element.append(self.plain_text_body(code))
return root_element.render()

def image(self, src, title, text):
def image(self, src, title, text, width=764, height=None):
"""
Render an image as Confluence Storage Format.
See https://confluence.atlassian.com/doc/confluence-storage-format-790796544.html
:param src: The image source path
:param title: The title of the image
:param text: Used as alt (tooltip) text for the image
:param width: The rendered width of the image, defaults to 764 which seems to work well in Confluence.
:param height: Specify the height of the image, relative to width by default.
"""
attributes = {"alt": text}
if title:
attributes["title"] = title
if width:
attributes["width"] = width
if height:
attributes["height"] = height

root_element = ConfluenceTag(name="image", attrib=attributes)
root_element = ConfluenceTag(name="image", attrib=attributes, namespace="ac")
parsed_source = urlparse(src)
if not parsed_source.netloc:
# Local file, requires upload
Expand All @@ -158,5 +172,4 @@ def image(self, src, title, text):
else:
url_tag = ConfluenceTag("url", attrib={"value": src}, namespace="ri")
root_element.append(url_tag)

return root_element.render()

0 comments on commit b553b76

Please sign in to comment.