From: Vladimír Vondruš
Date: Sun, 14 Oct 2018 14:32:10 +0000 (+0200)
Subject: m.dot: make title optional.
X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=545986c93c9af084ff73f56c4f6a770783e393ad;p=blog.git
m.dot: make title optional.
Requiring a title won't make any sense for graph figures.
---
diff --git a/doc/plugins/plots-and-graphs.rst b/doc/plugins/plots-and-graphs.rst
index b2ac3394..3d00e267 100644
--- a/doc/plugins/plots-and-graphs.rst
+++ b/doc/plugins/plots-and-graphs.rst
@@ -199,7 +199,7 @@ The plugin produces SVG graphcs that make use of the
--------------------
The :rst:`.. digraph::` directive uses the ``dot`` tool to produce directed
-graphs. The required directive argument is graph title, contents is whatever
+graphs. The optional directive argument is graph title, contents is whatever
you would put inside the :dot:`digraph` block. Use the :rst:`:class:` to
specify a `CSS color class <{filename}/css/components.rst#colors>`_ for the
whole graph, it's also possible to color particular nodes and edges using the
diff --git a/pelican-plugins/m/dot.py b/pelican-plugins/m/dot.py
index 04e2a41e..b5f8855b 100644
--- a/pelican-plugins/m/dot.py
+++ b/pelican-plugins/m/dot.py
@@ -35,7 +35,7 @@ import dot2svg
class Dot(rst.Directive):
has_content = True
- required_arguments = 1
+ optional_arguments = 1
final_argument_whitespace = True
option_spec = {'class': directives.class_option,
'name': directives.unchanged}
@@ -53,19 +53,35 @@ class Dot(rst.Directive):
class Digraph(Dot):
def run(self):
- return Dot.run(self, 'digraph "{}" {{\n{}}}'.format(self.arguments[0], '\n'.join(self.content)))
+ # We need to pass "" for an empty title to get rid of ,
+ # otherwise the output contains %3 (wtf!)
+ return Dot.run(self, 'digraph "{}" {{\n{}}}'.format(
+ self.arguments[0] if self.arguments else '',
+ '\n'.join(self.content)))
class StrictDigraph(Dot):
def run(self):
- return Dot.run(self, 'strict digraph "{}" {{\n{}}}'.format(self.arguments[0], '\n'.join(self.content)))
+ # We need to pass "" for an empty title to get rid of ,
+ # otherwise the output contains %3 (wtf!)
+ return Dot.run(self, 'strict digraph "{}" {{\n{}}}'.format(
+ self.arguments[0] if self.arguments else '',
+ '\n'.join(self.content)))
class Graph(Dot):
def run(self):
- return Dot.run(self, 'graph "{}" {{\n{}}}'.format(self.arguments[0], '\n'.join(self.content)))
+ # We need to pass "" for an empty title to get rid of ,
+ # otherwise the output contains %3 (wtf!)
+ return Dot.run(self, 'graph "{}" {{\n{}}}'.format(
+ self.arguments[0] if self.arguments else '',
+ '\n'.join(self.content)))
class StrictGraph(Dot):
def run(self):
- return Dot.run(self, 'strict graph "{}" {{\n{}}}'.format(self.arguments[0], '\n'.join(self.content)))
+ # We need to pass "" for an empty title to get rid of ,
+ # otherwise the output contains %3 (wtf!)
+ return Dot.run(self, 'strict graph "{}" {{\n{}}}'.format(
+ self.arguments[0] if self.arguments else '',
+ '\n'.join(self.content)))
def configure(pelicanobj):
dot2svg.configure(
diff --git a/pelican-plugins/m/test/dot/page-236.html b/pelican-plugins/m/test/dot/page-236.html
index e740ce42..1963b629 100644
--- a/pelican-plugins/m/test/dot/page-236.html
+++ b/pelican-plugins/m/test/dot/page-236.html
@@ -97,11 +97,10 @@ and the arrowheads, nothing else. Non-default font size should be preserved.