Skip to content

Commit

Permalink
add svg width height properties, override SVG style
Browse files Browse the repository at this point in the history
  • Loading branch information
ndee02 authored and yuja committed Mar 2, 2023
1 parent 1a51304 commit 772e67f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion sphinxcontrib/plantuml.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class UmlDirective(Directive):
'name': directives.unchanged,
'scale': directives.percentage,
'width': directives.length_or_percentage_or_unitless,
'max-width': directives.length_or_percentage_or_unitless,
}

def run(self):
Expand Down Expand Up @@ -442,13 +443,25 @@ def _get_svg_style(fname):
return m.group(1)


def _svg_get_style_str(node, outfname):
width_height_styles = ["%s:%s" % (key, val)
for key, val in node.attributes.items()
if key in ['width', 'height', 'max-width']]
if width_height_styles:
style_str = '; '.join(width_height_styles)
else:
style_str = _get_svg_style(outfname) or ''
return style_str


def _get_svg_tag(self, fnames, node):
refname, outfname = fnames['svg']
style_str = _svg_get_style_str(node, outfname)
return '\n'.join([
# copy width/height style from <svg> tag, so that <object> area
# has enough space.
'<object data="%s" type="image/svg+xml" style="%s">' % (
self.encode(refname), _get_svg_style(outfname) or ''),
self.encode(refname), style_str),
_get_png_tag(self, fnames, node),
'</object>'])

Expand Down

0 comments on commit 772e67f

Please sign in to comment.