From 545986c93c9af084ff73f56c4f6a770783e393ad Mon Sep 17 00:00:00 2001
From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?=
Date: Sun, 14 Oct 2018 16:32:10 +0200
Subject: [PATCH] m.dot: make title optional.
Requiring a title won't make any sense for graph figures.
---
doc/plugins/plots-and-graphs.rst | 2 +-
pelican-plugins/m/dot.py | 26 +++++++++++++++++++-----
pelican-plugins/m/test/dot/page-236.html | 3 +--
pelican-plugins/m/test/dot/page-238.html | 3 +--
pelican-plugins/m/test/dot/page.html | 3 +--
pelican-plugins/m/test/dot/page.rst | 4 ++--
6 files changed, 27 insertions(+), 14 deletions(-)
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.