Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add svg width height property support #72

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 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,24 @@ def _get_svg_style(fname):
return m.group(1)


def _svg_style_subst_width_height(style_str, wh_style_subst):
# remove width and height
style_str_wo_wh = re.sub(r'width:[^;]+[;]?|height:[^;]+[;]?', '', style_str)
return '%s; %s' % (style_str_wo_wh, wh_style_subst)

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

yuja marked this conversation as resolved.
Show resolved Hide resolved
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