diff --git a/plugins/dot2svg.py b/plugins/dot2svg.py index d27e3f4e..e2483b23 100644 --- a/plugins/dot2svg.py +++ b/plugins/dot2svg.py @@ -43,11 +43,21 @@ _class_src = re.compile(r""" (?P<title>[^<]*) <(?Pellipse|polygon|path|text)( fill="(?P[^"]+)" stroke="[^"]+")? """) - _class_dst = r""" {title} <{element} """ +# Nodes that are links have an additional group containing a link inside. Again +# Graphviz < 2.40 (Ubuntu 16.04 and older) doesn't have a linebreak between +# and . +_class_with_link_inside_src = re.compile(r"""<g id="(edge|node)\d+" class="(?P<type>edge|node)(?P<classes>[^"]*)">[\n]?<title>(?P<title>[^<]*) +[^>]+)> +<(?Pellipse|polygon|path) fill="(?P[^"]+)" stroke="[^"]+" """) +_class_with_link_inside_dst = r""" +{title} + +<{element} """ + _attributes_src = re.compile(r"""<(?Pellipse|polygon|polyline) fill="[^"]+" stroke="[^"]+" """) _attributes_dst = r"""<\g """ @@ -111,6 +121,20 @@ def element_repl(match): element=match.group('element')) svg = _class_src.sub(element_repl, svg) + # Links have additional group around, second pass with a different regex + def element_link_repl(match): + classes = ['m-' + match.group('type')] + match.group('classes').replace('-', '-').split() + # distinguish between solid and filled nodes + if match.group('type') == 'node' and match.group('fill') == 'none': + classes += ['m-flat'] + + return _class_with_link_inside_dst.format( + link=match.group('link'), + classes=' '.join(classes), + title=match.group('title'), + element=match.group('element')) + svg = _class_with_link_inside_src.sub(element_link_repl, svg) + # Remove unnecessary fill and stroke attributes svg = _attributes_src.sub(_attributes_dst, svg) diff --git a/plugins/m/test/dot/page-240.html b/plugins/m/test/dot/page-240.html index 3f14d8db..c1004158 100644 --- a/plugins/m/test/dot/page-240.html +++ b/plugins/m/test/dot/page-240.html @@ -211,6 +211,42 @@

m.dot

+

Links:

+
+ + + +A + + +link to # + + + + +B + + +link to / + + + + +A->B + + + + + + +link to m.css + + + + + +
+

Figures:

diff --git a/plugins/m/test/dot/page.rst b/plugins/m/test/dot/page.rst index 0d997dfe..ae7a30a3 100644 --- a/plugins/m/test/dot/page.rst +++ b/plugins/m/test/dot/page.rst @@ -59,6 +59,17 @@ Structs: another [label="a | { b | c } | d | e" shape=record] +Links: + +.. digraph:: + + A [label="link to #" URL="#" style=filled class="m-primary"] + B [label="link to /" URL="#" class="m-success"] + + A -> B [label="link to m.css" URL="http://mcss.mosra.cz/" class="m-warning"] + +Figures: + .. graph-figure:: This is a title. .. digraph:: A to B