From 96c3553bf13b132cc6aeccb42733cc1426a7381d Mon Sep 17 00:00:00 2001 From: Andreas Wolf Date: Wed, 11 Jan 2023 09:55:13 +0100 Subject: [PATCH 1/3] add svg width height property support --- sphinxcontrib/plantuml.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sphinxcontrib/plantuml.py b/sphinxcontrib/plantuml.py index 8145359..e945dca 100644 --- a/sphinxcontrib/plantuml.py +++ b/sphinxcontrib/plantuml.py @@ -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): @@ -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)) + 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 tag, so that area # has enough space. '' % ( - self.encode(refname), _get_svg_style(outfname) or ''), + self.encode(refname), style_str), _get_png_tag(self, fnames, node), '']) From ad01161b5e6432ec466113b6dfe12b38cefe422c Mon Sep 17 00:00:00 2001 From: Andreas Wolf Date: Fri, 13 Jan 2023 08:40:24 +0100 Subject: [PATCH 2/3] override SVG style with width and height properties --- sphinxcontrib/plantuml.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/sphinxcontrib/plantuml.py b/sphinxcontrib/plantuml.py index e945dca..a5160e9 100644 --- a/sphinxcontrib/plantuml.py +++ b/sphinxcontrib/plantuml.py @@ -443,15 +443,14 @@ 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)) + width_height_styles = ["%s:%s" % (key, val) for key, val in node.attributes.items() if key in ['width', 'height', 'max-width']] + if len(width_height_styles) > 0: + 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'] From 5327af4743558de2b4084bb557ee3ae30d29bdfd Mon Sep 17 00:00:00 2001 From: Andreas Wolf Date: Thu, 2 Mar 2023 09:24:30 +0100 Subject: [PATCH 3/3] style improvements --- sphinxcontrib/plantuml.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sphinxcontrib/plantuml.py b/sphinxcontrib/plantuml.py index a5160e9..8600284 100644 --- a/sphinxcontrib/plantuml.py +++ b/sphinxcontrib/plantuml.py @@ -104,7 +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, + 'max-width': directives.length_or_percentage_or_unitless, } def run(self): @@ -445,7 +445,7 @@ def _get_svg_style(fname): 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 len(width_height_styles) > 0: + if width_height_styles: style_str = '; '.join(width_height_styles) else: style_str = _get_svg_style(outfname) or ''