Commits

Georg Brandl  committed 82cd821

Added ``alt`` option to ``graphviz`` extension directives.

  • Participants
  • Parent commits 7e80409

Comments (0)

Files changed (3)

 Release 1.0 (in development)
 ============================
 
+* Added ``alt`` option to ``graphviz`` extension directives.
+
 * Added Epub builder.
 
 * #309: The ``graphviz`` extension can now output SVG instead of PNG

File doc/ext/graphviz.rst

          "bar" -> "baz" -> "quux";
 
 
+.. versionadded:: 1.0
+   All three directives support an ``alt`` option that determines the image's
+   alternate text for HTML output.  If not given, the alternate text defaults to
+   the graphviz code.
+
+
 There are also these new config values:
 
 .. confval:: graphviz_dot

File sphinx/ext/graphviz.py

     from sha import sha
 
 from docutils import nodes
+from docutils.parsers.rst import directives
 
 from sphinx.errors import SphinxError
 from sphinx.util import ensuredir, ENOENT
     required_arguments = 0
     optional_arguments = 0
     final_argument_whitespace = False
-    option_spec = {}
+    option_spec = {
+        'alt': directives.unchanged,
+    }
 
     def run(self):
         dotcode = '\n'.join(self.content)
         node = graphviz()
         node['code'] = dotcode
         node['options'] = []
+        if 'alt' in self.options:
+            node['alt'] = self.options['alt']
         return [node]
 
 
     required_arguments = 1
     optional_arguments = 0
     final_argument_whitespace = False
-    option_spec = {}
+    option_spec = {
+        'alt': directives.unchanged,
+    }
 
     def run(self):
         node = graphviz()
         node['code'] = '%s %s {\n%s\n}\n' % \
                        (self.name, self.arguments[0], '\n'.join(self.content))
         node['options'] = []
+        if 'alt' in self.options:
+            node['alt'] = self.options['alt']
         return [node]
 
 
         self.body.append(self.encode(code))
     else:
         if alt is None:
-            alt = self.encode(code).strip()
+            alt = node.get('alt', self.encode(code).strip())
         if format == 'svg':
             svgtag = get_svg_tag(fname, outfn, imgcls)
             self.body.append(svgtag)